Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        public bool NeedToCreateTrackingTable(DbBuilderOption builderOption)
        {
            if (builderOption.HasFlag(DbBuilderOption.CreateOrUseExistingSchema))
            {
                return(!MySqlManagementUtils.TableExists(connection, transaction, trackingName.UnquotedString));
            }

            return(false);
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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();
                }
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Construct a DbBuilder. You should provide
 /// </summary>
 public DbBuilder(DmTable tableDescription, DbBuilderOption option = DbBuilderOption.CreateOrUseExistingSchema)
 {
     this.TableDescription = tableDescription;
     this.BuilderOption    = option;
 }
Ejemplo n.º 8
0
 public SqliteBuilder(DmTable tableDescription, DbBuilderOption option = DbBuilderOption.CreateOrUseExistingSchema)
     : base(tableDescription, option)
 {
     sqlObjectNames = new SqliteObjectNames(tableDescription);
 }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
 public override DbBuilder GetDatabaseBuilder(DmTable tableDescription, DbBuilderOption options = DbBuilderOption.UseExistingSchema) => new SqlBuilder(tableDescription, options);
Ejemplo n.º 11
0
 public bool NeedToCreateSchema(DbBuilderOption builderOption)
 {
     return(false);
 }
Ejemplo n.º 12
0
 public bool NeedToCreateForeignKeyConstraints(DmRelation constraint, DbBuilderOption builderOption)
 {
     return(false);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Check if we need to create the TVP Type
 /// </summary>
 public bool NeedToCreateType(DbCommandType commandType, DbBuilderOption option)
 {
     return(false);
 }
Ejemplo n.º 14
0
 public async Task<SyncContext> EnsureDatabaseAsync(SyncContext ctx, ScopeInfo scopeInfo, DbBuilderOption options)
     => await this.LocalProvider.EnsureDatabaseAsync(ctx, scopeInfo, options);
Ejemplo n.º 15
0
 public bool NeedToCreateForeignKeyConstraints(DmRelation constraint, DbBuilderOption builderOption)
 {
     throw new NotImplementedException();
 }