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!"); }
//////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// // // Constructors // //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// // Construct from a command and a statement handle internal OracleDataReader( OracleCommand command, OciHandle statementHandle, string statementText, CommandBehavior behavior ) { _statementHandle = statementHandle; _connection = (OracleConnection)command.Connection; _connectionCloseCount = _connection.CloseCount; _columnInfo = null; if (OCI.STMT.OCI_STMT_SELECT == command.StatementType) { FillColumnInfo(); _recordsAffected = -1; // Don't know this until we read the last row if (OracleCommand.IsBehavior(behavior, CommandBehavior.SchemaOnly)) { _endOfData = true; } } else { _statementHandle.GetAttribute(OCI.ATTR.OCI_ATTR_ROW_COUNT, out _recordsAffected, ErrorHandle); _endOfData = true; _hasRows = x_hasRows_False; } _statementText = statementText; _closeConnectionToo = (OracleCommand.IsBehavior(behavior, CommandBehavior.CloseConnection)); if (CommandType.Text == command.CommandType) { _keyInfoRequested = (OracleCommand.IsBehavior(behavior, CommandBehavior.KeyInfo)); } }
override protected DBSqlParserColumnCollection GatherTableColumns( DBSqlParserTable table ) { // Called to get a column list for the table specified. OciHandle statementHandle = _connection.EnvironmentHandle.CreateOciHandle(OCI.HTYPE.OCI_HTYPE_STMT); OciHandle errorHandle = _connection.ErrorHandle; StringBuilder sb = new StringBuilder(); string schemaName = table.SchemaName; string tableName = table.TableName; string columnName; int tableColumnCount; int rc; string tempStatement; DBSqlParserColumnCollection columns = new DBSqlParserColumnCollection(); Debug.Assert(string.Empty == table.DatabaseName, "oracle doesn't support 4 part names!"); sb.Append("select * from "); if (String.Empty != schemaName) { sb.Append(schemaName); sb.Append("."); } sb.Append(tableName); tempStatement = sb.ToString(); rc = TracedNativeMethods.OCIStmtPrepare( statementHandle, errorHandle, tempStatement, tempStatement.Length, OCI.SYNTAX.OCI_NTV_SYNTAX, OCI.MODE.OCI_DEFAULT, _connection ); if (0 == rc) { rc = TracedNativeMethods.OCIStmtExecute( _connection.ServiceContextHandle, statementHandle, errorHandle, 0, // iters 0, // rowoff ADP.NullHandleRef, // snap_in ADP.NullHandleRef, // snap_out OCI.MODE.OCI_DESCRIBE_ONLY // mode ); if (0 == rc) { // Build the column list for the table statementHandle.GetAttribute(OCI.ATTR.OCI_ATTR_PARAM_COUNT, out tableColumnCount, errorHandle); for (int j = 0; j < tableColumnCount; j++) { OciHandle describeHandle = statementHandle.GetDescriptor(j, errorHandle); describeHandle.GetAttribute(OCI.ATTR.OCI_ATTR_NAME, out columnName, errorHandle, _connection); OciHandle.SafeDispose(ref describeHandle); columnName = QuotePrefixCharacter + columnName + QuoteSuffixCharacter; columns.Add(null, schemaName, tableName, columnName, null); } // Now, derive the key information for the statement and update the column list // with it. } } // Clean up and return; OciHandle.SafeDispose(ref statementHandle); return(columns); }