public static string genRemoveSql(string orderId) { SqlDeleteGenerator sql = new SqlDeleteGenerator(); string cmd = sql.getResultSql(TableName.PLAYER_ORDER_WAIT, string.Format("orderId='{0}' ", orderId)); return(cmd); }
private void TranslateCommandTree(DbCommandTree commandTree, DbCommand command) { SqlBaseGenerator sqlGenerator = null; DbQueryCommandTree select; DbInsertCommandTree insert; DbUpdateCommandTree update; DbDeleteCommandTree delete; if ((select = commandTree as DbQueryCommandTree) != null) { sqlGenerator = new SqlSelectGenerator(select); } else if ((insert = commandTree as DbInsertCommandTree) != null) { sqlGenerator = new SqlInsertGenerator(insert); } else if ((update = commandTree as DbUpdateCommandTree) != null) { sqlGenerator = new SqlUpdateGenerator(update); } else if ((delete = commandTree as DbDeleteCommandTree) != null) { sqlGenerator = new SqlDeleteGenerator(delete); } else { // TODO: get a message (unsupported DbCommandTree type) throw new ArgumentException(); } sqlGenerator.BuildCommand(command); }
public void Gen_Delete_Test_Keyless() { TestClass T = new TestClass() { DateColumn = DateTime.Parse("1/1/2021"), FloatColumn = 12.12, IntegerColumn = 123, ScalarColumn = 1, TextColumn = "Tomato" }; SqlDeleteGenerator delr = new SqlDeleteGenerator(); try { var command = delr.Generate(T, new Func <TestClass, IEnumerable <KeyValuePair <string, object> > >(x => { return(new List <KeyValuePair <string, object> >()); })); } catch { Assert.Pass(); } Assert.Fail(); }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <returns></returns> public virtual bool Delete(object key) { var sql = SqlDeleteGenerator.GetDelete(); using (var connection = DbConnectionFactory.CreateConnection()) { connection.Open(); return(connection.Execute(sql, key) > 0); } }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <returns></returns> public virtual async Task <bool> DeleteAsync(object key) { var sql = SqlDeleteGenerator.GetDelete(); using (var connection = DbConnectionFactory.CreateConnection()) { connection.Open(); await connection.QueryAsync <int>(sql, key); return(true); } }
// 删除操作日志 private OpRes delGmOpLog(ParamDelAcc p, GMUser user) { if (!user.isAdmin()) { return(OpRes.op_res_no_right); } SqlDeleteGenerator gen = new SqlDeleteGenerator(); string cmd = gen.getResultSql(TableName.OPLOG, "1=1"); int count = user.sqlDb.executeOp(cmd, user.getMySqlServerID(), MySqlDbName.DB_XIANXIA); return(count >= 0 ? OpRes.opres_success : OpRes.op_res_db_failed); }
private void ButtonGenerateDelete_Click(object sender, RoutedEventArgs e) { if (lstSelectedTables.SelectedItems.Count > 0) { string output = string.Empty; foreach (var item in lstSelectedTables.SelectedItems) { if (item is TSqlObject table) { SqlDeleteGenerator gen = new SqlDeleteGenerator(GeneratorSettings, table, true); output += gen.Generate(); } } txtOutput.Text = output; } }
public void Gen_Delete_For_TestClass() { TestClass T = new TestClass() { DateColumn = DateTime.Parse("1/1/2021"), FloatColumn = 12.12, IntegerColumn = 123, ScalarColumn = 1, TextColumn = "Tomato" }; SqlDeleteGenerator delr = new SqlDeleteGenerator(); var command = delr.Generate(T); Assert.AreEqual(command, correctStr); }
private OpRes delGmAcc(ParamDelAcc p, GMUser user) { DestGmUser dst = new DestGmUser(p.m_acc, user); if (dst.m_isSelf) { return(OpRes.op_res_no_right); } if (!dst.m_isExists) { return(OpRes.op_res_no_right); } if (!dst.isDerivedFrom(user)) { return(OpRes.op_res_no_right); } int childCount = (int)user.sqlDb.getRecordCount(TableName.GM_ACCOUNT, string.Format("owner='{0}' ", dst.m_owner), 0, MySqlDbName.DB_XIANXIA); SqlUpdateGenerator up = new SqlUpdateGenerator(); up.addField("childNodeNumber", childCount, FieldType.TypeNumber); string sql = up.getResultSql(TableName.GM_ACCOUNT, string.Format("acc='{0}' and childNodeNumber=0 ", dst.m_owner)); int count = user.sqlDb.executeOp(sql, user.getMySqlServerID(), MySqlDbName.DB_XIANXIA); if (count >= 0) { SqlDeleteGenerator gen = new SqlDeleteGenerator(); string cmd1 = gen.getResultSql(TableName.GM_ACCOUNT, string.Format(" createCode like '{0}%' ", dst.m_createCode)); user.sqlDb.executeOp(cmd1, user.getMySqlServerID(), MySqlDbName.DB_XIANXIA); string cmd2 = gen.getResultSql(TableName.PLAYER_ACCOUNT_XIANXIA, string.Format(" createCode like '{0}%' ", dst.m_createCode)); count = user.sqlDb.executeOp(cmd2, user.getMySqlServerID(), MySqlDbName.DB_XIANXIA); return(count >= 0 ? OpRes.opres_success : OpRes.op_res_db_failed); } return(OpRes.op_res_db_failed); }
private OpRes delPlayer(ParamDelAcc p, GMUser user) { Player player = new Player(p.m_acc, user); if (!player.m_isExists) { return(OpRes.op_res_player_not_exist); } if (!player.isDerivedFrom(user)) { return(OpRes.op_res_no_right); } SqlDeleteGenerator gen = new SqlDeleteGenerator(); string cmd = gen.getResultSql(TableName.PLAYER_ACCOUNT_XIANXIA, string.Format("acc='{0}'", p.m_acc)); int count = user.sqlDb.executeOp(cmd, user.getMySqlServerID(), MySqlDbName.DB_XIANXIA); return(count > 0 ? OpRes.opres_success : OpRes.op_res_db_failed); }
internal void TranslateCommandTree(Version serverVersion, DbCommandTree commandTree, DbCommand command, bool createParametersForNonSelect = true) { SqlBaseGenerator sqlGenerator; DbQueryCommandTree select; DbInsertCommandTree insert; DbUpdateCommandTree update; DbDeleteCommandTree delete; DbFunctionCommandTree function; if ((select = commandTree as DbQueryCommandTree) != null) { sqlGenerator = new SqlSelectGenerator(select); } else if ((insert = commandTree as DbInsertCommandTree) != null) { sqlGenerator = new SqlInsertGenerator(insert); } else if ((update = commandTree as DbUpdateCommandTree) != null) { sqlGenerator = new SqlUpdateGenerator(update); } else if ((delete = commandTree as DbDeleteCommandTree) != null) { sqlGenerator = new SqlDeleteGenerator(delete); } else if ((function = commandTree as DbFunctionCommandTree) != null) { sqlGenerator = new SqlFunctionGenerator(function); } else { // TODO: get a message (unsupported DbCommandTree type) throw new ArgumentException(); } sqlGenerator.CreateParametersForConstants = select == null && createParametersForNonSelect; sqlGenerator.Command = (NpgsqlCommand)command; sqlGenerator.Version = serverVersion; sqlGenerator.BuildCommand(command); }
public void Gen_Delete_Custom_Keys() { string correctStatement = "DELETE FROM TestClass WHERE TextColumn = 'Blah' AND ScalarColumn = 1"; TestClass T = new TestClass() { DateColumn = DateTime.Parse("1/1/2021"), FloatColumn = 12.12, IntegerColumn = 123, ScalarColumn = 1, TextColumn = "Tomato" }; SqlDeleteGenerator delr = new SqlDeleteGenerator(); var statement = delr.Generate(T, new Func <TestClass, IEnumerable <KeyValuePair <string, object> > >(x => { return(new List <KeyValuePair <string, object> >() { new KeyValuePair <string, object>("TextColumn", "Blah"), new KeyValuePair <string, object>("ScalarColumn", 1) }); })); Assert.AreEqual(correctStatement, statement); }
public override OpRes doDyop(object param, GMUser user) { if (user.isSubAcc()) // 子账号没有操作权限 { return(OpRes.op_res_no_right); } ParamDelDataScoreLog p = (ParamDelDataScoreLog)param; DateTime mint = DateTime.Now, maxt = DateTime.Now; bool res = Tool.splitTimeStr(p.m_timeRange, ref mint, ref maxt); if (!res) { return(OpRes.op_res_time_format_error); } string cond = getCondition(p, mint, user); SqlDeleteGenerator gen = new SqlDeleteGenerator(); string cmd = gen.getResultSql(TableName.GM_SCORE, cond); int count = user.sqlDb.executeOp(cmd, user.getMySqlServerID(), MySqlDbName.DB_XIANXIA); return(count >= 0 ? OpRes.opres_success : OpRes.op_res_db_failed); }
public static async Task WriteSqlScriptsFileAsync(TSqlModel model, GeneratorSettings generatorSettings, Action <double> progressHandler = null) { var fileName = generatorSettings.OutputPath_SqlScripts; var tables = model.GetAllTables().ToDictionary(currTable => currTable.Name.Parts[1].ToLower()); double progress = 0.0; var fileStream = File.Open(fileName, FileMode.Create, FileAccess.Write); var bufferSize = 5 * 1024 * 1024; // 5 MB using (StreamWriter writer = new StreamWriter(fileStream, Encoding.UTF8, bufferSize)) { // Flush stream after every table loop, manually writer.AutoFlush = false; // Loop only on selected tables, or on every table in model if GenerateForAllTables == true IEnumerable <string> tableNames; if (generatorSettings.RunGeneratorForAllTables) { tableNames = tables.Keys; } else { tableNames = (IEnumerable <string>)generatorSettings.RunGeneratorForSelectedTables ?? new string[0]; } var tablesCount = tableNames.Count(); foreach (var currTableName in tableNames) { string sql = ""; var currTable = tables.ContainsKey(currTableName.ToLower()) ? tables[currTableName.ToLower()] : null; if (currTable != null) { sql = new SqlInsertGenerator(generatorSettings, currTable).Generate(); if (sql != string.Empty) { writer.WriteLine(sql); } sql = new SqlTableTypeGenerator(generatorSettings, currTable).Generate(); if (sql != string.Empty) { writer.WriteLine(sql); } sql = new SqlBulkInsertGenerator(generatorSettings, currTable).Generate(); if (sql != string.Empty) { writer.WriteLine(sql); } sql = new SqlUpdateGenerator(generatorSettings, currTable).Generate(); if (sql != string.Empty) { writer.WriteLine(sql); } sql = new SqlDeleteGenerator(generatorSettings, currTable).Generate(); if (sql != string.Empty) { writer.WriteLine(sql); } sql = new SqlSelectAllGenerator(generatorSettings, currTable).Generate(); if (sql != string.Empty) { writer.WriteLine(sql); } sql = new SqlSelectByPKGenerator(generatorSettings, currTable).Generate(); if (sql != string.Empty) { writer.WriteLine(sql); } sql = new SqlSelectByPKListGenerator(generatorSettings, currTable).Generate(); if (sql != string.Empty) { writer.WriteLine(sql); } sql = new SqlSelectByUKGenerator(generatorSettings, currTable).Generate(); if (sql != string.Empty) { writer.WriteLine(sql); } await writer.FlushAsync(); progress += 100.0 / tablesCount; progressHandler?.Invoke((int)progress); } } } return; }