コード例 #1
0
ファイル: SqlRepository.cs プロジェクト: dimi3tron/data.dump
 protected override IDbCommand GetCreateTableCommand(IDbConnection connection, DataTable table)
 {
     return(CreateDbCommand(
                connection,
                $"if OBJECT_ID('{table.TableName}') is null \r\n" +
                "begin \r\n" +
                $"create {TableDefinitionGenerator.GetTableDefinition(table)}; \r\n" +
                "end"
                ));
 }
コード例 #2
0
        protected override IDbCommand GetCreateTableCommand(IDbConnection connection, DataTable table)
        {
            var functionId = $"{Guid.NewGuid():N}";

            return(CreateDbCommand(
                       connection,
                       "start transaction;\r\n" +
                       $"create or replace function create_{functionId} ()\r\n" +
                       "returns void as\r\n" +
                       "$func$\r\n" +
                       "begin\r\n" +
                       $"if (select to_regclass('{table.TableName}') is null) then\r\n" +
                       $"create {TableDefinitionGenerator.GetTableDefinition(table)};\r\n" +
                       "end if;\r\n" +
                       "end\r\n" +
                       "$func$ language plpgsql;\r\n" +
                       $"select  create_{functionId} ();\r\n" +
                       $"drop function create_{functionId};\r\n" +
                       "commit transaction;"
                       ));
        }