internal static EnumerableRowCollection <DataRow> Get( string sourceTableName) { return(Def.GetSqlIoOfAdmin().ExecuteTable( Def.Code.Sql_GetColumns.Replace("#TableName#", sourceTableName), SqlCmd.Types.PlainSql).AsEnumerable()); }
internal static void CreateTable( string generalTableName, string sourceTableName, bool old, IEnumerable <ColumnDefinition> columnDefinitionCollection, IEnumerable <IndexInfo> tableIndexCollection, EnumerableRowCollection <DataRow> dbColumnCollection, string tableNameTemp = "") { Consoles.Write(sourceTableName, Consoles.Levels.Info); if (tableNameTemp == string.Empty) { tableNameTemp = sourceTableName; } var sqlCmd = new SqlCmd( Def.Code.Sql_CreateTable, SqlCmd.Types.PlainSql, Sqls.GetSqlParamCollection()); sqlCmd.CreateColumn(sourceTableName, columnDefinitionCollection); sqlCmd.CreatePk(sourceTableName, columnDefinitionCollection, tableIndexCollection); sqlCmd.CreateIx(generalTableName, sourceTableName, old, columnDefinitionCollection); sqlCmd.CreateDefault(tableNameTemp, columnDefinitionCollection, dbColumnCollection); sqlCmd.DropConstraints(sourceTableName, tableIndexCollection); sqlCmd.CommandText = sqlCmd.CommandText.Replace("#TableName#", tableNameTemp); Def.GetSqlIoOfAdmin(transactional: true).ExecuteNonQuery(sqlCmd); }
internal static void MigrateTable( string generalTableName, string sourceTableName, bool old, IEnumerable <ColumnDefinition> columnDefinitionCollection, IEnumerable <IndexInfo> tableIndexCollection) { Consoles.Write(generalTableName, Consoles.Levels.Info); var destinationTableName = Times.Full() + "_" + sourceTableName; CreateTable( generalTableName, sourceTableName, old, columnDefinitionCollection, tableIndexCollection, null, destinationTableName); if (Def.ExistsTable(generalTableName, o => o.Identity && !sourceTableName.EndsWith("_deleted") && !sourceTableName.EndsWith("_old"))) { Def.GetSqlIoOfAdmin().ExecuteNonQuery( GetMigrateSql( Def.Code.Sql_MigrateTableWithIdentity, columnDefinitionCollection, sourceTableName, destinationTableName), SqlCmd.Types.PlainSql); } else { Def.GetSqlIoOfAdmin().ExecuteNonQuery( GetMigrateSql( Def.Code.Sql_MigrateTable, columnDefinitionCollection, sourceTableName, destinationTableName), SqlCmd.Types.PlainSql); } }
internal static bool Exists(string sourceTableName) { return(Def.GetSqlIoOfAdmin().ExecuteTable( Def.Code.Sql_ExistsTable.Replace("#TableName#", sourceTableName), SqlCmd.Types.PlainSql).Rows.Count == 1); }