123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using OTSModelSharp.DTLBase;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OTSModelSharp.DTLBase
- {
- public class CSQLiteDB :IDBBase
- {
-
- //表结构
- protected IDBTableBase m_sqlitetable;
-
- //数据库连接地址
- protected IDBStoreBase m_DBStore;
-
- /// <summary>
- /// 初始换
- /// </summary>
- /// <param name="conStr">数据库地址</param>
- /// <param name="_table">表结构</param>
- public CSQLiteDB(IDBStoreBase a_dbStore, IDBTableBase a_table)
- {
- //dbStore =(CSQLiteDBStore) a_dbStore;
- m_sqlitetable = a_table;
-
- m_DBStore = a_dbStore;
- }
- /// <summary>
- /// 建表
- /// </summary>
- /// <param name="a_bClean">如果a_bClean删除表再建表</param>
- /// <returns></returns>
- public bool Init(bool a_bClean = false)
- {
- if (IsDBExist())
- {
- if (a_bClean)
- {
- DeleteTable();
- }
- else
- {
- return true;
- }
- }
- return CreateTable();
- }
-
- /// <summary>
- ///建表
- /// </summary>
- /// <returns></returns>
- public bool CreateTable( bool a_bForce=false)
- {
- if (m_DBStore.IsTableExists(m_sqlitetable.GetTableName()))
- {
- if (a_bForce)
- {
- if (!DeleteTable())
- {
- return false;
- }
- }
- else
- {
- return true;
- }
- }
- // create table
- string sSQLCommand = m_sqlitetable.GetCreateTableCommandString();
- return m_DBStore.RunCommand(sSQLCommand);
- }
- /// <summary>
- ///删除表
- /// </summary>
- /// <returns></returns>
- public bool DeleteTable()
- {
- return m_DBStore.DeleteTable(m_sqlitetable.GetTableName());
-
- }
- /// <summary>
- ///移除表数据
- /// </summary>
- /// <returns></returns>
- public bool RemoveAllRows()
- {
- if (!m_DBStore. IsTableExists(m_sqlitetable. GetTableName()))
- {
- return true;
- }
- // create table
- string sSQLCommand = m_sqlitetable.GetRemoveAllRowsCommandString();
- return m_DBStore. RunCommand(sSQLCommand);
- }
- /// <summary>
- /// 判断表是否存在
- /// </summary>
- /// <returns></returns>
- public bool IsDBExist()
- {
- return m_DBStore.IsTableExists(m_sqlitetable.GetTableName());
- }
- /// <summary>
- /// 获取连接字符串
- /// </summary>
- /// <returns></returns>
- public IDBStoreBase GetDatastore()
- {
- return m_DBStore;
- }
- /// <summary>
- /// 获取表结构
- /// </summary>
- /// <returns></returns>
- /// <summary>
- /// 获取表所有信息
- /// </summary>
- /// <param name="a_sOrderColumnName">排序字段</param>
- /// <returns></returns>
- public IDBQueryBase GetTableQuery(string a_sOrderColumnName="")
- {
- return m_DBStore.QueryByTableName(m_sqlitetable.GetTableName(),a_sOrderColumnName);
- }
- public DataTable GetTableQueryForDataTable(string a_sOrderColumnName = "")
- {
- return m_DBStore.QueryByTableNameForDataTable(m_sqlitetable.GetTableName(), a_sOrderColumnName);
- }
- public IDBTableBase GetTableInfo()
- {
- return m_sqlitetable;
- }
-
- }
- }
|