Example #1
0
 protected override void BuildCreateTableNullAttribute(SqlField field, DefaultNullable defaultNullable)
 {
     if (!field.CanBeNull)
     {
         StringBuilder.Append("NOT NULL");
     }
 }
Example #2
0
        protected override void BuildCreateTableNullAttribute(SqlField field, DefaultNullable defaultNullable)
        {
            if (field.CanBeNull && field.Type.DataType == DataType.Guid)
            {
                return;
            }

            base.BuildCreateTableNullAttribute(field, defaultNullable);
        }
Example #3
0
        protected override void BuildCreateTableNullAttribute(SqlField field, DefaultNullable defaultNullable)
        {
            // BIT cannot be nullable in ASE
            if (field.CanBeNull && field.Type.DataType == DataType.Boolean)
            {
                return;
            }

            base.BuildCreateTableNullAttribute(field, defaultNullable);
        }
Example #4
0
            public static ITable <T> Query(IDataContext dataContext,
                                           string tableName, string databaseName, string schemaName,
                                           string statementHeader, string statementFooter,
                                           DefaultNullable defaultNullable)
            {
                var sqlTable    = new SqlTable <T>(dataContext.MappingSchema);
                var createTable = new SqlCreateTableStatement();

                if (tableName != null)
                {
                    sqlTable.PhysicalName = tableName;
                }
                if (databaseName != null)
                {
                    sqlTable.Database = databaseName;
                }
                if (schemaName != null)
                {
                    sqlTable.Schema = schemaName;
                }

                createTable.Table           = sqlTable;
                createTable.StatementHeader = statementHeader;
                createTable.StatementFooter = statementFooter;
                createTable.DefaultNullable = defaultNullable;

                var query = new Query <int>(dataContext, null)
                {
                    Queries = { new QueryInfo {
                                    Statement = createTable,
                                } }
                };

                SetNonQueryQuery(query);

                query.GetElement(dataContext, Expression.Constant(null), null);

                ITable <T> table = new Table <T>(dataContext);

                if (tableName != null)
                {
                    table = table.TableName(tableName);
                }
                if (databaseName != null)
                {
                    table = table.DatabaseName(databaseName);
                }
                if (schemaName != null)
                {
                    table = table.SchemaName(schemaName);
                }

                return(table);
            }
Example #5
0
 protected override void BuildCreateTableNullAttribute(SqlField field, DefaultNullable defaulNullable)
 {
     if (defaulNullable == DefaultNullable.Null && field.CanBeNull)
     {
         return;
     }
     else if (defaulNullable == DefaultNullable.NotNull && !field.CanBeNull)
     {
         return;
     }
     StringBuilder.Append(field.CanBeNull ? "        " : "NOT NULL");
 }
 /// <summary>
 /// Creates new table in database for mapping class <typeparamref name="T"/>.
 /// Information about table name, columns names and types is taken from mapping class.
 /// </summary>
 /// <typeparam name="T">Mapping class.</typeparam>
 /// <param name="dataContext">Database connection context.</param>
 /// <param name="tableName">Optional table name to override default table name, extracted from <typeparamref name="T"/> mapping.</param>
 /// <param name="databaseName">Optional database name, to override default database name. See <see cref="LinqExtensions.DatabaseName{T}(ITable{T}, string)"/> method for support information per provider.</param>
 /// <param name="schemaName">Optional schema/owner name, to override default name. See <see cref="LinqExtensions.SchemaName{T}(ITable{T}, string)"/> method for support information per provider.</param>
 /// <param name="statementHeader">Optional replacement for <c>"CREATE TABLE table_name"</c> header. Header is a template with <c>{0}</c> parameter for table name.</param>
 /// <param name="statementFooter">Optional SQL, appended to generated create table statement.</param>
 /// <param name="defaultNullable">Defines how columns nullability flag should be generated:
 /// <para> - <see cref="DefaultNullable.Null"/> - generate only <c>NOT NULL</c> for non-nullable fields. Missing nullability information treated as <c>NULL</c> by database.</para>
 /// <para> - <see cref="DefaultNullable.NotNull"/> - generate only <c>NULL</c> for nullable fields. Missing nullability information treated as <c>NOT NULL</c> by database.</para>
 /// <para> - <see cref="DefaultNullable.None"/> - explicitly generate <c>NULL</c> and <c>NOT NULL</c> for all columns.</para>
 /// Default value: <see cref="DefaultNullable.None"/>.
 /// </param>
 /// <returns>Created table as queryable source.</returns>
 public static ITable <T> CreateTable <T>([NotNull] this IDataContext dataContext,
                                          string tableName                = null,
                                          string databaseName             = null,
                                          string schemaName               = null,
                                          string statementHeader          = null,
                                          string statementFooter          = null,
                                          DefaultNullable defaultNullable = DefaultNullable.None)
 {
     if (dataContext == null)
     {
         throw new ArgumentNullException(nameof(dataContext));
     }
     return(QueryRunner.CreateTable <T> .Query(dataContext,
                                               tableName, databaseName, schemaName, statementHeader, statementFooter, defaultNullable));
 }
 /// <summary>
 /// Asynchronously creates new table in database for mapping class <typeparamref name="T"/>.
 /// Information about table name, columns names and types is taken from mapping class.
 /// </summary>
 /// <typeparam name="T">Mapping class.</typeparam>
 /// <param name="dataContext">Database connection context.</param>
 /// <param name="tableName">Optional table name to override default table name, extracted from <typeparamref name="T"/> mapping.</param>
 /// <param name="databaseName">Optional database name, to override default database name. See <see cref="LinqExtensions.DatabaseName{T}(ITable{T}, string)"/> method for support information per provider.</param>
 /// <param name="schemaName">Optional schema/owner name, to override default name. See <see cref="LinqExtensions.SchemaName{T}(ITable{T}, string)"/> method for support information per provider.</param>
 /// <param name="statementHeader">Optional replacement for <c>"CREATE TABLE table_name"</c> header. Header is a template with <c>{0}</c> parameter for table name.</param>
 /// <param name="statementFooter">Optional SQL, appended to generated create table statement.</param>
 /// <param name="defaultNullable">Defines how columns nullability flag should be generated:
 /// <para> - <see cref="DefaultNullable.Null"/> - generate only <c>NOT NULL</c> for non-nullable fields. Missing nullability information treated as <c>NULL</c> by database.</para>
 /// <para> - <see cref="DefaultNullable.NotNull"/> - generate only <c>NULL</c> for nullable fields. Missing nullability information treated as <c>NOT NULL</c> by database.</para>
 /// <para> - <see cref="DefaultNullable.None"/> - explicitly generate <c>NULL</c> and <c>NOT NULL</c> for all columns.</para>
 /// Default value: <see cref="DefaultNullable.None"/>.
 /// </param>
 /// <param name="token">Optional asynchronous operation cancellation token.</param>
 /// <returns>Created table as queryable source.</returns>
 public static Task <ITable <T> > CreateTableAsync <T>([NotNull] this IDataContext dataContext,
                                                       string tableName                = null,
                                                       string databaseName             = null,
                                                       string schemaName               = null,
                                                       string statementHeader          = null,
                                                       string statementFooter          = null,
                                                       DefaultNullable defaultNullable = DefaultNullable.None,
                                                       CancellationToken token         = default)
 {
     if (dataContext == null)
     {
         throw new ArgumentNullException(nameof(dataContext));
     }
     return(QueryRunner.CreateTable <T> .QueryAsync(dataContext,
                                                    tableName, databaseName, schemaName, statementHeader, statementFooter, defaultNullable, token));
 }
Example #8
0
            public static async Task <ITable <T> > QueryAsync(
                IDataContext dataContext,
                string?tableName,
                string?serverName,
                string?databaseName,
                string?schemaName,
                string?statementHeader,
                string?statementFooter,
                DefaultNullable defaultNullable,
                TableOptions tableOptions,
                CancellationToken token)
            {
                var sqlTable    = new SqlTable <T>(dataContext.MappingSchema);
                var createTable = new SqlCreateTableStatement(sqlTable);

                if (tableName != null)
                {
                    sqlTable.PhysicalName = tableName;
                }
                if (serverName != null)
                {
                    sqlTable.Server = serverName;
                }
                if (databaseName != null)
                {
                    sqlTable.Database = databaseName;
                }
                if (schemaName != null)
                {
                    sqlTable.Schema = schemaName;
                }
                if (tableOptions.IsSet())
                {
                    sqlTable.TableOptions = tableOptions;
                }

                createTable.StatementHeader = statementHeader;
                createTable.StatementFooter = statementFooter;
                createTable.DefaultNullable = defaultNullable;

                var query = new Query <int>(dataContext, null)
                {
                    Queries = { new QueryInfo {
                                    Statement = createTable,
                                } }
                };

                SetNonQueryQuery(query);

                await query.GetElementAsync(dataContext, ExpressionInstances.UntypedNull, null, null, token).ConfigureAwait(Common.Configuration.ContinueOnCapturedContext);

                ITable <T> table = new Table <T>(dataContext);

                if (sqlTable.PhysicalName != null)
                {
                    table = table.TableName(sqlTable.PhysicalName);
                }
                if (sqlTable.Server != null)
                {
                    table = table.ServerName(sqlTable.Server);
                }
                if (sqlTable.Database != null)
                {
                    table = table.DatabaseName(sqlTable.Database);
                }
                if (sqlTable.Schema != null)
                {
                    table = table.SchemaName(sqlTable.Schema);
                }
                if (sqlTable.TableOptions.IsSet())
                {
                    table = table.TableOptions(sqlTable.TableOptions);
                }

                return(table);
            }
 protected override void BuildCreateTableNullAttribute(SqlField field, DefaultNullable defaulNullable) {
   if ((defaulNullable != DefaultNullable.Null || !field.CanBeNull) && (defaulNullable != DefaultNullable.NotNull || field.CanBeNull)) {
     StringBuilder.Append(field.CanBeNull ? " " : "NOT NULL");
   }
 }
Example #10
0
            public static ITable <T> Query(
                IDataContext dataContext,
                string?tableName,
                string?serverName,
                string?databaseName,
                string?schemaName,
                string?statementHeader,
                string?statementFooter,
                DefaultNullable defaultNullable,
                TableOptions tableOptions)
            {
                var sqlTable    = new SqlTable <T>(dataContext.MappingSchema);
                var createTable = new SqlCreateTableStatement(sqlTable);

                if (tableName != null || schemaName != null || databaseName != null || databaseName != null)
                {
                    sqlTable.TableName = new(
                        tableName ?? sqlTable.TableName.Name,
                        Server  : serverName ?? sqlTable.TableName.Server,
                        Database : databaseName ?? sqlTable.TableName.Database,
                        Schema  : schemaName ?? sqlTable.TableName.Schema);
                }

                if (tableOptions.IsSet())
                {
                    sqlTable.TableOptions = tableOptions;
                }

                createTable.StatementHeader = statementHeader;
                createTable.StatementFooter = statementFooter;
                createTable.DefaultNullable = defaultNullable;

                var query = new Query <int>(dataContext, null)
                {
                    Queries = { new QueryInfo {
                                    Statement = createTable,
                                } }
                };

                SetNonQueryQuery(query);

                query.GetElement(dataContext, ExpressionInstances.UntypedNull, null, null);

                ITable <T> table = new Table <T>(dataContext);

                if (sqlTable.TableName.Name != null)
                {
                    table = table.TableName(sqlTable.TableName.Name);
                }
                if (sqlTable.TableName.Server != null)
                {
                    table = table.ServerName(sqlTable.TableName.Server);
                }
                if (sqlTable.TableName.Database != null)
                {
                    table = table.DatabaseName(sqlTable.TableName.Database);
                }
                if (sqlTable.TableName.Schema != null)
                {
                    table = table.SchemaName(sqlTable.TableName.Schema);
                }
                if (sqlTable.TableOptions.IsSet())
                {
                    table = table.TableOptions(sqlTable.TableOptions);
                }

                return(table);
            }