public override void SetCommandParameters(DbCommandType commandType, DbCommand command, SyncFilter filter = null) { switch (commandType) { case DbCommandType.SelectChanges: case DbCommandType.SelectChangesWithFilters: this.SetSelecteChangesParameters(command); break; case DbCommandType.SelectRow: this.SetSelectRowParameters(command); break; case DbCommandType.DeleteMetadata: this.SetDeleteMetadataParameters(command); break; case DbCommandType.DeleteRow: this.SetDeleteRowParameters(command); break; case DbCommandType.UpdateRow: this.SetUpdateRowParameters(command); break; case DbCommandType.Reset: this.SetResetParameters(command); break; default: break; } }
public override DbCommand GetCommand(DbCommandType nameType, IEnumerable <string> additionals = null) { var command = this.Connection.CreateCommand(); string text; if (additionals != null) { text = this.sqlObjectNames.GetCommandName(nameType, additionals); } else { text = this.sqlObjectNames.GetCommandName(nameType); } // on Sql Server, everything is Stored Procedure command.CommandType = CommandType.StoredProcedure; command.CommandText = text; command.Connection = Connection; if (Transaction != null) { command.Transaction = Transaction; } return(command); }
public override DbCommand GetCommand(DbCommandType commandType, IEnumerable <FilterClause> additionals = null) { var command = this.Connection.CreateCommand(); string text; bool isStoredProc; if (additionals != null) { (text, isStoredProc) = this.mySqlObjectNames.GetCommandName(commandType, additionals); } else { (text, isStoredProc) = this.mySqlObjectNames.GetCommandName(commandType); } var textName = ParserName.Parse(text, "`"); command.CommandType = isStoredProc ? CommandType.StoredProcedure : CommandType.Text; command.CommandText = isStoredProc ? textName.Quoted().ToString() : text; command.Connection = Connection; if (Transaction != null) { command.Transaction = Transaction; } return(command); }
public override Task AddCommandParametersAsync(DbCommandType commandType, DbCommand command, DbConnection connection, DbTransaction transaction = null, SyncFilter filter = null) { if (command == null) { return(Task.CompletedTask); } if (command.Parameters != null && command.Parameters.Count > 0) { return(Task.CompletedTask); } switch (commandType) { case DbCommandType.DeleteRow: this.SetDeleteRowParameters(command); return(Task.CompletedTask); case DbCommandType.UpdateRow: case DbCommandType.InsertRow: this.SetUpdateRowParameters(command); return(Task.CompletedTask); default: break; } return(base.AddCommandParametersAsync(commandType, command, connection, transaction, filter)); }
public override Task SetCommandParametersAsync(DbCommandType commandType, DbCommand command, SyncFilter filter = null) { switch (commandType) { case DbCommandType.SelectChanges: case DbCommandType.SelectChangesWithFilters: case DbCommandType.SelectInitializedChanges: case DbCommandType.SelectInitializedChangesWithFilters: this.SetSelecteChangesParameters(command, filter); break; case DbCommandType.SelectRow: this.SetSelectRowParameters(command); break; case DbCommandType.DeleteMetadata: this.SetDeleteMetadataParameters(command); break; case DbCommandType.DeleteRow: this.SetDeleteRowParameters(command); break; case DbCommandType.UpdateRow: this.SetUpdateRowParameters(command); break; default: break; } return(Task.CompletedTask); }
public string GetCommandName(DbCommandType objectType, IEnumerable<string> adds = null) { if (!names.ContainsKey(objectType)) throw new NotSupportedException($"MySql provider does not support the command type {objectType.ToString()}"); return names[objectType]; }
public override DbCommand GetCommand(DbCommandType commandType, IEnumerable <string> additionals = null) { var command = this.Connection.CreateCommand(); string text; if (additionals != null) { text = this.postgreSqlObjectNames.GetCommandName(commandType, additionals); } else { text = this.postgreSqlObjectNames.GetCommandName(commandType); } // on MySql, everything is text based :) command.CommandType = CommandType.Text; command.CommandText = text; command.Connection = Connection; if (Transaction != null) { command.Transaction = Transaction; } return(command); }
public override DbCommand GetCommand(DbCommandType commandType, IEnumerable <string> additionals = null) { var command = Connection.CreateCommand(); string text; if (additionals != null) { text = _postgreSqlObjectNames.GetCommandName(commandType, additionals); } else { text = _postgreSqlObjectNames.GetCommandName(commandType); } command.CommandType = CommandType.StoredProcedure; command.CommandText = text; command.Connection = Connection; if (Transaction != null) { command.Transaction = Transaction; } return(command); }
public void AddName(DbCommandType objectType, string name) { if (names.ContainsKey(objectType)) throw new Exception("Yous can't add an objectType multiple times"); names.Add(objectType, name); }
/// <summary> /// return null for all no used commands /// </summary> public override (DbCommand, bool) GetCommand(DbCommandType nameType, SyncFilter filter) { var command = new SqliteCommand(); switch (nameType) { case DbCommandType.UpdateRow: return(CreateUpdateCommand(), false); case DbCommandType.InsertRows: return(CreateInitiliazeRowCommand(), false); case DbCommandType.DeleteRow: return(CreateDeleteCommand(), false); case DbCommandType.DisableConstraints: command.CommandType = CommandType.Text; command.CommandText = this.sqliteObjectNames.GetCommandName(DbCommandType.DisableConstraints, filter); break; case DbCommandType.EnableConstraints: command.CommandType = CommandType.Text; command.CommandText = this.sqliteObjectNames.GetCommandName(DbCommandType.EnableConstraints, filter); break; case DbCommandType.Reset: return(CreateResetCommand(), false); default: return(default, default); } return(command, false); }
public string GetCommandName(DbCommandType objectType, IEnumerable <FilterClause> filters = null) { if (!names.ContainsKey(objectType)) { throw new NotSupportedException($"Sqlite provider does not support the command type {objectType.ToString()}"); } var commandName = names[objectType]; if (filters != null) { string name = ""; string sep = ""; foreach (var c in filters) { var columnName = ParserName.Parse(c.ColumnName).Unquoted().Normalized().ToString(); name += $"{columnName}{sep}"; sep = "_"; } commandName = string.Format(commandName, name); } return(commandName); }
public override DbCommand GetCommand(DbCommandType commandType, IEnumerable <string> additionals = null) { var command = this.Connection.CreateCommand(); string text; if (additionals != null) { text = this.mySqlObjectNames.GetCommandName(commandType, additionals); } else { text = this.mySqlObjectNames.GetCommandName(commandType); } var textName = new ObjectNameParser(text, "`", "`"); // on MySql, everything is text based :) command.CommandType = CommandType.StoredProcedure; command.CommandText = textName.ObjectName; command.Connection = Connection; //if (commandType == DbCommandType.UpdateRow) //{ // command.CommandType = CommandType.StoredProcedure; // command.CommandText = "customers_update"; // command.Connection = Connection; //} if (Transaction != null) { command.Transaction = Transaction; } return(command); }
public override DbCommand GetCommand(DbCommandType nameType, IEnumerable <FilterClause> filters = null) { var command = this.Connection.CreateCommand(); string text; bool isStoredProc; if (filters != null) { (text, isStoredProc) = this.sqlObjectNames.GetCommandName(nameType, filters); } else { (text, isStoredProc) = this.sqlObjectNames.GetCommandName(nameType); } command.CommandType = isStoredProc ? CommandType.StoredProcedure : CommandType.Text; command.CommandText = text; command.Connection = Connection; if (Transaction != null) { command.Transaction = Transaction; } return(command); }
public override DbCommand GetCommand(DbCommandType commandType, IEnumerable <FilterClause> filters = null) { var command = this.Connection.CreateCommand(); string text; if (filters != null) { text = this.sqliteObjectNames.GetCommandName(commandType, filters); } else { text = this.sqliteObjectNames.GetCommandName(commandType); } // on Sqlite, everything is text :) command.CommandType = CommandType.Text; command.CommandText = text; command.Connection = Connection; if (Transaction != null) { command.Transaction = Transaction; } return(command); }
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously private async Task DropProcedureAsync(DbCommandType procType, SyncFilter filter = null) { var commandName = this.mySqlObjectNames.GetCommandName(procType).name; var commandText = $"drop procedure if exists {commandName}"; bool alreadyOpened = connection.State == ConnectionState.Open; try { if (!alreadyOpened) { await connection.OpenAsync().ConfigureAwait(false); } using (var command = new MySqlCommand(commandText, connection)) { if (transaction != null) { command.Transaction = transaction; } await command.ExecuteNonQueryAsync().ConfigureAwait(false); } if (filter != null) { using (var command = new MySqlCommand()) { if (!alreadyOpened) { await connection.OpenAsync().ConfigureAwait(false); } if (this.transaction != null) { command.Transaction = this.transaction; } var commandNameWithFilter = this.mySqlObjectNames.GetCommandName(DbCommandType.SelectChangesWithFilters, filter).name; command.CommandText = $"DROP PROCEDURE {commandNameWithFilter};"; command.Connection = this.connection; await command.ExecuteNonQueryAsync().ConfigureAwait(false); } } } catch (Exception ex) { Debug.WriteLine($"Error during DropProcedureCommand : {ex}"); throw; } finally { if (!alreadyOpened && connection.State != ConnectionState.Closed) { connection.Close(); } } }
public string CreateDropTriggerScriptText(DbCommandType triggerType) { var triggerName = string.Format(this.sqliteObjectNames.GetCommandName(triggerType), tableName.UnquotedStringWithUnderScore); string dropTrigger = $"DROP TRIGGER IF EXISTS {triggerName}"; string str = $"Drop Trigger {triggerName} for table {tableName.QuotedString}"; return(SqliteBuilder.WrapScriptTextWithComments(dropTrigger, str)); }
private void UpdateMetadatas(DbCommandType dbCommandType, DmRow dmRow, ScopeInfo scope) { using (var dbCommand = this.GetCommand(dbCommandType)) { this.SetCommandParameters(dbCommandType, dbCommand); this.InsertOrUpdateMetadatas(dbCommand, dmRow, scope.Id); } }
private string DropProcedureText(DbCommandType procType) { var commandName = this.sqlObjectNames.GetCommandName(procType); var commandText = $"drop procedure if exists {commandName}"; var str1 = $"Drop procedure {commandName} for table {tableName.FullQuotedString}"; return(MySqlBuilder.WrapScriptTextWithComments(commandText, str1)); }
private string DropTriggerText(DbCommandType triggerType) { var commandName = this.mySqlObjectNames.GetCommandName(triggerType).name; var commandText = $"drop trigger if exists {commandName}"; var str1 = $"Drop trigger {commandName} for table {tableName.Quoted().ToString()}"; return(MySqlBuilder.WrapScriptTextWithComments(commandText, str1)); }
private string DropTriggerText(DbCommandType triggerType) { var commandName = _postgreSqlObjectNames.GetCommandName(triggerType); var commandText = $"drop trigger if exists {commandName}"; var str1 = $"Drop trigger {commandName} for table {_tableName.QuotedString}"; return(PostgreSqlBuilder.WrapScriptTextWithComments(commandText, str1)); }
public override Task AddCommandParametersAsync(DbCommandType commandType, DbCommand command, DbConnection connection, DbTransaction transaction = null, SyncFilter filter = null) { if (command == null) { return(Task.CompletedTask); } if (command.Parameters != null && command.Parameters.Count > 0) { return(Task.CompletedTask); } switch (commandType) { case DbCommandType.SelectChanges: case DbCommandType.SelectChangesWithFilters: this.SetSelecteChangesParameters(command); break; case DbCommandType.SelectRow: this.SetSelectRowParameters(command); break; case DbCommandType.DeleteMetadata: this.SetDeleteMetadataParameters(command); break; case DbCommandType.DeleteRow: case DbCommandType.DeleteRows: this.SetDeleteRowParameters(command); break; case DbCommandType.UpdateRow: case DbCommandType.UpdateRows: this.SetUpdateRowParameters(command); break; case DbCommandType.InsertRow: case DbCommandType.InsertRows: this.SetInitializeRowParameters(command); break; case DbCommandType.Reset: this.SetResetParameters(command); break; case DbCommandType.UpdateMetadata: this.SetUpdateMetadataParameters(command); break; default: break; } return(Task.CompletedTask); }
/// <summary> /// Get the command from provider, check connection is opened, affect connection and transaction /// Prepare the command parameters and add scope parameters /// </summary> public async Task <(DbCommand Command, bool IsBatch)> GetCommandAsync(DbCommandType commandType, DbConnection connection, DbTransaction transaction, SyncFilter filter = null) { // Create the key var commandKey = $"{connection.DataSource}-{connection.Database}-{this.TableDescription.GetFullName()}-{commandType}"; var(command, isBatch) = GetCommand(commandType, filter); if (command == null) { return(null, false); } // Add Parameters await this.AddCommandParametersAsync(commandType, command, connection, transaction, filter).ConfigureAwait(false); if (command == null) { throw new MissingCommandException(commandType.ToString()); } if (connection == null) { throw new MissingConnectionException(); } if (connection.State != ConnectionState.Open) { throw new ConnectionClosedException(connection); } command.Connection = connection; command.Transaction = transaction; // Get a lazy command instance var lazyCommand = commands.GetOrAdd(commandKey, k => new Lazy <SyncCommand>(() => { var syncCommand = new SyncCommand(commandKey); return(syncCommand); })); // lazyCommand.Metadata is a boolean indicating if the command is already prepared on the server if (lazyCommand.Value.IsPrepared == true) { return(command, isBatch); } // Testing The Prepare() performance increase command.Prepare(); // Adding this command as prepared lazyCommand.Value.IsPrepared = true; commands.AddOrUpdate(commandKey, lazyCommand, (key, lc) => new Lazy <SyncCommand>(() => lc.Value)); return(command, isBatch); }
public async Task DropTriggerAsync(DbCommandType triggerType, DbConnection connection, DbTransaction transaction) { var triggerName = string.Format(this.mySqlObjectNames.GetCommandName(triggerType).name, tableName.Unquoted().Normalized().ToString()); var commandText = $"DROP TRIGGER IF EXISTS {triggerName}"; using (var command = new MySqlCommand(commandText, (MySqlConnection)connection, (MySqlTransaction)transaction)) { await command.ExecuteNonQueryAsync().ConfigureAwait(false); } }
private async Task DropTriggerAsync(DbCommandType triggerType, DbConnection connection, DbTransaction transaction) { var triggerName = string.Format(this.sqliteObjectNames.GetCommandName(triggerType), tableName.Unquoted().ToString()); var dropTrigger = $"DROP TRIGGER IF EXISTS {triggerName}"; using (var command = new SqliteCommand(dropTrigger, (SqliteConnection)connection, (SqliteTransaction)transaction)) { await command.ExecuteNonQueryAsync().ConfigureAwait(false); } }
/// <summary> /// Check if we need to create the stored procedure /// </summary> public bool NeedToCreateProcedure(DbCommandType commandType) { if (connection.State != ConnectionState.Open) { throw new ArgumentException("Here, we need an opened connection please"); } var commandName = this.sqlObjectNames.GetCommandName(commandType); return(!MySqlManagementUtils.ProcedureExists(connection, transaction, commandName)); }
/// <summary> /// Overriding adapter since the update metadata is not a stored proc that we can override /// </summary> public override DbCommand GetCommand(DbCommandType nameType, SyncFilter filter) { if (nameType == DbCommandType.UpdateMetadata) { var c = new SqlCommand("Set @sync_row_count = 1;"); c.Parameters.Add("@sync_row_count", SqlDbType.Int); return(c); } return(base.GetCommand(nameType, filter)); }
/// <summary> /// Check if we need to create the stored procedure /// </summary> public async Task <bool> NeedToCreateProcedureAsync(DbCommandType commandType) { if (connection.State != ConnectionState.Open) { throw new ArgumentException("Here, we need an opened connection please"); } var commandName = this.mySqlObjectNames.GetCommandName(commandType).name; return(!(await MySqlManagementUtils.ProcedureExistsAsync(connection, transaction, commandName).ConfigureAwait(false))); }
public override (DbCommand, bool) GetCommand(DbCommandType commandType, SyncFilter filter = null) { var command = new SqliteCommand(); string text; text = this.sqliteObjectNames.GetCommandName(commandType, filter); // on Sqlite, everything is text :) command.CommandType = CommandType.Text; command.CommandText = text; return(command, false); }
public override DbCommand GetCommand(DbCommandType nameType, SyncFilter filter) { var command = new SqlCommand(); string text; bool isStoredProc; (text, isStoredProc) = this.sqlObjectNames.GetCommandName(nameType, filter); command.CommandType = isStoredProc ? CommandType.StoredProcedure : CommandType.Text; command.CommandText = text; return(command); }
public string GetCommandName(DbCommandType objectType, SyncFilter filter = null) { if (!names.ContainsKey(objectType)) { throw new NotSupportedException($"Sqlite provider does not support the command type {objectType.ToString()}"); } var commandName = names[objectType]; // concat filter name //if (filter != null) // commandName = string.Format(commandName, filter.GetFilterName()); return(commandName); }