public static void CreateDB(String schemaName, DbCreateType dbType) { if (!String.IsNullOrEmpty(schemaName)) { DbHelper.CreateSchema(schemaName); } CreateTables(schemaName, dbType); PopulateTables(schemaName); }
/// <summary> /// Create table in the database. /// </summary> /// <param name="sqls"></param> /// <param name="ctx"></param> /// <param name="currentModel"></param> public virtual void ExecuteSqlInDb(List <string> sqls, ModelContext ctx, Model currentModel) { DbCreateType createType = ctx.AllModels.Settings.DbAction_Create; DBSchema helper = new DBSchema(_conn); string error = "Error executing sql for model : " + currentModel.Name + " table name : " + currentModel.TableName; Try.CatchLog(error, () => { foreach (string sql in sqls) { helper.ExecuteNonQuery(sql, CommandType.Text, null); } }); }
/// <summary> /// Create table in the database. /// </summary> /// <param name="sql"></param> /// <param name="ctx"></param> /// <param name="currentModel"></param> public virtual void ExecuteSqlProcsInDb(BoolMessageItem <List <string> > procs, ModelContext ctx, Model currentModel) { DbCreateType createType = ctx.AllModels.Settings.DbAction_Create; DBSchema helper = new DBSchema(_conn); try { foreach (string sql in procs.Item) { helper.ExecuteNonQuery(sql, CommandType.Text, null); } } catch (Exception ex) { Logger.Error("Error creating tables for model : " + currentModel.Name + " table name : " + currentModel.TableName); Logger.Error(ex.Message); } }
/// <summary> /// Create table in the database. /// </summary> /// <param name="sql"></param> /// <param name="ctx"></param> /// <param name="currentModel"></param> public virtual void ExecuteSqlInDb(string sql, ModelContext ctx, Model currentModel) { DbCreateType createType = ctx.AllModels.Settings.DbAction_Create; DBSchema helper = new DBSchema(_conn); try { if (createType == DbCreateType.DropCreate) { helper.DropTable(currentModel.TableName); } helper.ExecuteNonQuery(sql, CommandType.Text, null); } catch (Exception ex) { Logger.Error("Error creating tables for model : " + currentModel.Name + " table name : " + currentModel.TableName); Logger.Error(ex.Message); } }
private static void CreateTables(String schemaName, DbCreateType dbType) { switch (dbType) { case DbCreateType.Basic: DbHelper.ExecuteNonQueryStatement(GetCreateTableBasicStatement( schemaName, TableName.ADDRESS)); DbHelper.ExecuteNonQueryStatement(GetCreateTableBasicStatement( schemaName, TableName.CATEGORY)); DbHelper.ExecuteNonQueryStatement(GetCreateTableBasicStatement( schemaName, TableName.SUPPLIER)); DbHelper.ExecuteNonQueryStatement(GetCreateTableBasicStatement( schemaName, TableName.CUSTOMER)); DbHelper.ExecuteNonQueryStatement(GetCreateTableBasicStatement( schemaName, TableName.PRODUCT)); DbHelper.ExecuteNonQueryStatement(GetCreateTableBasicStatement( schemaName, TableName.ORDERS)); DbHelper.ExecuteNonQueryStatement(GetCreateTableBasicStatement( schemaName, TableName.ORDERDETAIL)); return; case DbCreateType.PKPartition: DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.ADDRESS)); DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.CATEGORY)); DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.SUPPLIER)); DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.CUSTOMER)); DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.PRODUCT)); DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.ORDERS)); DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.ORDERDETAIL)); return; case DbCreateType.Colocate: DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.ADDRESS)); DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.CATEGORY)); DbHelper.ExecuteNonQueryStatement(GetCreateTableFKPartitionColocateStatement( schemaName, Relation.SUPPLIER_ADDRESS)); DbHelper.ExecuteNonQueryStatement(GetCreateTableFKPartitionColocateStatement( schemaName, Relation.CUSTOMER_ADDRESS)); DbHelper.ExecuteNonQueryStatement(GetCreateTableFKPartitionColocateStatement( schemaName, Relation.PRODUCT_CATEGORY)); DbHelper.ExecuteNonQueryStatement(GetCreateTableFKPartitionColocateStatement( schemaName, Relation.ORDER_CUSTOMER)); DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.ORDERDETAIL)); return; case DbCreateType.FKPartition: return; case DbCreateType.Replicate: DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.ADDRESS)); DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.CATEGORY)); DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.SUPPLIER)); DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.CUSTOMER)); DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.PRODUCT)); DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.ORDERS)); DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.ORDERDETAIL)); return; } }
private static void CreateTables(String schemaName, DbCreateType dbType) { switch (dbType) { case DbCreateType.Basic: DbHelper.ExecuteNonQueryStatement(GetCreateTableBasicStatement( schemaName, TableName.ADDRESS)); DbHelper.ExecuteNonQueryStatement(GetCreateTableBasicStatement( schemaName, TableName.CATEGORY)); DbHelper.ExecuteNonQueryStatement(GetCreateTableBasicStatement( schemaName, TableName.SUPPLIER)); DbHelper.ExecuteNonQueryStatement(GetCreateTableBasicStatement( schemaName, TableName.CUSTOMER)); DbHelper.ExecuteNonQueryStatement(GetCreateTableBasicStatement( schemaName, TableName.PRODUCT)); DbHelper.ExecuteNonQueryStatement(GetCreateTableBasicStatement( schemaName, TableName.ORDERS)); DbHelper.ExecuteNonQueryStatement(GetCreateTableBasicStatement( schemaName, TableName.ORDERDETAIL)); return; case DbCreateType.PKPartition: DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.ADDRESS)); DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.CATEGORY)); DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.SUPPLIER)); DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.CUSTOMER)); DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.PRODUCT)); DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.ORDERS)); DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.ORDERDETAIL)); return; case DbCreateType.Colocate: DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.ADDRESS)); DbHelper.ExecuteNonQueryStatement(GetCreateTablePKPartitionStatement( schemaName, TableName.CATEGORY)); DbHelper.ExecuteNonQueryStatement(GetCreateTableFKPartitionColocateStatement( schemaName, Relation.SUPPLIER_ADDRESS)); DbHelper.ExecuteNonQueryStatement(GetCreateTableFKPartitionColocateStatement( schemaName, Relation.CUSTOMER_ADDRESS)); DbHelper.ExecuteNonQueryStatement(GetCreateTableFKPartitionColocateStatement( schemaName, Relation.PRODUCT_CATEGORY)); DbHelper.ExecuteNonQueryStatement(GetCreateTableFKPartitionColocateStatement( schemaName, Relation.ORDER_CUSTOMER)); DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.ORDERDETAIL)); return; case DbCreateType.FKPartition: return; case DbCreateType.Replicate: DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.ADDRESS)); DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.CATEGORY)); DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.SUPPLIER)); DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.CUSTOMER)); DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.PRODUCT)); DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.ORDERS)); DbHelper.ExecuteNonQueryStatement(GetCreateTableReplicateStatement( schemaName, TableName.ORDERDETAIL)); return; } }
public static void CreateDB(String schemaName, DbCreateType dbType) { if (!String.IsNullOrEmpty(schemaName)) DbHelper.CreateSchema(schemaName); CreateTables(schemaName, dbType); PopulateTables(schemaName); }