Beispiel #1
0
        private void FillSchemaTable(DataTable schemaTable)
        {
            DataColumn column3 = new DataColumn(SchemaTableOptionalColumn.ProviderSpecificDataType, typeof(Type));

            schemaTable.Columns.Add(column3);
            int fieldCount = this.FieldCount;
            DbSqlParserColumnCollection columns = null;
            int count = 0;

            if (this._keyInfoRequested)
            {
                OracleSqlParser parser = new OracleSqlParser();
                parser.Parse(this._statementText, this._connection);
                columns = parser.Columns;
                count   = columns.Count;
            }
            for (int i = 0; i < fieldCount; i++)
            {
                OracleColumn column = this._columnInfo[i];
                DataRow      row    = schemaTable.NewRow();
                row[SchemaTableColumn.ColumnName]    = column.ColumnName;
                row[SchemaTableColumn.ColumnOrdinal] = column.Ordinal;
                if (column.IsLong | column.IsLob)
                {
                    row[SchemaTableColumn.ColumnSize] = 0x7fffffff;
                }
                else
                {
                    row[SchemaTableColumn.ColumnSize] = column.SchemaTableSize;
                }
                row[SchemaTableColumn.NumericPrecision] = column.Precision;
                row[SchemaTableColumn.NumericScale]     = column.Scale;
                row[SchemaTableColumn.DataType]         = column.GetFieldType();
                row[column3] = column.GetFieldOracleType();
                row[SchemaTableColumn.ProviderType] = column.OracleType;
                row[SchemaTableColumn.IsLong]       = column.IsLong | column.IsLob;
                row[SchemaTableColumn.AllowDBNull]  = column.IsNullable;
                if (this._keyInfoRequested && (count == fieldCount))
                {
                    DbSqlParserColumn column2 = columns[i];
                    row[SchemaTableColumn.IsAliased]      = column2.IsAliased;
                    row[SchemaTableColumn.IsExpression]   = column2.IsExpression;
                    row[SchemaTableColumn.IsKey]          = column2.IsKey;
                    row[SchemaTableColumn.IsUnique]       = column2.IsUnique;
                    row[SchemaTableColumn.BaseSchemaName] = this.SetSchemaValue(OracleSqlParser.CatalogCase(column2.SchemaName));
                    row[SchemaTableColumn.BaseTableName]  = this.SetSchemaValue(OracleSqlParser.CatalogCase(column2.TableName));
                    row[SchemaTableColumn.BaseColumnName] = this.SetSchemaValue(OracleSqlParser.CatalogCase(column2.ColumnName));
                }
                else
                {
                    row[SchemaTableColumn.IsAliased]      = DBNull.Value;
                    row[SchemaTableColumn.IsExpression]   = DBNull.Value;
                    row[SchemaTableColumn.IsKey]          = DBNull.Value;
                    row[SchemaTableColumn.IsUnique]       = DBNull.Value;
                    row[SchemaTableColumn.BaseSchemaName] = DBNull.Value;
                    row[SchemaTableColumn.BaseTableName]  = DBNull.Value;
                    row[SchemaTableColumn.BaseColumnName] = DBNull.Value;
                }
                schemaTable.Rows.Add(row);
                row.AcceptChanges();
            }
        }
Beispiel #2
0
        private void BuildSchemaTable()
        {
            Debug.Assert(null == _schemaTable, "BuildSchemaTable: schema table already exists");
            Debug.Assert(null != _columnInfo, "BuildSchemaTable: no columnInfo");

            int                         columnCount = FieldCount;
            OracleSqlParser             parser;
            DBSqlParserColumnCollection parsedColumns      = null;
            int                         parsedColumnsCount = 0;

            if (_keyInfoRequested)
            {
                parser = new OracleSqlParser();
                parser.Parse(_statementText, _connection);

                parsedColumns      = parser.Columns;
                parsedColumnsCount = parsedColumns.Count;
            }


            DataTable schemaTable = new DataTable("SchemaTable");

            schemaTable.MinimumCapacity = columnCount;

            DataColumn name      = new DataColumn("ColumnName", typeof(System.String));
            DataColumn ordinal   = new DataColumn("ColumnOrdinal", typeof(System.Int32));
            DataColumn size      = new DataColumn("ColumnSize", typeof(System.Int32));
            DataColumn precision = new DataColumn("NumericPrecision", typeof(System.Int16));
            DataColumn scale     = new DataColumn("NumericScale", typeof(System.Int16));

            DataColumn dataType   = new DataColumn("DataType", typeof(System.Type));
            DataColumn oracleType = new DataColumn("ProviderType", typeof(System.Int32));

            DataColumn isLong       = new DataColumn("IsLong", typeof(System.Boolean));
            DataColumn isNullable   = new DataColumn("AllowDBNull", typeof(System.Boolean));
            DataColumn isAliased    = new DataColumn("IsAliased", typeof(System.Boolean));
            DataColumn isExpression = new DataColumn("IsExpression", typeof(System.Boolean));
            DataColumn isKey        = new DataColumn("IsKey", typeof(System.Boolean));
            DataColumn isUnique     = new DataColumn("IsUnique", typeof(System.Boolean));

            DataColumn baseSchemaName = new DataColumn("BaseSchemaName", typeof(System.String));
            DataColumn baseTableName  = new DataColumn("BaseTableName", typeof(System.String));
            DataColumn baseColumnName = new DataColumn("BaseColumnName", typeof(System.String));


            ordinal.DefaultValue = 0;
            isLong.DefaultValue  = false;

            DataColumnCollection columns = schemaTable.Columns;

            columns.Add(name);
            columns.Add(ordinal);
            columns.Add(size);
            columns.Add(precision);
            columns.Add(scale);

            columns.Add(dataType);
            columns.Add(oracleType);

            columns.Add(isLong);
            columns.Add(isNullable);
            columns.Add(isAliased);
            columns.Add(isExpression);
            columns.Add(isKey);
            columns.Add(isUnique);

            columns.Add(baseSchemaName);
            columns.Add(baseTableName);
            columns.Add(baseColumnName);

            for (int i = 0; i < columnCount; ++i)
            {
                OracleColumn column = _columnInfo[i];

                DataRow newRow = schemaTable.NewRow();

                newRow[name]    = column.ColumnName;
                newRow[ordinal] = column.Ordinal;

                if (column.IsLong | column.IsLob)
                {
                    newRow[size] = Int32.MaxValue;          //MDAC 82554
                }
                else
                {
                    newRow[size] = column.Size;
                }

                newRow[precision] = column.Precision;
                newRow[scale]     = column.Scale;

                newRow[dataType]   = column.GetFieldType();
                newRow[oracleType] = column.OracleType;

                newRow[isLong]     = column.IsLong | column.IsLob;
                newRow[isNullable] = column.IsNullable;

                if (_keyInfoRequested && parsedColumnsCount == columnCount)
                {
                    DBSqlParserColumn parsedColumn = parsedColumns[i];

                    newRow[isAliased]      = parsedColumn.IsAliased;
                    newRow[isExpression]   = parsedColumn.IsExpression;
                    newRow[isKey]          = parsedColumn.IsKey;
                    newRow[isUnique]       = parsedColumn.IsUnique;
                    newRow[baseSchemaName] = SetSchemaValue(OracleSqlParser.CatalogCase(parsedColumn.SchemaName));
                    newRow[baseTableName]  = SetSchemaValue(OracleSqlParser.CatalogCase(parsedColumn.TableName));
                    newRow[baseColumnName] = SetSchemaValue(OracleSqlParser.CatalogCase(parsedColumn.ColumnName));
                }
                else
                {
                    newRow[isAliased]      = DBNull.Value;      // don't know
                    newRow[isExpression]   = DBNull.Value;      // don't know
                    newRow[isKey]          = DBNull.Value;      // don't know
                    newRow[isUnique]       = DBNull.Value;      // don't know
                    newRow[baseSchemaName] = DBNull.Value;      // don't know
                    newRow[baseTableName]  = DBNull.Value;      // don't know
                    newRow[baseColumnName] = DBNull.Value;      // don't know
                }

                schemaTable.Rows.Add(newRow);
                newRow.AcceptChanges();
            }

            // mark all columns as readonly
            for (int i = 0; i < columns.Count; i++)
            {
                columns[i].ReadOnly = true;
            }

//          DataSet dataset = new DataSet();
//          dataset.Tables.Add(schemaTable);
//          Debug.WriteLine(dataset.GetXml());
//          dataset.Tables.Remove(schemaTable);
            _schemaTable = schemaTable;
        }