Beispiel #1
0
        static internal DbSchemaRow[] GetSortedSchemaRows(DataTable dataTable, bool returnProviderSpecificTypes)   // MDAC 60609
        {
            DataColumn sortindex = dataTable.Columns[SchemaMappingUnsortedIndex];

            if (null == sortindex)                                                     // WebData 100390
            {
                sortindex = new DataColumn(SchemaMappingUnsortedIndex, typeof(Int32)); // MDAC 67050
                dataTable.Columns.Add(sortindex);
            }
            int count = dataTable.Rows.Count;

            for (int i = 0; i < count; ++i)
            {
                dataTable.Rows[i][sortindex] = i;
            }
            ;
            DbSchemaTable schemaTable = new DbSchemaTable(dataTable, returnProviderSpecificTypes);

            const DataViewRowState rowStates = DataViewRowState.Unchanged | DataViewRowState.Added | DataViewRowState.ModifiedCurrent;

            DataRow[] dataRows = dataTable.Select(null, "ColumnOrdinal ASC", rowStates);
            Debug.Assert(null != dataRows, "GetSchemaRows: unexpected null dataRows");

            DbSchemaRow[] schemaRows = new DbSchemaRow[dataRows.Length];

            for (int i = 0; i < dataRows.Length; ++i)
            {
                schemaRows[i] = new DbSchemaRow(schemaTable, dataRows[i]);
            }
            return(schemaRows);
        }
Beispiel #2
0
        internal static DbSchemaRow[] GetSortedSchemaRows(DataTable dataTable, bool returnProviderSpecificTypes)
        {
            DataColumn?sortindex = dataTable.Columns[SchemaMappingUnsortedIndex];

            if (null == sortindex)
            {
                sortindex = new DataColumn(SchemaMappingUnsortedIndex, typeof(int));
                dataTable.Columns.Add(sortindex);
            }
            int count = dataTable.Rows.Count;

            for (int i = 0; i < count; ++i)
            {
                dataTable.Rows[i][sortindex] = i;
            }
            ;
            DbSchemaTable schemaTable = new DbSchemaTable(dataTable, returnProviderSpecificTypes);


            DataRow[] dataRows = SelectRows(dataTable, returnProviderSpecificTypes);
            Debug.Assert(null != dataRows, "GetSchemaRows: unexpected null dataRows");

            DbSchemaRow[] schemaRows = new DbSchemaRow[dataRows.Length];

            for (int i = 0; i < dataRows.Length; ++i)
            {
                schemaRows[i] = new DbSchemaRow(schemaTable, dataRows[i]);
            }
            return(schemaRows);
        }
        internal static DbSchemaRow[] GetSortedSchemaRows(DataTable dataTable, bool returnProviderSpecificTypes)
        {
            DataColumn column = dataTable.Columns["SchemaMapping Unsorted Index"];

            if (column == null)
            {
                column = new DataColumn("SchemaMapping Unsorted Index", typeof(int));
                dataTable.Columns.Add(column);
            }
            int count = dataTable.Rows.Count;

            for (int i = 0; i < count; i++)
            {
                dataTable.Rows[i][column] = i;
            }
            DbSchemaTable schemaTable = new DbSchemaTable(dataTable, returnProviderSpecificTypes);

            System.Data.DataRow[] rowArray  = dataTable.Select(null, "ColumnOrdinal ASC", DataViewRowState.CurrentRows);
            DbSchemaRow[]         rowArray2 = new DbSchemaRow[rowArray.Length];
            for (int j = 0; j < rowArray.Length; j++)
            {
                rowArray2[j] = new DbSchemaRow(schemaTable, rowArray[j]);
            }
            return(rowArray2);
        }
Beispiel #4
0
        internal static DbSchemaRow[] GetSortedSchemaRows(DataTable dataTable, bool returnProviderSpecificTypes)
        {
            DataColumn sortindex = dataTable.Columns[SchemaMappingUnsortedIndex];
            if (null == sortindex)
            {
                sortindex = new DataColumn(SchemaMappingUnsortedIndex, typeof(int));
                dataTable.Columns.Add(sortindex);
            }
            int count = dataTable.Rows.Count;
            for (int i = 0; i < count; ++i)
            {
                dataTable.Rows[i][sortindex] = i;
            };
            DbSchemaTable schemaTable = new DbSchemaTable(dataTable, returnProviderSpecificTypes);

            const DataViewRowState rowStates = DataViewRowState.Unchanged | DataViewRowState.Added | DataViewRowState.ModifiedCurrent;
            DataRow[] dataRows = dataTable.Select(null, "ColumnOrdinal ASC", rowStates);
            Debug.Assert(null != dataRows, "GetSchemaRows: unexpected null dataRows");

            DbSchemaRow[] schemaRows = new DbSchemaRow[dataRows.Length];

            for (int i = 0; i < dataRows.Length; ++i)
            {
                schemaRows[i] = new DbSchemaRow(schemaTable, dataRows[i]);
            }
            return schemaRows;
        }
 internal static DbSchemaRow[] GetSortedSchemaRows(DataTable dataTable, bool returnProviderSpecificTypes)
 {
     DataColumn column = dataTable.Columns["SchemaMapping Unsorted Index"];
     if (column == null)
     {
         column = new DataColumn("SchemaMapping Unsorted Index", typeof(int));
         dataTable.Columns.Add(column);
     }
     int count = dataTable.Rows.Count;
     for (int i = 0; i < count; i++)
     {
         dataTable.Rows[i][column] = i;
     }
     DbSchemaTable schemaTable = new DbSchemaTable(dataTable, returnProviderSpecificTypes);
     System.Data.DataRow[] rowArray = dataTable.Select(null, "ColumnOrdinal ASC", DataViewRowState.CurrentRows);
     DbSchemaRow[] rowArray2 = new DbSchemaRow[rowArray.Length];
     for (int j = 0; j < rowArray.Length; j++)
     {
         rowArray2[j] = new DbSchemaRow(schemaTable, rowArray[j]);
     }
     return rowArray2;
 }
        private string CreateParameterForValue(
            DbCommand       command,
            string          parameterName,
            string          sourceColumn,
            DataRowVersion  version,
            int             parameterCount,
            object          value,
            DbSchemaRow     row,
            StatementType   statementType,
            bool            whereClause
            ) {
            DbParameter p = GetNextParameter(command, parameterCount);

            if (null == parameterName) {
                p.ParameterName = GetParameterName(1 + parameterCount);
            }
            else {
                p.ParameterName = parameterName;
            }
            p.Direction     = ParameterDirection.Input;
            p.SourceColumn  = sourceColumn;
            p.SourceVersion = version;
            p.SourceColumnNullMapping = false;
            p.Value         = value;
            p.Size          = 0; // don't specify parameter.Size so that we don't silently truncate to the metadata size

            ApplyParameterInfo(p, row.DataRow, statementType, whereClause);

            if (!command.Parameters.Contains(p)) {
                command.Parameters.Add(p);
            }

            if (null == parameterName) {
                return GetParameterPlaceholder(1 + parameterCount);
            }
            else {
                Debug.Assert(null != _parameterNames, "How can we have a parameterName without a _parameterNames collection?");
                Debug.Assert(null != _parameterMarkerFormat, "How can we have a _parameterNames collection but no _parameterMarkerFormat?");

                return String.Format(CultureInfo.InvariantCulture, _parameterMarkerFormat, parameterName);
            }
        }
            internal ParameterNames(DbCommandBuilder dbCommandBuilder, DbSchemaRow[] schemaRows) {
                _dbCommandBuilder = dbCommandBuilder;
                _baseParameterNames = new string[schemaRows.Length];
                _originalParameterNames = new string[schemaRows.Length];
                _nullParameterNames = new string[schemaRows.Length];
                _isMutatedName = new bool[schemaRows.Length];
                _count = schemaRows.Length;
                _parameterNameParser = new Regex(_dbCommandBuilder.ParameterNamePattern, RegexOptions.ExplicitCapture | RegexOptions.Singleline);

                SetAndValidateNamePrefixes();
                _adjustedParameterNameMaxLength = GetAdjustedParameterNameMaxLength();

                // Generate the baseparameter names and remove conflicting names
                // No names will be generated for any name that is rejected due to invalid prefix, regex violation or
                // name conflict after mutation.
                // All null values will be replaced with generic parameter names
                //
                for (int i = 0; i < schemaRows.Length; i++) {
                    if (null == schemaRows[i]) {
                        continue;
                    }
                    bool isMutatedName = false;
                    string columnName = schemaRows[i].ColumnName;

                    // all names that start with original- or isNullPrefix are invalid
                    if (null != _originalPrefix) {
                        if (columnName.StartsWith(_originalPrefix, StringComparison.OrdinalIgnoreCase)) {
                            continue;
                        }
                    }
                    if (null != _isNullPrefix) {
                        if (columnName.StartsWith(_isNullPrefix, StringComparison.OrdinalIgnoreCase)) {
                            continue;
                        }
                    }

                    // Mutate name if it contains space(s)
                    if (columnName.IndexOf(' ') >= 0) {
                        columnName = columnName.Replace(' ', '_');
                        isMutatedName = true;
                    }

                    // Validate name against regular expression
                    if (!_parameterNameParser.IsMatch(columnName)) {
                        continue;
                    }

                    // Validate name against adjusted max parametername length
                    if (columnName.Length > _adjustedParameterNameMaxLength) {
                        continue;
                    }

                    _baseParameterNames[i] = columnName;
                    _isMutatedName[i] = isMutatedName;
                }

                EliminateConflictingNames();

                // Generate names for original- and isNullparameters
                // no names will be generated if the prefix failed parametername validation
                for (int i = 0; i < schemaRows.Length; i++) {
                    if (null != _baseParameterNames[i]) {
                        if (null != _originalPrefix) {
                            _originalParameterNames[i] = _originalPrefix + _baseParameterNames[i];
                        }
                        if (null != _isNullPrefix) {
                            // don't bother generating an 'IsNull' name if it's not used
                            if (schemaRows[i].AllowDBNull) {
                                _nullParameterNames[i] = _isNullPrefix + _baseParameterNames[i];
                            }
                        }
                    }
                }
                ApplyProviderSpecificFormat();
                GenerateMissingNames(schemaRows);
            }
 // Generates parameternames that couldn't be generated from columnname
 internal void GenerateMissingNames(DbSchemaRow[] schemaRows) {
     // foreach name in base names
     // if base name is null
     //  for base, original and nullnames (null names only if nullable)
     //   do
     //    generate name based on current index
     //    increment index
     //    search name in base names
     //   loop while name occures in base names
     //  end for
     // end foreach
     string name;
     for (int i = 0; i < _baseParameterNames.Length; i++) {
         name = _baseParameterNames[i];
         if (null == name) {
             _baseParameterNames[i] = GetNextGenericParameterName();
             _originalParameterNames[i] = GetNextGenericParameterName();
             // don't bother generating an 'IsNull' name if it's not used
             if ((null != schemaRows[i]) && schemaRows[i].AllowDBNull) {
                 _nullParameterNames[i] = GetNextGenericParameterName();
             }
         }
     }
 }
 private bool IncrementWhereCount(DbSchemaRow row) {
     ConflictOption value = ConflictOption;
     switch(value) {
     case ConflictOption.CompareAllSearchableValues:
     case ConflictOption.OverwriteChanges:
         // find the primary key
         return (row.IsKey || row.IsUnique) && !row.IsLong && !row.IsRowVersion;
     case ConflictOption.CompareRowVersion:
         // or the row version
         return (((row.IsKey || row.IsUnique) && !_hasPartialPrimaryKey) || row.IsRowVersion) && !row.IsLong;
     default:
         throw ADP.InvalidConflictOptions(value);                    
     }
 }
Beispiel #10
0
 private bool IncludeInWhereClause(DbSchemaRow row, bool isUpdate) {
     bool flag = IncrementWhereCount(row);
     if (flag && row.IsHidden) { // MDAC 52564
         if (ConflictOption.CompareRowVersion == ConflictOption) {
             throw ADP.DynamicSQLNoKeyInfoRowVersionUpdate();
         }
         throw ADP.DynamicSQLNoKeyInfoUpdate();
     }
     if (!flag && (ConflictOption.CompareAllSearchableValues == ConflictOption)) {
         // include other searchable values
         flag = !row.IsLong && !row.IsRowVersion && !row.IsHidden;
     }
     return flag;
 }
Beispiel #11
0
        private bool IncludeInUpdateSet(DbSchemaRow row) {
            // 

            return (!row.IsAutoIncrement && !row.IsRowVersion && !row.IsHidden && !row.IsReadOnly);
        }
Beispiel #12
0
        private bool IncludeInInsertValues(DbSchemaRow row) {
            // 

            return (!row.IsAutoIncrement && !row.IsHidden && !row.IsExpression && !row.IsRowVersion && !row.IsReadOnly);
        }
        private bool IncrementWhereCount(DbSchemaRow row)
        {
            System.Data.ConflictOption conflictOption = this.ConflictOption;
            switch (conflictOption)
            {
                case System.Data.ConflictOption.CompareAllSearchableValues:
                case System.Data.ConflictOption.OverwriteChanges:
                    return (((row.IsKey || row.IsUnique) && !row.IsLong) && !row.IsRowVersion);

                case System.Data.ConflictOption.CompareRowVersion:
                    if (((!row.IsKey && !row.IsUnique) || this._hasPartialPrimaryKey) && !row.IsRowVersion)
                    {
                        return false;
                    }
                    return !row.IsLong;
            }
            throw ADP.InvalidConflictOptions(conflictOption);
        }
 private bool IncludeInWhereClause(DbSchemaRow row, bool isUpdate)
 {
     bool flag = this.IncrementWhereCount(row);
     if (flag && row.IsHidden)
     {
         if (System.Data.ConflictOption.CompareRowVersion == this.ConflictOption)
         {
             throw ADP.DynamicSQLNoKeyInfoRowVersionUpdate();
         }
         throw ADP.DynamicSQLNoKeyInfoUpdate();
     }
     if (!flag && (System.Data.ConflictOption.CompareAllSearchableValues == this.ConflictOption))
     {
         flag = (!row.IsLong && !row.IsRowVersion) && !row.IsHidden;
     }
     return flag;
 }
 private string CreateParameterForValue(DbCommand command, string parameterName, string sourceColumn, DataRowVersion version, int parameterCount, object value, DbSchemaRow row, StatementType statementType, bool whereClause)
 {
     DbParameter nextParameter = GetNextParameter(command, parameterCount);
     if (parameterName == null)
     {
         nextParameter.ParameterName = this.GetParameterName((int) (1 + parameterCount));
     }
     else
     {
         nextParameter.ParameterName = parameterName;
     }
     nextParameter.Direction = ParameterDirection.Input;
     nextParameter.SourceColumn = sourceColumn;
     nextParameter.SourceVersion = version;
     nextParameter.SourceColumnNullMapping = false;
     nextParameter.Value = value;
     nextParameter.Size = 0;
     this.ApplyParameterInfo(nextParameter, row.DataRow, statementType, whereClause);
     if (!command.Parameters.Contains(nextParameter))
     {
         command.Parameters.Add(nextParameter);
     }
     if (parameterName == null)
     {
         return this.GetParameterPlaceholder(1 + parameterCount);
     }
     return string.Format(CultureInfo.InvariantCulture, this._parameterMarkerFormat, new object[] { parameterName });
 }
 internal void GenerateMissingNames(DbSchemaRow[] schemaRows)
 {
     for (int i = 0; i < this._baseParameterNames.Length; i++)
     {
         if (this._baseParameterNames[i] == null)
         {
             this._baseParameterNames[i] = this.GetNextGenericParameterName();
             this._originalParameterNames[i] = this.GetNextGenericParameterName();
             if ((schemaRows[i] != null) && schemaRows[i].AllowDBNull)
             {
                 this._nullParameterNames[i] = this.GetNextGenericParameterName();
             }
         }
     }
 }
 internal ParameterNames(DbCommandBuilder dbCommandBuilder, DbSchemaRow[] schemaRows)
 {
     this._dbCommandBuilder = dbCommandBuilder;
     this._baseParameterNames = new string[schemaRows.Length];
     this._originalParameterNames = new string[schemaRows.Length];
     this._nullParameterNames = new string[schemaRows.Length];
     this._isMutatedName = new bool[schemaRows.Length];
     this._count = schemaRows.Length;
     this._parameterNameParser = new Regex(this._dbCommandBuilder.ParameterNamePattern, RegexOptions.Singleline | RegexOptions.ExplicitCapture);
     this.SetAndValidateNamePrefixes();
     this._adjustedParameterNameMaxLength = this.GetAdjustedParameterNameMaxLength();
     for (int i = 0; i < schemaRows.Length; i++)
     {
         if (schemaRows[i] != null)
         {
             bool flag = false;
             string columnName = schemaRows[i].ColumnName;
             if (((this._originalPrefix == null) || !columnName.StartsWith(this._originalPrefix, StringComparison.OrdinalIgnoreCase)) && ((this._isNullPrefix == null) || !columnName.StartsWith(this._isNullPrefix, StringComparison.OrdinalIgnoreCase)))
             {
                 if (columnName.IndexOf(' ') >= 0)
                 {
                     columnName = columnName.Replace(' ', '_');
                     flag = true;
                 }
                 if (this._parameterNameParser.IsMatch(columnName) && (columnName.Length <= this._adjustedParameterNameMaxLength))
                 {
                     this._baseParameterNames[i] = columnName;
                     this._isMutatedName[i] = flag;
                 }
             }
         }
     }
     this.EliminateConflictingNames();
     for (int j = 0; j < schemaRows.Length; j++)
     {
         if (this._baseParameterNames[j] != null)
         {
             if (this._originalPrefix != null)
             {
                 this._originalParameterNames[j] = this._originalPrefix + this._baseParameterNames[j];
             }
             if ((this._isNullPrefix != null) && schemaRows[j].AllowDBNull)
             {
                 this._nullParameterNames[j] = this._isNullPrefix + this._baseParameterNames[j];
             }
         }
     }
     this.ApplyProviderSpecificFormat();
     this.GenerateMissingNames(schemaRows);
 }
Beispiel #18
0
 private bool IncludeInUpdateSet(DbSchemaRow row)
 {
     // NOTE: Include ignore condition - i.e. ignore if 'row' is IsReadOnly else include
     return (!row.IsAutoIncrement && !row.IsRowVersion && !row.IsHidden && !row.IsReadOnly);
 }