コード例 #1
0
        internal string GetOutputIdentityCmd(string identityColumn, ColumnDirection outputIdentity, string tmpTableName, OperationType operation)
        {
            StringBuilder sb = new StringBuilder();

            if (identityColumn == null || outputIdentity != ColumnDirection.InputOutput)
            {
                return("; ");
            }
            if (operation == OperationType.Insert)
            {
                sb.Append("OUTPUT INSERTED." + identityColumn + " INTO " + tmpTableName + "(" + identityColumn + "); ");
            }

            else if (operation == OperationType.InsertOrUpdate || operation == OperationType.Update)
            {
                sb.Append("OUTPUT Source." + Constants.InternalId + ", INSERTED." + identityColumn + " INTO " + tmpTableName
                          + "(" + Constants.InternalId + ", " + identityColumn + "); ");
            }

            else if (operation == OperationType.Delete)
            {
                sb.Append("OUTPUT Source." + Constants.InternalId + ", DELETED." + identityColumn + " INTO " + tmpTableName
                          + "(" + Constants.InternalId + ", " + identityColumn + "); ");
            }

            return(sb.ToString());
        }
コード例 #2
0
        #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member

        /// <summary>
        ///
        /// </summary>
        /// <param name="list"></param>
        /// <param name="tableName"></param>
        /// <param name="schema"></param>
        /// <param name="columns"></param>
        /// <param name="disableIndexList"></param>
        /// <param name="disableAllIndexes"></param>
        /// <param name="customColumnMappings"></param>
        /// <param name="sqlTimeout"></param>
        /// <param name="bulkCopyTimeout"></param>
        /// <param name="bulkCopyEnableStreaming"></param>
        /// <param name="bulkCopyNotifyAfter"></param>
        /// <param name="bulkCopyBatchSize"></param>
        /// <param name="sqlBulkCopyOptions"></param>
        /// <param name="ext"></param>
        protected AbstractOperation(IEnumerable <T> list, string tableName, string schema, HashSet <string> columns,
                                    HashSet <string> disableIndexList, bool disableAllIndexes,
                                    Dictionary <string, string> customColumnMappings, int sqlTimeout, int bulkCopyTimeout,
                                    bool bulkCopyEnableStreaming,
                                    int?bulkCopyNotifyAfter, int?bulkCopyBatchSize, SqlBulkCopyOptions sqlBulkCopyOptions, BulkOperations ext)
        {
            _list                    = list;
            _tableName               = tableName;
            _schema                  = schema;
            _columns                 = columns;
            _disableIndexList        = disableIndexList;
            _disableAllIndexes       = disableAllIndexes;
            _customColumnMappings    = customColumnMappings;
            _sqlTimeout              = sqlTimeout;
            _bulkCopyTimeout         = bulkCopyTimeout;
            _bulkCopyEnableStreaming = bulkCopyEnableStreaming;
            _bulkCopyNotifyAfter     = bulkCopyNotifyAfter;
            _bulkCopyBatchSize       = bulkCopyBatchSize;
            _sqlBulkCopyOptions      = sqlBulkCopyOptions;
            _ext               = ext;
            _identityColumn    = null;
            _helper            = new BulkOperationsHelper();
            _outputIdentityDic = new Dictionary <int, T>();
            _outputIdentity    = ColumnDirection.Input;
            _matchTargetOn     = new List <string>();
        }
コード例 #3
0
        internal string GetOutputCreateTableCmd(ColumnDirection outputIdentity, string tmpTablename, OperationType operation, string identityColumn)
        {
            if (operation == OperationType.Insert)
            {
                return(outputIdentity == ColumnDirection.InputOutput ? "CREATE TABLE " + tmpTablename + "(" + "[" + identityColumn + "] int); " : "");
            }

            else if (operation == OperationType.InsertOrUpdate || operation == OperationType.Update || operation == OperationType.Delete)
            {
                return(outputIdentity == ColumnDirection.InputOutput ? "CREATE TABLE " + tmpTablename + "("
                       + "[" + Constants.InternalId + "]" + " int, [" + identityColumn + "] int); " : "");
            }

            return(string.Empty);
        }
コード例 #4
0
ファイル: BulkInsert.cs プロジェクト: willyt150/SqlBulkTools
 /// <summary>
 /// Sets the identity column for the table. Required if an Identity column exists in table and one of the two
 /// following conditions is met: (1) MatchTargetOn list contains an identity column (2) AddAllColumns is used in setup.
 /// </summary>
 /// <param name="columnName"></param>
 /// <param name="outputIdentity"></param>
 /// <returns></returns>
 public BulkInsert <T> SetIdentityColumn(Expression <Func <T, object> > columnName, ColumnDirection outputIdentity)
 {
     base.SetIdentity(columnName, outputIdentity);
     return(this);
 }
コード例 #5
0
        internal string GetInsertIntoStagingTableCmd(SqlCommand command, SqlConnection conn, string schema, string tableName,
                                                     HashSet <string> columns, string identityColumn, ColumnDirection outputIdentity)
        {
            string fullTableName = GetFullQualifyingTableName(conn.Database, schema,
                                                              tableName);

            string comm =
                GetOutputCreateTableCmd(outputIdentity, Constants.TempOutputTableName,
                                        OperationType.Insert, identityColumn) +
                BuildInsertIntoSet(columns, identityColumn, fullTableName)
                + "OUTPUT INSERTED.[" + identityColumn + "] INTO "
                + Constants.TempOutputTableName + "([" + identityColumn + "]) "
                + BuildSelectSet(columns, Constants.SourceAlias, identityColumn)
                + " FROM " + Constants.TempTableName + " AS Source; " +
                "DROP TABLE " + Constants.TempTableName + ";";

            return(comm);
        }
コード例 #6
0
        internal string BuildCreateTempTable(HashSet <string> columns, DataTable schema, ColumnDirection outputIdentity)
        {
            Dictionary <string, string>        actualColumns = new Dictionary <string, string>();
            Dictionary <string, string>        actualColumnsMaxCharLength     = new Dictionary <string, string>();
            Dictionary <string, PrecisionType> actualColumnsNumericPrecision  = new Dictionary <string, PrecisionType>();
            Dictionary <string, string>        actualColumnsDateTimePrecision = new Dictionary <string, string>();


            foreach (DataRow row in schema.Rows)
            {
                string columnType = row["DATA_TYPE"].ToString();
                string columnName = row["COLUMN_NAME"].ToString();

                actualColumns.Add(row["COLUMN_NAME"].ToString(), row["DATA_TYPE"].ToString());

                if (columnType == "varchar" || columnType == "nvarchar" ||
                    columnType == "char" || columnType == "binary" ||
                    columnType == "varbinary" || columnType == "nchar")

                {
                    actualColumnsMaxCharLength.Add(row["COLUMN_NAME"].ToString(),
                                                   row["CHARACTER_MAXIMUM_LENGTH"].ToString());
                }

                if (columnType == "datetime2" || columnType == "time")
                {
                    actualColumnsDateTimePrecision.Add(row["COLUMN_NAME"].ToString(), row["DATETIME_PRECISION"].ToString());
                }

                if (columnType == "numeric" || columnType == "decimal")
                {
                    PrecisionType p = new PrecisionType
                    {
                        NumericPrecision = row["NUMERIC_PRECISION"].ToString(),
                        NumericScale     = row["NUMERIC_SCALE"].ToString()
                    };
                    actualColumnsNumericPrecision.Add(columnName, p);
                }
            }

            StringBuilder command = new StringBuilder();

            command.Append("CREATE TABLE " + Constants.TempTableName + "(");

            List <string> paramList = new List <string>();

            foreach (var column in columns.ToList())
            {
                if (column == Constants.InternalId)
                {
                    continue;
                }
                string columnType;
                if (actualColumns.TryGetValue(column, out columnType))
                {
                    columnType = GetVariableCharType(column, columnType, actualColumnsMaxCharLength);
                    columnType = GetDecimalPrecisionAndScaleType(column, columnType, actualColumnsNumericPrecision);
                    columnType = GetDateTimePrecisionType(column, columnType, actualColumnsDateTimePrecision);
                }

                paramList.Add("[" + column + "]" + " " + columnType);
            }

            string paramListConcatenated = string.Join(", ", paramList);

            command.Append(paramListConcatenated);

            if (outputIdentity == ColumnDirection.InputOutput)
            {
                command.Append(", [" + Constants.InternalId + "] int");
            }
            command.Append(");");

            return(command.ToString());
        }
コード例 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="columnName"></param>
 /// <param name="outputIdentity"></param>
 protected void SetIdentity(Expression <Func <T, object> > columnName, ColumnDirection outputIdentity)
 {
     _outputIdentity = outputIdentity;
     SetIdentity(columnName);
 }
コード例 #8
0
ファイル: ColumnMapping.cs プロジェクト: matkoch/Nevermore
 IColumnMappingBuilder IColumnMappingBuilder.SaveOnly()
 {
     direction = ColumnDirection.ToDatabase;
     return(this);
 }
コード例 #9
0
ファイル: ColumnMapping.cs プロジェクト: matkoch/Nevermore
 IColumnMappingBuilder IColumnMappingBuilder.LoadOnly()
 {
     direction = ColumnDirection.FromDatabase;
     return(this);
 }