private DataTable GetDataTypesCollection(string[] restrictions, OdbcConnection connection) { if (!ADP.IsEmptyArray(restrictions)) { throw ADP.TooManyRestrictions(DbMetaDataCollectionNames.DataTypes); } if (base.CollectionDataSet.Tables[DbMetaDataCollectionNames.DataTypes] == null) { throw ADP.UnableToBuildCollection(DbMetaDataCollectionNames.DataTypes); } DataTable dataTypesTable = base.CloneAndFilterCollection(DbMetaDataCollectionNames.DataTypes, null); OdbcCommand command = null; OdbcDataReader dataReader = null; object[] methodArguments = new object[] { (short)0 }; try { command = this.GetCommand(connection); dataReader = command.ExecuteReaderFromSQLMethod(methodArguments, ODBC32.SQL_API.SQLGETTYPEINFO); this.DataTableFromDataReaderDataTypes(dataTypesTable, dataReader, connection); } finally { if (dataReader != null) { dataReader.Dispose(); } if (command != null) { command.Dispose(); } } dataTypesTable.AcceptChanges(); return(dataTypesTable); }
private static DataTable GetColumnsCollection(string?[]?restrictions, OdbcConnection connection) { OdbcCommand? command = null; OdbcDataReader?dataReader = null; DataTable? resultTable = null; const int columnsRestrictionsCount = 4; try { command = GetCommand(connection); string[] allRestrictions = new string[columnsRestrictionsCount]; FillOutRestrictions(columnsRestrictionsCount, restrictions, allRestrictions, OdbcMetaDataCollectionNames.Columns); dataReader = command.ExecuteReaderFromSQLMethod(allRestrictions, ODBC32.SQL_API.SQLCOLUMNS); resultTable = DataTableFromDataReader(dataReader, OdbcMetaDataCollectionNames.Columns); } finally { dataReader?.Dispose();; command?.Dispose();; } return(resultTable); }
private DataTable GetColumnsCollection(string[] restrictions, OdbcConnection connection) { OdbcDataReader reader = null; OdbcCommand command = null; DataTable table = null; try { command = this.GetCommand(connection); string[] allRestrictions = new string[4]; this.FillOutRestrictions(4, restrictions, allRestrictions, OdbcMetaDataCollectionNames.Columns); reader = command.ExecuteReaderFromSQLMethod(allRestrictions, ODBC32.SQL_API.SQLCOLUMNS); table = this.DataTableFromDataReader(reader, OdbcMetaDataCollectionNames.Columns); } finally { if (reader != null) { reader.Dispose(); } if (command != null) { command.Dispose(); } } return(table); }
private DataTable GetProceduresCollection(string[] restrictions, OdbcConnection connection) { OdbcDataReader reader = null; OdbcCommand command = null; DataTable table = null; try { short num; command = this.GetCommand(connection); string[] allRestrictions = new string[4]; this.FillOutRestrictions(4, restrictions, allRestrictions, OdbcMetaDataCollectionNames.Procedures); reader = command.ExecuteReaderFromSQLMethod(allRestrictions, ODBC32.SQL_API.SQLPROCEDURES); if (allRestrictions[3] == null) { return(this.DataTableFromDataReader(reader, OdbcMetaDataCollectionNames.Procedures)); } if ((restrictions[3] == "SQL_PT_UNKNOWN") || (restrictions[3] == "0")) { num = 0; } else if ((restrictions[3] == "SQL_PT_PROCEDURE") || (restrictions[3] == "1")) { num = 1; } else { if (!(restrictions[3] == "SQL_PT_FUNCTION") && !(restrictions[3] == "2")) { throw ADP.InvalidRestrictionValue(OdbcMetaDataCollectionNames.Procedures, "PROCEDURE_TYPE", restrictions[3]); } num = 2; } table = this.DataTableFromDataReaderProcedures(reader, OdbcMetaDataCollectionNames.Procedures, num); } finally { if (reader != null) { reader.Dispose(); } if (command != null) { command.Dispose(); } } return(table); }
private static DataTable GetIndexCollection(string?[]?restrictions, OdbcConnection connection) { OdbcCommand? command = null; OdbcDataReader?dataReader = null; DataTable? resultTable = null; const int nativeRestrictionsCount = 5; const int indexRestrictionsCount = 4; const int indexOfTableName = 2; const int indexOfIndexName = 3; try { command = GetCommand(connection); object[] allRestrictions = new object[nativeRestrictionsCount]; FillOutRestrictions(indexRestrictionsCount, restrictions, allRestrictions, OdbcMetaDataCollectionNames.Indexes); if (allRestrictions[indexOfTableName] == null) { throw ODBC.GetSchemaRestrictionRequired(); } allRestrictions[3] = (short)ODBC32.SQL_INDEX.ALL; allRestrictions[4] = (short)ODBC32.SQL_STATISTICS_RESERVED.ENSURE; dataReader = command.ExecuteReaderFromSQLMethod(allRestrictions, ODBC32.SQL_API.SQLSTATISTICS); string?indexName = null; if (restrictions != null) { if (restrictions.Length >= indexOfIndexName + 1) { indexName = restrictions[indexOfIndexName]; } } resultTable = DataTableFromDataReaderIndex(dataReader, OdbcMetaDataCollectionNames.Indexes, indexName); } finally { dataReader?.Dispose();; command?.Dispose();; } return(resultTable); }
private DataTable GetDataTypesCollection(string?[]?restrictions, OdbcConnection connection) { if (ADP.IsEmptyArray(restrictions) == false) { throw ADP.TooManyRestrictions(DbMetaDataCollectionNames.DataTypes); } // verify the existence of the table in the data set DataTable?dataTypesTable = CollectionDataSet.Tables[DbMetaDataCollectionNames.DataTypes]; if (dataTypesTable == null) { throw ADP.UnableToBuildCollection(DbMetaDataCollectionNames.DataTypes); } // copy the data table it dataTypesTable = CloneAndFilterCollection(DbMetaDataCollectionNames.DataTypes, null); OdbcCommand? command = null; OdbcDataReader?dataReader = null; object[] allArguments = new object[1]; allArguments[0] = ODBC32.SQL_ALL_TYPES; try { command = GetCommand(connection); dataReader = command.ExecuteReaderFromSQLMethod(allArguments, ODBC32.SQL_API.SQLGETTYPEINFO); DataTableFromDataReaderDataTypes(dataTypesTable, dataReader, connection); } finally { dataReader?.Dispose();; command?.Dispose();; } dataTypesTable.AcceptChanges(); return(dataTypesTable); }
private DataTable GetTablesCollection(string[] restrictions, OdbcConnection connection, bool isTables) { OdbcDataReader reader = null; OdbcCommand command = null; DataTable table = null; try { string tables; string str2; command = this.GetCommand(connection); string[] allRestrictions = new string[4]; if (isTables) { str2 = "TABLE,SYSTEM TABLE"; tables = OdbcMetaDataCollectionNames.Tables; } else { str2 = "VIEW"; tables = OdbcMetaDataCollectionNames.Views; } this.FillOutRestrictions(3, restrictions, allRestrictions, tables); allRestrictions[3] = str2; reader = command.ExecuteReaderFromSQLMethod(allRestrictions, ODBC32.SQL_API.SQLTABLES); table = this.DataTableFromDataReader(reader, tables); } finally { if (reader != null) { reader.Dispose(); } if (command != null) { command.Dispose(); } } return(table); }
private DataTable GetIndexCollection(string[] restrictions, OdbcConnection connection) { OdbcDataReader reader = null; OdbcCommand command = null; DataTable table = null; try { command = this.GetCommand(connection); object[] allRestrictions = new object[5]; this.FillOutRestrictions(4, restrictions, allRestrictions, OdbcMetaDataCollectionNames.Indexes); if (allRestrictions[2] == null) { throw ODBC.GetSchemaRestrictionRequired(); } allRestrictions[3] = (short)1; allRestrictions[4] = (short)1; reader = command.ExecuteReaderFromSQLMethod(allRestrictions, ODBC32.SQL_API.SQLSTATISTICS); string restrictionIndexName = null; if ((restrictions != null) && (restrictions.Length >= 4)) { restrictionIndexName = restrictions[3]; } table = this.DataTableFromDataReaderIndex(reader, OdbcMetaDataCollectionNames.Indexes, restrictionIndexName); } finally { if (reader != null) { reader.Dispose(); } if (command != null) { command.Dispose(); } } return(table); }
private static DataTable GetProcedureColumnsCollection(string?[]?restrictions, OdbcConnection connection, bool isColumns) { OdbcCommand? command = null; OdbcDataReader?dataReader = null; DataTable? resultTable = null; const int procedureColumnsRestrictionsCount = 4; try { command = GetCommand(connection); string[] allRestrictions = new string[procedureColumnsRestrictionsCount]; FillOutRestrictions(procedureColumnsRestrictionsCount, restrictions, allRestrictions, OdbcMetaDataCollectionNames.Columns); dataReader = command.ExecuteReaderFromSQLMethod(allRestrictions, ODBC32.SQL_API.SQLPROCEDURECOLUMNS); string collectionName; if (isColumns) { collectionName = OdbcMetaDataCollectionNames.ProcedureColumns; } else { collectionName = OdbcMetaDataCollectionNames.ProcedureParameters; } resultTable = DataTableFromDataReaderProcedureColumns(dataReader, collectionName, isColumns); } finally { dataReader?.Dispose();; command?.Dispose();; } return(resultTable); }
private DataTable GetProcedureColumnsCollection(string[] restrictions, OdbcConnection connection, bool isColumns) { OdbcDataReader reader = null; OdbcCommand command = null; DataTable table = null; try { string procedureColumns; command = this.GetCommand(connection); string[] allRestrictions = new string[4]; this.FillOutRestrictions(4, restrictions, allRestrictions, OdbcMetaDataCollectionNames.Columns); reader = command.ExecuteReaderFromSQLMethod(allRestrictions, ODBC32.SQL_API.SQLPROCEDURECOLUMNS); if (isColumns) { procedureColumns = OdbcMetaDataCollectionNames.ProcedureColumns; } else { procedureColumns = OdbcMetaDataCollectionNames.ProcedureParameters; } table = this.DataTableFromDataReaderProcedureColumns(reader, procedureColumns, isColumns); } finally { if (reader != null) { reader.Dispose(); } if (command != null) { command.Dispose(); } } return(table); }
private OdbcDataReader ExecuteReaderObject(CommandBehavior behavior, string method, bool needReader, object[] methodArguments, ODBC32.SQL_API odbcApiMethod) { OdbcDataReader target = null; try { ODBC32.RetCode typeInfo; this.DisposeDeadDataReader(); this.ValidateConnectionAndTransaction(method); if ((CommandBehavior.SingleRow & behavior) != CommandBehavior.Default) { behavior |= CommandBehavior.SingleResult; } OdbcStatementHandle statementHandle = this.GetStatementHandle().StatementHandle; this._cmdWrapper.Canceling = false; if ((this.weakDataReaderReference != null) && this.weakDataReaderReference.IsAlive) { object obj2 = this.weakDataReaderReference.Target; if (((obj2 != null) && this.weakDataReaderReference.IsAlive) && !((OdbcDataReader)obj2).IsClosed) { throw ADP.OpenReaderExists(); } } target = new OdbcDataReader(this, this._cmdWrapper, behavior); if (!this.Connection.ProviderInfo.NoQueryTimeout) { this.TrySetStatementAttribute(statementHandle, ODBC32.SQL_ATTR.QUERY_TIMEOUT, (IntPtr)this.CommandTimeout); } if ((needReader && this.Connection.IsV3Driver) && (!this.Connection.ProviderInfo.NoSqlSoptSSNoBrowseTable && !this.Connection.ProviderInfo.NoSqlSoptSSHiddenColumns)) { if (target.IsBehavior(CommandBehavior.KeyInfo)) { if (!this._cmdWrapper._ssKeyInfoModeOn) { this.TrySetStatementAttribute(statementHandle, (ODBC32.SQL_ATTR) 0x4cc, (IntPtr)1L); this.TrySetStatementAttribute(statementHandle, ODBC32.SQL_ATTR.SQL_COPT_SS_TXN_ISOLATION, (IntPtr)1L); this._cmdWrapper._ssKeyInfoModeOff = false; this._cmdWrapper._ssKeyInfoModeOn = true; } } else if (!this._cmdWrapper._ssKeyInfoModeOff) { this.TrySetStatementAttribute(statementHandle, (ODBC32.SQL_ATTR) 0x4cc, (IntPtr)0L); this.TrySetStatementAttribute(statementHandle, ODBC32.SQL_ATTR.SQL_COPT_SS_TXN_ISOLATION, (IntPtr)0L); this._cmdWrapper._ssKeyInfoModeOff = true; this._cmdWrapper._ssKeyInfoModeOn = false; } } if (target.IsBehavior(CommandBehavior.KeyInfo) || target.IsBehavior(CommandBehavior.SchemaOnly)) { typeInfo = statementHandle.Prepare(this.CommandText); if (typeInfo != ODBC32.RetCode.SUCCESS) { this._connection.HandleError(statementHandle, typeInfo); } } bool success = false; CNativeBuffer parameterBuffer = this._cmdWrapper._nativeParameterBuffer; RuntimeHelpers.PrepareConstrainedRegions(); try { if ((this._parameterCollection != null) && (0 < this._parameterCollection.Count)) { int initialSize = this._parameterCollection.CalcParameterBufferSize(this); if ((parameterBuffer == null) || (parameterBuffer.Length < initialSize)) { if (parameterBuffer != null) { parameterBuffer.Dispose(); } parameterBuffer = new CNativeBuffer(initialSize); this._cmdWrapper._nativeParameterBuffer = parameterBuffer; } else { parameterBuffer.ZeroMemory(); } parameterBuffer.DangerousAddRef(ref success); this._parameterCollection.Bind(this, this._cmdWrapper, parameterBuffer); } if (target.IsBehavior(CommandBehavior.SchemaOnly)) { goto Label_0443; } if ((target.IsBehavior(CommandBehavior.KeyInfo) || target.IsBehavior(CommandBehavior.SchemaOnly)) && (this.CommandType != System.Data.CommandType.StoredProcedure)) { short num2; typeInfo = statementHandle.NumberOfResultColumns(out num2); switch (typeInfo) { case ODBC32.RetCode.SUCCESS: case ODBC32.RetCode.SUCCESS_WITH_INFO: if (num2 > 0) { target.GetSchemaTable(); } goto Label_029A; } if (typeInfo != ODBC32.RetCode.NO_DATA) { this._connection.HandleError(statementHandle, typeInfo); } } Label_029A: switch (odbcApiMethod) { case ODBC32.SQL_API.SQLEXECDIRECT: if (target.IsBehavior(CommandBehavior.KeyInfo) || this._isPrepared) { typeInfo = statementHandle.Execute(); } else { typeInfo = statementHandle.ExecuteDirect(this.CommandText); } break; case ODBC32.SQL_API.SQLCOLUMNS: typeInfo = statementHandle.Columns((string)methodArguments[0], (string)methodArguments[1], (string)methodArguments[2], (string)methodArguments[3]); break; case ODBC32.SQL_API.SQLSTATISTICS: typeInfo = statementHandle.Statistics((string)methodArguments[0], (string)methodArguments[1], (string)methodArguments[2], (short)methodArguments[3], (short)methodArguments[4]); break; case ODBC32.SQL_API.SQLTABLES: typeInfo = statementHandle.Tables((string)methodArguments[0], (string)methodArguments[1], (string)methodArguments[2], (string)methodArguments[3]); break; case ODBC32.SQL_API.SQLGETTYPEINFO: typeInfo = statementHandle.GetTypeInfo((short)methodArguments[0]); break; case ODBC32.SQL_API.SQLPROCEDURECOLUMNS: typeInfo = statementHandle.ProcedureColumns((string)methodArguments[0], (string)methodArguments[1], (string)methodArguments[2], (string)methodArguments[3]); break; case ODBC32.SQL_API.SQLPROCEDURES: typeInfo = statementHandle.Procedures((string)methodArguments[0], (string)methodArguments[1], (string)methodArguments[2]); break; default: throw ADP.InvalidOperation(method.ToString()); } if ((typeInfo != ODBC32.RetCode.SUCCESS) && (ODBC32.RetCode.NO_DATA != typeInfo)) { this._connection.HandleError(statementHandle, typeInfo); } } finally { if (success) { parameterBuffer.DangerousRelease(); } } Label_0443: this.weakDataReaderReference = new WeakReference(target); if (!target.IsBehavior(CommandBehavior.SchemaOnly)) { target.FirstResult(); } this.cmdState = ConnectionState.Fetching; } finally { if (ConnectionState.Fetching != this.cmdState) { if (target != null) { if (this._parameterCollection != null) { this._parameterCollection.ClearBindings(); } target.Dispose(); } if (this.cmdState != ConnectionState.Closed) { this.cmdState = ConnectionState.Closed; } } } return(target); }
private OdbcDataReader ExecuteReaderObject(CommandBehavior behavior, string method, bool needReader, object[] methodArguments, ODBC32.SQL_API odbcApiMethod) { OdbcDataReader target = null; try { ODBC32.RetCode typeInfo; this.DisposeDeadDataReader(); this.ValidateConnectionAndTransaction(method); if ((CommandBehavior.SingleRow & behavior) != CommandBehavior.Default) { behavior |= CommandBehavior.SingleResult; } OdbcStatementHandle statementHandle = this.GetStatementHandle().StatementHandle; this._cmdWrapper.Canceling = false; if ((this.weakDataReaderReference != null) && this.weakDataReaderReference.IsAlive) { object obj2 = this.weakDataReaderReference.Target; if (((obj2 != null) && this.weakDataReaderReference.IsAlive) && !((OdbcDataReader) obj2).IsClosed) { throw ADP.OpenReaderExists(); } } target = new OdbcDataReader(this, this._cmdWrapper, behavior); if (!this.Connection.ProviderInfo.NoQueryTimeout) { this.TrySetStatementAttribute(statementHandle, ODBC32.SQL_ATTR.QUERY_TIMEOUT, (IntPtr) this.CommandTimeout); } if ((needReader && this.Connection.IsV3Driver) && (!this.Connection.ProviderInfo.NoSqlSoptSSNoBrowseTable && !this.Connection.ProviderInfo.NoSqlSoptSSHiddenColumns)) { if (target.IsBehavior(CommandBehavior.KeyInfo)) { if (!this._cmdWrapper._ssKeyInfoModeOn) { this.TrySetStatementAttribute(statementHandle, (ODBC32.SQL_ATTR) 0x4cc, (IntPtr) 1L); this.TrySetStatementAttribute(statementHandle, ODBC32.SQL_ATTR.SQL_COPT_SS_TXN_ISOLATION, (IntPtr) 1L); this._cmdWrapper._ssKeyInfoModeOff = false; this._cmdWrapper._ssKeyInfoModeOn = true; } } else if (!this._cmdWrapper._ssKeyInfoModeOff) { this.TrySetStatementAttribute(statementHandle, (ODBC32.SQL_ATTR) 0x4cc, (IntPtr) 0L); this.TrySetStatementAttribute(statementHandle, ODBC32.SQL_ATTR.SQL_COPT_SS_TXN_ISOLATION, (IntPtr) 0L); this._cmdWrapper._ssKeyInfoModeOff = true; this._cmdWrapper._ssKeyInfoModeOn = false; } } if (target.IsBehavior(CommandBehavior.KeyInfo) || target.IsBehavior(CommandBehavior.SchemaOnly)) { typeInfo = statementHandle.Prepare(this.CommandText); if (typeInfo != ODBC32.RetCode.SUCCESS) { this._connection.HandleError(statementHandle, typeInfo); } } bool success = false; CNativeBuffer parameterBuffer = this._cmdWrapper._nativeParameterBuffer; RuntimeHelpers.PrepareConstrainedRegions(); try { if ((this._parameterCollection != null) && (0 < this._parameterCollection.Count)) { int initialSize = this._parameterCollection.CalcParameterBufferSize(this); if ((parameterBuffer == null) || (parameterBuffer.Length < initialSize)) { if (parameterBuffer != null) { parameterBuffer.Dispose(); } parameterBuffer = new CNativeBuffer(initialSize); this._cmdWrapper._nativeParameterBuffer = parameterBuffer; } else { parameterBuffer.ZeroMemory(); } parameterBuffer.DangerousAddRef(ref success); this._parameterCollection.Bind(this, this._cmdWrapper, parameterBuffer); } if (target.IsBehavior(CommandBehavior.SchemaOnly)) { goto Label_0443; } if ((target.IsBehavior(CommandBehavior.KeyInfo) || target.IsBehavior(CommandBehavior.SchemaOnly)) && (this.CommandType != System.Data.CommandType.StoredProcedure)) { short num2; typeInfo = statementHandle.NumberOfResultColumns(out num2); switch (typeInfo) { case ODBC32.RetCode.SUCCESS: case ODBC32.RetCode.SUCCESS_WITH_INFO: if (num2 > 0) { target.GetSchemaTable(); } goto Label_029A; } if (typeInfo != ODBC32.RetCode.NO_DATA) { this._connection.HandleError(statementHandle, typeInfo); } } Label_029A: switch (odbcApiMethod) { case ODBC32.SQL_API.SQLEXECDIRECT: if (target.IsBehavior(CommandBehavior.KeyInfo) || this._isPrepared) { typeInfo = statementHandle.Execute(); } else { typeInfo = statementHandle.ExecuteDirect(this.CommandText); } break; case ODBC32.SQL_API.SQLCOLUMNS: typeInfo = statementHandle.Columns((string) methodArguments[0], (string) methodArguments[1], (string) methodArguments[2], (string) methodArguments[3]); break; case ODBC32.SQL_API.SQLSTATISTICS: typeInfo = statementHandle.Statistics((string) methodArguments[0], (string) methodArguments[1], (string) methodArguments[2], (short) methodArguments[3], (short) methodArguments[4]); break; case ODBC32.SQL_API.SQLTABLES: typeInfo = statementHandle.Tables((string) methodArguments[0], (string) methodArguments[1], (string) methodArguments[2], (string) methodArguments[3]); break; case ODBC32.SQL_API.SQLGETTYPEINFO: typeInfo = statementHandle.GetTypeInfo((short) methodArguments[0]); break; case ODBC32.SQL_API.SQLPROCEDURECOLUMNS: typeInfo = statementHandle.ProcedureColumns((string) methodArguments[0], (string) methodArguments[1], (string) methodArguments[2], (string) methodArguments[3]); break; case ODBC32.SQL_API.SQLPROCEDURES: typeInfo = statementHandle.Procedures((string) methodArguments[0], (string) methodArguments[1], (string) methodArguments[2]); break; default: throw ADP.InvalidOperation(method.ToString()); } if ((typeInfo != ODBC32.RetCode.SUCCESS) && (ODBC32.RetCode.NO_DATA != typeInfo)) { this._connection.HandleError(statementHandle, typeInfo); } } finally { if (success) { parameterBuffer.DangerousRelease(); } } Label_0443: this.weakDataReaderReference = new WeakReference(target); if (!target.IsBehavior(CommandBehavior.SchemaOnly)) { target.FirstResult(); } this.cmdState = ConnectionState.Fetching; } finally { if (ConnectionState.Fetching != this.cmdState) { if (target != null) { if (this._parameterCollection != null) { this._parameterCollection.ClearBindings(); } target.Dispose(); } if (this.cmdState != ConnectionState.Closed) { this.cmdState = ConnectionState.Closed; } } } return target; }