Пример #1
0
        private object _createInheritedTable(string tableName, string inheritFromTable, TableDefinition definition, bool throwIfAlreadyExists)
        {
            if (String.IsNullOrWhiteSpace(tableName))
            {
                throw new ArgumentNullException(nameof(tableName));
            }

            tableName = $"\"{tableName.Trim("\"".ToCharArray())}\"";

            if (String.IsNullOrWhiteSpace(inheritFromTable))
            {
                throw new ArgumentNullException(nameof(inheritFromTable));
            }

            inheritFromTable = $"\"{inheritFromTable}\"";

            var tblName        = $"{(!String.IsNullOrWhiteSpace(ConnectionString.SchemaName) ? $"{ConnectionString.SchemaName}." : "")}{tableName}";
            var inherittblName = $"{(!String.IsNullOrWhiteSpace(ConnectionString.SchemaName) ? $"{ConnectionString.SchemaName}." : "")}{inheritFromTable}";

            try
            {
                var strBuilder = new StringBuilder();
                strBuilder.Append("CREATE TABLE");
                if (!throwIfAlreadyExists)
                {
                    strBuilder.Append(" IF NOT EXISTS");
                }
                strBuilder.AppendLine($" {tblName} (");
                if (definition != null)
                {
                    strBuilder.AppendLine(definition.GetInnerSqlDefinition());
                }
                strBuilder.Append($") INHERITS ({inherittblName})");

                return(new DbExecuter(ConnectionString).ExecuteScalar(strBuilder.ToString()));
            }
            catch (PostgresException ex) when(ex.SqlState == "42P07")
            {
                throw new TableAlreadyExistsException(tableName);
            }
        }
Пример #2
0
 public TypedTable <T> CreateTable <T>(string tableName, TableDefinition <T> definition, bool throwIfAlreadyExists = false)
 {
     _createTable(tableName, definition, throwIfAlreadyExists);
     return(GetTable <T>(tableName));
 }
Пример #3
0
 public TypedTable <T> CreateTableInheritedFrom <T>(string tableName, string inheritFromTable, TableDefinition <T> additionalFields = null, bool throwIfAlreadyExists = false)
 {
     _createInheritedTable(tableName, inheritFromTable, additionalFields, throwIfAlreadyExists);
     return(GetTable <T>(tableName));
 }
Пример #4
0
 public ObjectTable CreateTable(string tableName, TableDefinition definition, bool throwIfAlreadyExists)
 {
     _createTable(tableName, definition, throwIfAlreadyExists);
     return(GetTable(tableName));
 }