Exemplo n.º 1
0
        /// <summary>
        /// Set the default stored procedures names
        /// </summary>
        private void SetDefaultNames()
        {
            var tpref = this.Setup.TriggersPrefix != null ? this.Setup.TriggersPrefix : "";
            var tsuf  = this.Setup.TriggersSuffix != null ? this.Setup.TriggersSuffix : "";

            this.AddName(DbCommandType.InsertTrigger, string.Format(insertTriggerName, $"{tpref}{tableName.Unquoted().Normalized().ToString()}{tsuf}"));
            this.AddName(DbCommandType.UpdateTrigger, string.Format(updateTriggerName, $"{tpref}{tableName.Unquoted().Normalized().ToString()}{tsuf}"));
            this.AddName(DbCommandType.DeleteTrigger, string.Format(deleteTriggerName, $"{tpref}{tableName.Unquoted().Normalized().ToString()}{tsuf}"));

            // Check if we have mutables columns
            var hasMutableColumns = TableDescription.GetMutableColumns(false).Any();


            // Select changes
            this.CreateSelectChangesCommandText();
            this.CreateSelectRowCommandText();
            this.CreateSelectInitializedCommandText();
            this.CreateDeleteCommandText();
            this.CreateDeleteMetadataCommandText();
            this.CreateUpdateCommandText(hasMutableColumns);
            this.CreateResetCommandText();
            this.CreateUpdateUntrackedRowsCommand();

            // Sqlite does not have any constraints, so just return a simple statement
            this.AddName(DbCommandType.DisableConstraints, "Select 0"); // PRAGMA foreign_keys = OFF
            this.AddName(DbCommandType.EnableConstraints, "Select 0");
        }
Exemplo n.º 2
0
        public async Task CreateStoredProceduresAsync(DbConnection connection, DbTransaction transaction)
        {
            if (TableDescription.PrimaryKeys.Count <= 0)
            {
                throw new MissingPrimaryKeyException(TableDescription.TableName);
            }

            // Check if we have mutables columns
            var hasMutableColumns = TableDescription.GetMutableColumns(false).Any();

            var alreadyOpened = connection.State != ConnectionState.Closed;

            if (!alreadyOpened)
            {
                await connection.OpenAsync().ConfigureAwait(false);
            }

            // could be null
            var procBuilder = CreateProcBuilder();

            if (procBuilder == null)
            {
                return;
            }

            await procBuilder.CreateSelectIncrementalChangesAsync(this.Filter, connection, transaction).ConfigureAwait(false);

            await procBuilder.CreateSelectInitializedChangesAsync(this.Filter, connection, transaction).ConfigureAwait(false);

            await procBuilder.CreateSelectRowAsync(connection, transaction).ConfigureAwait(false);

            await procBuilder.CreateUpdateAsync(hasMutableColumns, connection, transaction).ConfigureAwait(false);

            await procBuilder.CreateDeleteAsync(connection, transaction).ConfigureAwait(false);

            await procBuilder.CreateDeleteMetadataAsync(connection, transaction).ConfigureAwait(false);

            await procBuilder.CreateResetAsync(connection, transaction).ConfigureAwait(false);

            if (this.UseBulkProcedures && await procBuilder.NeedToCreateTypeAsync(DbCommandType.BulkTableType, connection, transaction).ConfigureAwait(false))
            {
                await procBuilder.CreateTVPTypeAsync(connection, transaction).ConfigureAwait(false);

                await procBuilder.CreateBulkUpdateAsync(hasMutableColumns, connection, transaction).ConfigureAwait(false);

                await procBuilder.CreateBulkDeleteAsync(connection, transaction).ConfigureAwait(false);
            }

            if (!alreadyOpened)
            {
                connection.Close();
            }
        }