public DBServer() { if (!Directory.Exists("LocalSQLDB")) { Directory.CreateDirectory("LocalSQLDB"); } if (!Directory.Exists("DBCfg")) { Directory.CreateDirectory("DBCfg"); } LocalSQLFile = Path.Combine("LocalSQLDB", "localdb.db"); KVDir = "LocalKVDB"; SQLCfgDir = "DBCfg"; RedisCfg = Path.Combine("DBCfg", "Redis.Cfg"); memHelper = new SqliteHelper(); bDBHelper = new BDBHelper <object, object>(); kvdir = bDBHelper.EnvHome; bDBHelper.EnvHome = KVDir; bDBHelper.Reset(); sqliteHelper = new SqliteHelper(); sqliteHelper.ConnectString = LocalSQLFile; sqliteHelper.CreateEmptyDB(LocalSQLFile); DBAcessPool.SetConfigDir(SQLCfgDir); LoadRedisCfg(); }
/// <summary> /// 不使用默认值时重新初始化 /// </summary> public void ResetInit() { RemoveConfig(); bDBHelper.EnvHome = KVDir; bDBHelper.Reset(); sqliteHelper.ConnectString = LocalSQLFile; sqliteHelper.CreateEmptyDB(LocalSQLFile); DBAcessPool.SetConfigDir(SQLCfgDir); LoadRedisCfg(); }
private RequestResult MemorySQL(DBTransfer transfer) { RequestResult result = new RequestResult(); result.Error = ErrorCode.Sucess; DBAcessPool dBAcess = new DBAcessPool(); dBAcess.DBName = transfer.DBCfg; if (transfer.IsQuery) { try { DataSet ds = memHelper.GetSelect(transfer.SQL); if (ds.Tables.Count > 0) { DataTable dt = ds.Tables[0]; result.Result = dt; if (transfer.IsModel && !string.IsNullOrEmpty(transfer.ModelCls)) { object value = null; if (!dicModels.TryGetValue(transfer.ModelCls, out value)) { string path = null; path = transfer.ModelDLL; if (string.IsNullOrEmpty(path)) { path = transfer.ModelCls.Substring(0, transfer.ModelCls.LastIndexOf(".")); } Assembly assembly = Assembly.LoadFrom(Path.Combine("Models", path, ".dll")); value = assembly.CreateInstance(transfer.ModelCls, true); } // try { result.Result = DataConvert <object> .ToList(dt); } catch (Exception ex) { result.Error = ErrorCode.Exception; result.ReslutMsg = "转换Model错误," + ex.Message; } } } } catch (Exception ex) { result.Error = ErrorCode.Exception; result.ReslutMsg = "查询错误," + ex.Message; } } else { try { int r = memHelper.ExecuteUpdate(transfer.SQL, transfer.IsScala); result.Result = r; } catch (Exception ex) { result.Error = ErrorCode.Exception; result.ReslutMsg = "执行错误," + ex.Message; } } result.ErrorMsg = result.Error.ToDescriptionString(); return(result); }