添加编译指令

This commit is contained in:
gongxh
2022-01-18 20:20:10 +08:00
parent a7ef9c7b54
commit 89f1bb0536
5 changed files with 707 additions and 640 deletions

View File

@@ -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
}
}
}