添加编译指令
This commit is contained in:
@@ -28,25 +28,28 @@ namespace LeadDataBaseUtility
|
||||
public static int ExecuteSql(string sql)
|
||||
{
|
||||
int affectedRows = 0;
|
||||
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conn = new SQLiteConnection(connectionString))
|
||||
#endif
|
||||
using (SQLiteConnection conn = new SQLiteConnection(connectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (SQLiteCommand cmd = new SQLiteCommand(conn))
|
||||
{
|
||||
conn.Open();
|
||||
using (SQLiteCommand cmd = new SQLiteCommand(conn))
|
||||
{
|
||||
cmd.CommandText = sql;
|
||||
affectedRows = cmd.ExecuteNonQuery();
|
||||
}
|
||||
conn.Close();
|
||||
cmd.CommandText = sql;
|
||||
affectedRows = cmd.ExecuteNonQuery();
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
#if !DEBUG
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.WriteLog($"数据库运行异常:【{e.Message}】。SQL语句:【{sql}】。", LogTypeEum.DbErr);
|
||||
}
|
||||
|
||||
#endif
|
||||
return affectedRows;
|
||||
}
|
||||
/// <summary>
|
||||
@@ -59,17 +62,21 @@ namespace LeadDataBaseUtility
|
||||
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
|
||||
{
|
||||
DataSet ds = new DataSet();
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
SQLiteDataAdapter command = new SQLiteDataAdapter(SQLString, connection);
|
||||
command.Fill(ds, "ds");
|
||||
connection.Close();
|
||||
}
|
||||
#endif
|
||||
connection.Open();
|
||||
SQLiteDataAdapter command = new SQLiteDataAdapter(SQLString, connection);
|
||||
command.Fill(ds, "ds");
|
||||
connection.Close();
|
||||
#if !DEBUG
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.WriteLog($"数据库运行异常:【{e.Message}】。SQL语句:【{SQLString}】。", LogTypeEum.DbErr);
|
||||
}
|
||||
{
|
||||
LogHelper.WriteLog($"数据库运行异常:【{e.Message}】。SQL语句:【{SQLString}】。", LogTypeEum.DbErr);
|
||||
}
|
||||
#endif
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
@@ -84,27 +91,31 @@ namespace LeadDataBaseUtility
|
||||
{
|
||||
using (SQLiteCommand cmd = new SQLiteCommand(SQLString, connection))
|
||||
{
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
object obj = cmd.ExecuteScalar();
|
||||
if ((Equals(obj, null)) || (Equals(obj, System.DBNull.Value)))
|
||||
{
|
||||
connection.Close();
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
connection.Close();
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
catch (System.Data.SQLite.SQLiteException e)
|
||||
#endif
|
||||
connection.Open();
|
||||
object obj = cmd.ExecuteScalar();
|
||||
if ((Equals(obj, null)) || (Equals(obj, System.DBNull.Value)))
|
||||
{
|
||||
connection.Close();
|
||||
LogHelper.WriteLog($"数据库运行异常:【{e.Message}】。SQL语句:【{SQLString}】。", LogTypeEum.DbErr);
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
connection.Close();
|
||||
return obj;
|
||||
}
|
||||
#if !DEBUG
|
||||
}
|
||||
catch (System.Data.SQLite.SQLiteException e)
|
||||
{
|
||||
connection.Close();
|
||||
LogHelper.WriteLog($"数据库运行异常:【{e.Message}】。SQL语句:【{SQLString}】。", LogTypeEum.DbErr);
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user