Ejemplo n.º 1
0
        internal void FillColumnInfo()
        {
            // Gather the column information for the statement handle

            int  columnCount;
            bool cannotPrefetch = false;

            // Count the number of columns
            _statementHandle.GetAttribute(OCI.ATTR.OCI_ATTR_PARAM_COUNT, out columnCount, ErrorHandle);
            _columnInfo = new OracleColumn[columnCount];

            // Create column objects for each column, have them get their
            // descriptions and determine their location in a row buffer.
            _rowBufferLength = 0;
            for (int i = 0; i < columnCount; i++)
            {
                _columnInfo[i] = new OracleColumn(_statementHandle, i, ErrorHandle, _connection);
                if (_columnInfo[i].Describe(ref _rowBufferLength, _connection, ErrorHandle))
                {
                    cannotPrefetch = true;
                }
            }

            if (cannotPrefetch || 0 == _rowBufferLength)
            {
                _rowsToPrefetch = 1;
            }
            else
            {
                _rowsToPrefetch = (_prefetchMemory + _rowBufferLength - 1) / _rowBufferLength;  // at least one row...
            }
            Debug.Assert(1 <= _rowsToPrefetch, "bad prefetch rows value!");
        }
Ejemplo n.º 2
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();
            }
        }
        private object ExecuteScalarInternal(bool needCLStype, bool needRowid, out OciRowidDescriptor rowidDescriptor)
        {
            OciStatementHandle statementHandle = null;
            object             oracleValue     = null;
            int rc = 0;

            try
            {
                statementHandle = this.GetStatementHandle();
                ArrayList resultParameterOrdinals = new ArrayList();
                this.Execute(statementHandle, CommandBehavior.Default, needRowid, out rowidDescriptor, out resultParameterOrdinals);
                if (OCI.STMT.OCI_STMT_SELECT != this._statementType)
                {
                    return(oracleValue);
                }
                OracleColumn column       = new OracleColumn(statementHandle, 0, this.ErrorHandle, this._connection);
                int          offset       = 0;
                bool         success      = false;
                bool         mustRelease  = false;
                SafeHandle   handleToBind = null;
                column.Describe(ref offset, this._connection, this.ErrorHandle);
                NativeBuffer_RowBuffer buffer = new NativeBuffer_RowBuffer(offset, 1);
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    buffer.DangerousAddRef(ref success);
                    column.Bind(statementHandle, buffer, this.ErrorHandle, 0);
                    column.Rebind(this._connection, ref mustRelease, ref handleToBind);
                    rc = TracedNativeMethods.OCIStmtFetch(statementHandle, this.ErrorHandle, 1, OCI.FETCH.OCI_FETCH_NEXT, OCI.MODE.OCI_DEFAULT);
                    if (100 != rc)
                    {
                        if (rc != 0)
                        {
                            this.Connection.CheckError(this.ErrorHandle, rc);
                        }
                        if (needCLStype)
                        {
                            oracleValue = column.GetValue(buffer);
                        }
                        else
                        {
                            oracleValue = column.GetOracleValue(buffer);
                        }
                    }
                }
                finally
                {
                    if (mustRelease)
                    {
                        handleToBind.DangerousRelease();
                    }
                    if (success)
                    {
                        buffer.DangerousRelease();
                    }
                }
                GC.KeepAlive(column);
            }
            finally
            {
                if (statementHandle != null)
                {
                    this.ReleaseStatementHandle(statementHandle);
                }
            }
            return(oracleValue);
        }
Ejemplo n.º 4
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;
        }