コード例 #1
0
 protected DDLActionEnum ValidateVersion(SchemaObject schemaObj)
 {
     return(Anonymous.ValidateVersion(schemaObj, _LowVersion, _HighVersion));
 }
コード例 #2
0
        // 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());
        }