/// <summary> /// Check if we need to create the table in the current database /// </summary> public bool NeedToCreateTable(DbBuilderOption builderOptions) { if (builderOptions.HasFlag(DbBuilderOption.CreateOrUseExistingSchema)) { return(!SQLiteManagementUtils.TableExists(connection, transaction, tableName.QuotedString)); } return(false); }
public bool NeedToCreateTrackingTable(DbBuilderOption builderOption) { if (builderOption.HasFlag(DbBuilderOption.CreateOrUseExistingSchema)) { return(!MySqlManagementUtils.TableExists(connection, transaction, trackingName.UnquotedString)); } return(false); }
/// <summary> /// Check if we need to create the table in the current database /// </summary> public bool NeedToCreateSchema(DbBuilderOption builderOptions) { if (string.IsNullOrEmpty(tableName.SchemaName) || tableName.SchemaName.ToLowerInvariant() == "dbo") { return(false); } if (builderOptions.HasFlag(DbBuilderOption.CreateOrUseExistingSchema)) { return(!SqlManagementUtils.SchemaExists(connection, transaction, tableName.SchemaName)); } return(false); }
/// <summary> /// Check if we need to create the stored procedure /// </summary> public bool NeedToCreateProcedure(DbCommandType commandType, DbBuilderOption option) { if (connection.State != ConnectionState.Open) { throw new ArgumentException("Here, we need an opened connection please"); } var commandName = this.sqlObjectNames.GetCommandName(commandType); if (option.HasFlag(DbBuilderOption.CreateOrUseExistingSchema)) { return(!MySqlManagementUtils.ProcedureExists(connection, transaction, commandName)); } return(false); }
public bool NeedToCreateTrigger(DbTriggerType type, DbBuilderOption option) { var updTriggerName = string.Format(this.sqliteObjectNames.GetCommandName(DbCommandType.UpdateTrigger), tableName.UnquotedStringWithUnderScore); var delTriggerName = string.Format(this.sqliteObjectNames.GetCommandName(DbCommandType.DeleteTrigger), tableName.UnquotedStringWithUnderScore); var insTriggerName = string.Format(this.sqliteObjectNames.GetCommandName(DbCommandType.InsertTrigger), tableName.UnquotedStringWithUnderScore); if (option.HasFlag(DbBuilderOption.CreateOrUseExistingSchema)) { string triggerName = string.Empty; switch (type) { case DbTriggerType.Insert: { triggerName = insTriggerName; break; } case DbTriggerType.Update: { triggerName = updTriggerName; break; } case DbTriggerType.Delete: { triggerName = delTriggerName; break; } } return(!MySqlManagementUtils.TriggerExists(connection, transaction, triggerName)); } if (option.HasFlag(DbBuilderOption.UseExistingSchema)) { return(false); } return(false); }
public bool NeedToCreateForeignKeyConstraints(DmRelation foreignKey, DbBuilderOption builderOptions) { if (!builderOptions.HasFlag(DbBuilderOption.CreateOrUseExistingSchema)) { return(false); } string parentTable = foreignKey.ParentTable.TableName; string parentSchema = foreignKey.ParentTable.Schema; string parentFullName = String.IsNullOrEmpty(parentSchema) ? parentTable : $"{parentSchema}.{parentTable}"; bool alreadyOpened = connection.State == ConnectionState.Open; try { if (!alreadyOpened) { connection.Open(); } var dmTable = SqlManagementUtils.RelationsForTable(connection, transaction, parentFullName); var foreignKeyExist = dmTable.Rows.Any(r => dmTable.IsEqual(r["ForeignKey"].ToString(), foreignKey.RelationName)); return(!foreignKeyExist); } catch (Exception ex) { Logger.Current.Error($"Error during checking foreign keys: {ex}"); throw; } finally { if (!alreadyOpened && connection.State != ConnectionState.Closed) { connection.Close(); } } }
/// <summary> /// Construct a DbBuilder. You should provide /// </summary> public DbBuilder(DmTable tableDescription, DbBuilderOption option = DbBuilderOption.CreateOrUseExistingSchema) { this.TableDescription = tableDescription; this.BuilderOption = option; }
public SqliteBuilder(DmTable tableDescription, DbBuilderOption option = DbBuilderOption.CreateOrUseExistingSchema) : base(tableDescription, option) { sqlObjectNames = new SqliteObjectNames(tableDescription); }
public async Task <SyncContext> EnsureDatabaseAsync(SyncContext context, ScopeInfo scopeInfo, DbBuilderOption options) { HttpMessage httpMessage = new HttpMessage { SyncContext = context }; httpMessage.Step = HttpStep.EnsureDatabase; HttpEnsureDatabaseMessage ensureDatabaseMessage = new HttpEnsureDatabaseMessage { DbBuilderOption = options, ScopeInfo = scopeInfo }; httpMessage.EnsureDatabase = ensureDatabaseMessage; //Post request and get response var httpMessageResponse = await this.httpRequestHandler.ProcessRequest(context, httpMessage, cancellationToken); if (httpMessageResponse == null) { throw new Exception("Can't have an empty body"); } return(httpMessageResponse.SyncContext); }
public override DbBuilder GetDatabaseBuilder(DmTable tableDescription, DbBuilderOption options = DbBuilderOption.UseExistingSchema) => new SqlBuilder(tableDescription, options);
public bool NeedToCreateSchema(DbBuilderOption builderOption) { return(false); }
public bool NeedToCreateForeignKeyConstraints(DmRelation constraint, DbBuilderOption builderOption) { return(false); }
/// <summary> /// Check if we need to create the TVP Type /// </summary> public bool NeedToCreateType(DbCommandType commandType, DbBuilderOption option) { return(false); }
public async Task<SyncContext> EnsureDatabaseAsync(SyncContext ctx, ScopeInfo scopeInfo, DbBuilderOption options) => await this.LocalProvider.EnsureDatabaseAsync(ctx, scopeInfo, options);
public bool NeedToCreateForeignKeyConstraints(DmRelation constraint, DbBuilderOption builderOption) { throw new NotImplementedException(); }