protected DDLActionEnum ValidateVersion(SchemaObject schemaObj) { return(Anonymous.ValidateVersion(schemaObj, _LowVersion, _HighVersion)); }
public void BuildDDL(CaseSchema currentSchema, ref StringBuilder strCreateDDL, ref StringBuilder strDropDDL) { if (currentSchema == null) { return; } if (strCreateDDL == null) { strCreateDDL = new StringBuilder(); } strCreateDDL.Capacity = 36 * ByteUnit.KiloByte; // reserve 36K if (strDropDDL == null) { strDropDDL = new StringBuilder(); } strDropDDL.Capacity = 12 * ByteUnit.KiloByte; // reserve 12K ////////////////////////////// // Build objects // Initialize... ArrayList roleList = new ArrayList(); ArrayList grantList = new ArrayList(); ArrayList denyList = new ArrayList(); ArrayList tableList = new ArrayList(); ArrayList indexList = new ArrayList(); ArrayList foreignKeyList = new ArrayList(); ArrayList primaryKeyList = new ArrayList(); ArrayList uniqkeyList = new ArrayList(); ArrayList colAlterList = new ArrayList(); StringBuilder strRowDataSql = new StringBuilder(4 * ByteUnit.KiloByte); // Build! GlobalTableCollection globalTables = currentSchema.GlobalTables; foreach (GlobalTableDef tableDef in globalTables) { Anonymous.SafeAdd(ref tableList, BuildTable(tableDef, ref indexList, ref primaryKeyList, ref uniqkeyList, ref foreignKeyList, ref strRowDataSql, ref colAlterList)); } CaseTableDefCollection caseTables = currentSchema.CaseTables; foreach (CaseTableDef caseTableDef in caseTables) { Anonymous.SafeAdd(ref tableList, BuildTable(caseTableDef, ref indexList, ref primaryKeyList, ref uniqkeyList, ref foreignKeyList, ref strRowDataSql, ref colAlterList)); } ArrayList procedureList = new ArrayList(); ArrayList functionList = new ArrayList(); SQLStoredProcedureCollection spList = currentSchema.SQLStoredProcedures; foreach (SQLStoredProcedure spDef in spList) { Anonymous.SafeAdd(ref procedureList, BuildStoredProc(spDef, ref grantList, ref denyList)); } ArrayList viewList = new ArrayList(); ViewCollection globalViews = currentSchema.Views; foreach (View viewDef in globalViews) { Anonymous.SafeAdd(ref viewList, BuildView(viewDef)); } BuildRoleList(ref roleList, grantList, denyList); ////////////////////////////// // Build SQL // initialize temp stringBuilder... StringBuilder strPKConstraint = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strUKConstraint = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strFKConstraint = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strAlterColumn = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strDropIndex = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strDropProc = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strDropView = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strDropTable = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strDropRole = new StringBuilder(1 * ByteUnit.KiloByte); // build... BuildSQL(ref strCreateDDL, ref strDropRole, roleList); BuildSQL(ref strCreateDDL, ref strDropTable, tableList); BuildSQL(ref strCreateDDL, ref strDropIndex, indexList); BuildAlterSQL(ref strCreateDDL, ref strPKConstraint, primaryKeyList); BuildAlterSQL(ref strCreateDDL, ref strUKConstraint, uniqkeyList); BuildAlterSQL(ref strCreateDDL, ref strFKConstraint, foreignKeyList); BuildAlterSQL(ref strCreateDDL, ref strAlterColumn, colAlterList); BuildSQL(ref strCreateDDL, ref strDropProc, procedureList); BuildSQL(ref strCreateDDL, ref strDropView, viewList); ObjPermSQLBuilder permBuilder = new ObjPermSQLBuilder(); foreach (GranteeMeta granteeTmp in grantList) { AppendBatch(ref strCreateDDL, permBuilder.BuildGrantSQL(granteeTmp), _dbmsPlatform); } strCreateDDL.Append(strRowDataSql); strDropDDL.Append(strFKConstraint); strDropDDL.Append(strUKConstraint); strDropDDL.Append(strPKConstraint); strDropDDL.Append(strDropIndex); strDropDDL.Append(strDropProc); strDropDDL.Append(strDropView); strDropDDL.Append(strDropTable); strDropDDL.Append(strDropRole); }
protected void AppendBatch(ref StringBuilder strTarget, string strSrc, DBMSPlatformEnum dbmsPlatform) { Anonymous.AppendBatch(ref strTarget, strSrc, dbmsPlatform); }
// INSERT INTO MyTable (PriKey, Description) // VALUES (123, 'A description of part 123.') public static string BuildInsertLine(TableRowCollection rowCollection, TableMeta tableObj, Version lowVersion, Version highVersion) { string strTableName = tableObj.FullName; StringBuilder strInsertBatch = new StringBuilder(1024); // at least 1K string strInsertSQL = string.Empty; strInsertSQL += "INSERT INTO "; strInsertSQL += strTableName; foreach (TableRow tblRow in rowCollection) { DDLActionEnum action = Anonymous.ValidateVersion(tblRow, lowVersion, highVersion); if (action == DDLActionEnum.NONE) // not in range! { continue; } StringBuilder strInsertLineTmp = new StringBuilder(strInsertSQL); StringBuilder strColumnData = new StringBuilder(); strInsertLineTmp.Append(" ( "); TableFieldValueCollection fields = tblRow.FieldValues; for (int nInd = 0; nInd < fields.Count; nInd++) { TableFieldValue field = fields[nInd]; //if ( field.IsNull == false ) // continue; ColumnMeta colMetaTmp = tableObj.GetColMeta(field.Name); if (colMetaTmp == null) { Debug.Assert(false, "Column " + field.Name + " not found!"); continue; } if (strColumnData.Length > 0) { strInsertLineTmp.Append(","); strColumnData.Append(","); } strInsertLineTmp.Append(field.Name); if (IsNumeric(colMetaTmp.DataType.TypeEnum)) { strColumnData.Append(field.FieldValue); } else // Quote the value { strColumnData.Append(CHAR.SINGLEQUOTE); strColumnData.Append(field.FieldValue); strColumnData.Append(CHAR.SINGLEQUOTE); } } strInsertLineTmp.Append(" ) \n"); strInsertLineTmp.Append("VALUES ("); strInsertLineTmp.Append(strColumnData); strInsertLineTmp.Append(")"); strInsertBatch.Append(strInsertLineTmp); strInsertBatch.Append(KWD.SQLSVR_BD); } return(strInsertBatch.ToString()); }