2021-06-12 14:09:28 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Data.SQLite;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using DataParameter = System.Data.SQLite.SQLiteParameter;
|
|
|
|
|
|
using DataCommand = System.Data.SQLite.SQLiteCommand;
|
|
|
|
|
|
using DataAdapter = System.Data.SQLite.SQLiteDataAdapter;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ryCommonDb
|
|
|
|
|
|
{
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class SQLiteDataProvider : IDbInterface
|
|
|
|
|
|
{
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
readonly ryCommonDb.ClsDb myDb = new ryCommonDb.ClsDb();
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sql"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int ConnDb(string sql)
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] item = sql.Split('|');
|
|
|
|
|
|
if (item.Length == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
return myDb.ConnDb(sql.Replace("<app>",Application.StartupPath),"");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{ return myDb.ConnDb(item[0].Replace("<app>", Application.StartupPath), item[1]); }
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int CloseDb()
|
|
|
|
|
|
{
|
|
|
|
|
|
myDb.CloseDb();
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="tableName"></param>
|
|
|
|
|
|
/// <param name="wheresql"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int GetCount(string tableName, string wheresql)
|
|
|
|
|
|
{
|
|
|
|
|
|
string m_where = "";
|
|
|
|
|
|
if (wheresql != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
m_where = " where " + wheresql;
|
|
|
|
|
|
}
|
|
|
|
|
|
string sql= "select count(*) from "+ tableName + m_where;
|
|
|
|
|
|
return Convert.ToInt32(myDb.ExecuteSQL(sql,(DataParameter[])GetParameter(), "0")[0]);
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="newPwd"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int ChangePwd(string newPwd)
|
|
|
|
|
|
{
|
|
|
|
|
|
myDb.ChangePwd(newPwd);
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
private readonly List<SQLIitem> list_param = new List<SQLIitem>();
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="name"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
|
public void AddParameter(string name,object value)
|
|
|
|
|
|
{
|
|
|
|
|
|
list_param.Add(new SQLIitem(name, value));
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="name"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
|
public void ClearParameter(object name, object value)
|
|
|
|
|
|
{
|
|
|
|
|
|
list_param.Clear();
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public object[] GetParameter()
|
|
|
|
|
|
{
|
|
|
|
|
|
DataParameter[] defPar = new DataParameter[list_param.Count];
|
|
|
|
|
|
for (int i = 0; i < list_param.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SQLIitem item = (SQLIitem)list_param[i];
|
|
|
|
|
|
defPar[i] = new DataParameter("@" + item.Field.TrimStart('@').TrimStart('[').TrimEnd(']'), item.value);
|
|
|
|
|
|
}
|
|
|
|
|
|
return defPar;
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="mySQL"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public object[] GetParameter(RyQuickSQL mySQL)
|
|
|
|
|
|
{
|
|
|
|
|
|
DataParameter[] defPar = new DataParameter[mySQL.List.Count + mySQL.List_param.Count];
|
|
|
|
|
|
for (int i = 0; i < mySQL.List.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SQLIitem item = (SQLIitem)mySQL.List[i];
|
|
|
|
|
|
defPar[i] = new DataParameter("@" + item.Field.TrimStart('@').TrimStart('[').TrimEnd(']'), item.value);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (int i = mySQL.List.Count; i < mySQL.List.Count + mySQL.List_param.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SQLIitem item = (SQLIitem)mySQL.List_param[i - mySQL.List.Count];
|
|
|
|
|
|
defPar[i] = new DataParameter("@" + item.Field.TrimStart('@').TrimStart('[').TrimEnd(']'), item.value);
|
|
|
|
|
|
}
|
|
|
|
|
|
return defPar;
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="tableName"></param>
|
|
|
|
|
|
/// <param name="wheresql"></param>
|
|
|
|
|
|
/// <param name="orderSQL"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public string GetPageSQL(string tableName, string wheresql, string orderSQL)
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetPageSQL("*", tableName, wheresql, orderSQL);
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="tableName"></param>
|
|
|
|
|
|
/// <param name="wheresql"></param>
|
|
|
|
|
|
/// <param name="orderSQL"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public string GetPageSQL2(string tableName, string wheresql, string orderSQL)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="field"></param>
|
|
|
|
|
|
/// <param name="tableName"></param>
|
|
|
|
|
|
/// <param name="wheresql"></param>
|
|
|
|
|
|
/// <param name="orderSQL"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public string GetPageSQL(string field,string tableName, string wheresql, string orderSQL)
|
|
|
|
|
|
{
|
|
|
|
|
|
string m_where = "";
|
|
|
|
|
|
if (wheresql != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
m_where = " where " + wheresql;
|
|
|
|
|
|
}
|
|
|
|
|
|
string m_order = "";
|
|
|
|
|
|
if (orderSQL != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
m_order = " " + orderSQL;
|
|
|
|
|
|
}
|
|
|
|
|
|
return "select "+ field + " from " + tableName + m_where + m_order + " limit {pagesize} offset {recordnum}";
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="field"></param>
|
|
|
|
|
|
/// <param name="tableName"></param>
|
|
|
|
|
|
/// <param name="wheresql"></param>
|
|
|
|
|
|
/// <param name="orderSQL"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public string GetPageSQL2(string field,string tableName, string wheresql, string orderSQL)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sql"></param>
|
|
|
|
|
|
/// <param name="Parameter"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public bool ContainsData(string sql, object[] Parameter)
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Data.DataSet ds=ReadData(sql, Parameter);
|
|
|
|
|
|
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sql"></param>
|
|
|
|
|
|
/// <param name="Parameter"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public System.Data.DataSet ReadData(string sql, object[] Parameter)
|
|
|
|
|
|
{
|
|
|
|
|
|
DataCommand cmd = myDb.SQLite_cn.CreateCommand();
|
|
|
|
|
|
cmd.Parameters.Clear();
|
|
|
|
|
|
if (Parameter != null)
|
|
|
|
|
|
cmd.Parameters.AddRange(Parameter);
|
|
|
|
|
|
cmd.CommandText = sql;
|
|
|
|
|
|
DataAdapter ad = new DataAdapter(cmd);
|
|
|
|
|
|
System.Data.DataSet ds=new System.Data.DataSet();
|
|
|
|
|
|
ad.Fill(ds);
|
|
|
|
|
|
ad.Dispose();
|
|
|
|
|
|
cmd.Dispose();
|
|
|
|
|
|
return ds;
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sql"></param>
|
|
|
|
|
|
/// <param name="mySQL"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public System.Data.DataSet ReadData(string sql, RyQuickSQL mySQL)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ReadData(sql, GetParameter(mySQL));
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sql"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public System.Data.DataSet ReadData(string sql)
|
|
|
|
|
|
{
|
|
|
|
|
|
object[] Parameter = null;
|
|
|
|
|
|
return ReadData(sql, Parameter);
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="tableName"></param>
|
|
|
|
|
|
/// <param name="id"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public System.Data.DataSet ReadData(string tableName, string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
object[] Parameter = null;
|
|
|
|
|
|
return ReadData("select * from " + tableName + " where id=" + id, Parameter);
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sql"></param>
|
|
|
|
|
|
/// <param name="Parameter"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int ExecuteNonQuery(string sql, object[] Parameter)
|
|
|
|
|
|
{
|
|
|
|
|
|
DataCommand cmd = myDb.SQLite_cn.CreateCommand();
|
|
|
|
|
|
cmd.Parameters.Clear();
|
|
|
|
|
|
if(Parameter!=null)
|
|
|
|
|
|
cmd.Parameters.AddRange(Parameter);
|
|
|
|
|
|
cmd.CommandText = sql;
|
|
|
|
|
|
int i= cmd.ExecuteNonQuery();
|
|
|
|
|
|
cmd.Dispose();
|
|
|
|
|
|
return i;
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
2021-10-01 03:34:49 +00:00
|
|
|
|
/// 执行SQL语句
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="mySQL"></param>
|
|
|
|
|
|
/// <param name="wheresql">只针对IsAdd为false才生效,where 以后的sql语句</param>
|
|
|
|
|
|
/// <param name="IsAdd">是新增还是更新</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int ExecuteNonQuery(RyQuickSQL mySQL, string wheresql, bool IsAdd)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsAdd)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ExecuteNonQuery(mySQL.GetInsertSQL(), mySQL);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (wheresql.Length == 0) { return -1; }
|
|
|
|
|
|
return ExecuteNonQuery(mySQL.GetUpdateSQL() + " where " + wheresql, mySQL);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 插入数据库
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="mySQL"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int Insert(RyQuickSQL mySQL)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ExecuteNonQuery(mySQL.GetInsertSQL(), mySQL);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新数据库
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="mySQL"></param>
|
|
|
|
|
|
/// <param name="wheresql">where 以后的sql语句</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int Update(RyQuickSQL mySQL, string wheresql)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (wheresql.Length == 0) { return -1; }
|
|
|
|
|
|
return ExecuteNonQuery(mySQL.GetUpdateSQL() + " where " + wheresql, mySQL);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
2021-01-23 15:35:30 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sql"></param>
|
|
|
|
|
|
/// <param name="mySQL"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int ExecuteNonQuery(string sql, RyQuickSQL mySQL)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ExecuteNonQuery(sql, GetParameter(mySQL));
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sql"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int ExecuteNonQuery(string sql)
|
|
|
|
|
|
{
|
|
|
|
|
|
object[] pram = null;
|
|
|
|
|
|
return ExecuteNonQuery(sql, pram);
|
|
|
|
|
|
}
|
|
|
|
|
|
SQLiteTransaction tr;
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void BeginTransaction()
|
|
|
|
|
|
{
|
|
|
|
|
|
tr= myDb.SQLite_cn.BeginTransaction();
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void Commit()
|
|
|
|
|
|
{
|
|
|
|
|
|
tr.Commit();
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="tableName"></param>
|
|
|
|
|
|
/// <param name="id"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int DelById(string tableName, string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
object[] param = null;
|
|
|
|
|
|
return ExecuteNonQuery("delete from " + tableName + " where id=" + id, param);
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="mySQL"></param>
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int CreateDb(RyQuickSQL mySQL)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool table_exist;
|
|
|
|
|
|
DataCommand cmd = myDb.SQLite_cn.CreateCommand();
|
|
|
|
|
|
cmd.Parameters.Clear();
|
|
|
|
|
|
cmd.CommandText = "SELECT COUNT(*) FROM sqlite_master where type='table' and name='" + mySQL.TableName + "'";
|
|
|
|
|
|
if (0 == Convert.ToInt32(cmd.ExecuteScalar()))
|
|
|
|
|
|
{
|
|
|
|
|
|
table_exist = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
table_exist = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
cmd.Dispose();
|
|
|
|
|
|
if (table_exist)
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Data.DataSet ds = ReadData("select * from " + mySQL.TableName + " limit 1");
|
|
|
|
|
|
for (int i = 0; i < mySQL.List.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
#region 循环表字段,如果不存在就创建
|
|
|
|
|
|
SQLIitem item = (SQLIitem)mySQL.List[i];
|
|
|
|
|
|
if (ds.Tables[0].Columns.Contains(item.Field))
|
|
|
|
|
|
{ continue; }
|
|
|
|
|
|
string Field = "";
|
|
|
|
|
|
if (item.value is string)
|
|
|
|
|
|
{
|
|
|
|
|
|
Field = "[" + item.Field.TrimStart('[').TrimEnd(']') + "] TEXT COLLATE NOCASE";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item.value is int || item.value is Int64)
|
|
|
|
|
|
{
|
|
|
|
|
|
Field = "[" + item.Field.TrimStart('[').TrimEnd(']') + "] INTEGER DEFAULT 0";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item.value is double || item.value is float)
|
|
|
|
|
|
{
|
|
|
|
|
|
Field = "[" + item.Field.TrimStart('[').TrimEnd(']') + "] FLOAT DEFAULT 0";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item.value is DateTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
Field = "[" + item.Field.TrimStart('[').TrimEnd(']') + "] DATETIME";
|
|
|
|
|
|
}
|
2021-09-15 09:32:07 +00:00
|
|
|
|
else if (item.value is byte[])
|
|
|
|
|
|
{
|
|
|
|
|
|
Field = "[" + item.Field.TrimStart('[').TrimEnd(']') + "] BLOB";
|
|
|
|
|
|
}
|
2021-06-12 14:09:28 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
object[] param = null;
|
|
|
|
|
|
ExecuteNonQuery("ALTER TABLE " + mySQL.TableName + " ADD COLUMN " + Field, param);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception) { }
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
#region 创建表
|
|
|
|
|
|
string tmpSQL = "CREATE TABLE " + mySQL.TableName + " ([ID] INTEGER PRIMARY KEY,";
|
|
|
|
|
|
for (int i = 0; i < mySQL.List.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SQLIitem item = (SQLIitem)mySQL.List[i];
|
|
|
|
|
|
if (item.value is string)
|
|
|
|
|
|
{
|
|
|
|
|
|
tmpSQL += "[" + item.Field.TrimStart('[').TrimEnd(']') + "] TEXT COLLATE NOCASE,";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item.value is int || item.value is Int64)
|
|
|
|
|
|
{
|
|
|
|
|
|
tmpSQL += "[" + item.Field.TrimStart('[').TrimEnd(']') + "] INTEGER DEFAULT 0,";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item.value is double || item.value is float)
|
|
|
|
|
|
{
|
|
|
|
|
|
tmpSQL += "[" + item.Field.TrimStart('[').TrimEnd(']') + "] FLOAT DEFAULT 0,";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item.value is DateTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
tmpSQL += "[" + item.Field.TrimStart('[').TrimEnd(']') + "] DATETIME,";
|
|
|
|
|
|
}
|
2021-09-15 09:32:07 +00:00
|
|
|
|
else if (item.value is byte[])
|
|
|
|
|
|
{
|
|
|
|
|
|
tmpSQL += "[" + item.Field.TrimStart('[').TrimEnd(']') + "] BLOB,";
|
|
|
|
|
|
}
|
2021-06-12 14:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
object[] param = null;
|
|
|
|
|
|
return ExecuteNonQuery(tmpSQL.Substring(0, tmpSQL.Length - 1) + ")", param);
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-01-23 15:35:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
2021-06-12 14:09:28 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void Free()
|
|
|
|
|
|
{
|
|
|
|
|
|
list_param.Clear();
|
|
|
|
|
|
myDb.CloseDb();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|