internal DBSqlParserTable FindTableForColumn( DBSqlParserColumn column ) { DBSqlParserTableCollection tables = Tables; int tableCount = tables.Count; for (int i = 0; i < tableCount; ++i) { DBSqlParserTable table = tables[i]; // if the table name matches the correlation name, then we're certain // of a match if (string.Empty == column.DatabaseName && string.Empty == column.SchemaName && CatalogMatch(column.TableName, table.CorrelationName)) { return(table); } // otherwise, compare each part of the name (if they exist) with the // table and pick the one that matches all the parts that exist. if ((string.Empty == column.DatabaseName || CatalogMatch(column.DatabaseName, table.DatabaseName)) && (string.Empty == column.SchemaName || CatalogMatch(column.SchemaName, table.SchemaName)) && (string.Empty == column.TableName || CatalogMatch(column.TableName, table.TableName))) { return(table); } } Debug.Assert(false, "Why didn't we find a match for the column?"); return(null); }
//---------------------------------------------------------------------- // this[] // internal DBSqlParserTable this[int i] { get { DBSqlParserTable value = (DBSqlParserTable)InnerList[i]; return(value); } }
internal void CopySchemaInfoFrom(DBSqlParserTable table) { _databaseName = table.DatabaseName; _schemaName = table.SchemaName; _tableName = table.TableName; _isKey = false; _isUnique = false; }
internal DBSqlParserTable Add( string databaseName, string schemaName, string tableName, string correlationName ) { DBSqlParserTable p = new DBSqlParserTable(databaseName, schemaName, tableName, correlationName); return(Add(p)); }
protected DBSqlParserColumn FindCompletedColumn( DBSqlParserTable table, DBSqlParserColumn searchColumn ) { DBSqlParserColumnCollection columns = table.Columns; int columnsCount = columns.Count; for (int i = 0; i < columnsCount; ++i) { DBSqlParserColumn column = columns[i]; // Compare each part of the name (if they exist) with the // table and pick the one that matches all the parts that exist. if (CatalogMatch(column.ColumnName, searchColumn.ColumnName)) { return(column); } } // MDAC 87152: ROWID and ROWNUM shouldn't fire an assert here: //Debug.Assert(false, "Why didn't we find a match for the search column?"); return(null); }
// Called after the table and column information is completed to // identify which columns in the select-list are key columns for // their table. abstract protected void GatherKeyColumns( DBSqlParserTable table );
private void CompleteSchemaInformation() { DBSqlParserColumnCollection columns = Columns; DBSqlParserTableCollection tables = Tables; int columnCount = columns.Count; int tableCount = tables.Count; // First, derive all of the information we can about each table for (int i = 0; i < tableCount; i++) { DBSqlParserTable table = tables[i]; DBSqlParserColumnCollection tableColumns = GatherTableColumns(table); table.Columns = tableColumns; } // Next, derive all of the column information we can. for (int i = 0; i < columnCount; i++) { DBSqlParserColumn column = columns[i]; DBSqlParserTable table = FindTableForColumn(column); if (!column.IsExpression) { // If this is a '*' column, then we have to expand the '*' into // its component parts. if ("*" == column.ColumnName) { // Remove the existing "*" column entry and replace it with the // complete list of columns in the table. columns.RemoveAt(i); // If this is a tablename.* column, then add references to the // all columns in the specified table, otherwise add references // to all columns in all tables. if (String.Empty != column.TableName) { DBSqlParserColumnCollection tableColumns = table.Columns; int tableColumnCount = tableColumns.Count; for (int j = 0; j < tableColumnCount; ++j) { columns.Insert(i + j, tableColumns[j]); } columnCount += tableColumnCount - 1; // don't forget to adjust our loop end i += tableColumnCount - 1; } else { for (int k = 0; k < tableCount; k++) { table = tables[k]; DBSqlParserColumnCollection tableColumns = table.Columns; int tableColumnCount = tableColumns.Count; for (int j = 0; j < tableColumnCount; ++j) { columns.Insert(i + j, tableColumns[j]); } columnCount += tableColumnCount - 1; // don't forget to adjust our loop end i += tableColumnCount; } } } else { // if this isn't a '*' column, we find the table that the column belongs // to, and ask it's column collection for the completed column info (that // contains information about key values, etc.) DBSqlParserColumn completedColumn = FindCompletedColumn(table, column); if (null != completedColumn) // MDAC 87152 { column.CopySchemaInfoFrom(completedColumn); } else { column.CopySchemaInfoFrom(table); } } } } // Finally, derive the key column information for each table for (int i = 0; i < tableCount; i++) { DBSqlParserTable table = tables[i]; GatherKeyColumns(table); } }
// Called to get a column list for the table specified. abstract protected DBSqlParserColumnCollection GatherTableColumns( DBSqlParserTable table );
//////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// // // Methods // //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// //---------------------------------------------------------------------- // Add() // internal DBSqlParserTable Add(DBSqlParserTable value) { OnValidate(value); InnerList.Add(value); return(value); }
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); }
protected override void GatherKeyColumns( DBSqlParserTable table ) { // Called after the table and column information is completed to // identify which columns in the select-list are key columns for // their table. OracleCommand cmd = null; OracleDataReader rdr = null; try { try { cmd = _connection.CreateCommand(); cmd.Transaction = _connection.Transaction; // must set the transaction context to be the same as the command, or we'll throw when we execute. string schemaName = CatalogCase(table.SchemaName); string tableName = CatalogCase(table.TableName); string synonymSchemaName = schemaName; string synonymTableName = tableName; // First, we have to "dereference" a synonym, if it was specified, because // synonyms don't have catalog items stored for them, they're for the table // or view that the synonym references. cmd.CommandText = GetSynonymQueryStatement(schemaName, tableName); rdr = cmd.ExecuteReader(); if (rdr.Read()) { synonymSchemaName = rdr.GetString(0); synonymTableName = rdr.GetString(1); } rdr.Dispose(); // Now we have the real schema name and table name, go and derive the key // columns cmd.CommandText = GetConstraintQueryStatement(synonymSchemaName, synonymTableName); rdr = cmd.ExecuteReader(); ArrayList constraintColumnNames = new ArrayList(); bool isUniqueConstraint; if (true == (_moreConstraints = rdr.Read())) { while (GetConstraint(rdr, out isUniqueConstraint, constraintColumnNames)) { bool foundAllColumns = true; int constraintColumnCount = constraintColumnNames.Count; DBSqlParserColumn[] constraintColumn = new DBSqlParserColumn[constraintColumnCount]; for (int j = 0; j < constraintColumnCount; ++j) { DBSqlParserColumn column = FindConstraintColumn( schemaName, tableName, (string)constraintColumnNames[j] ); if (null == column) { foundAllColumns = false; break; } constraintColumn[j] = column; } if (foundAllColumns) { for (int j = 0; j < constraintColumnCount; ++j) { constraintColumn[j].SetAsKey(isUniqueConstraint); } break; } } } } finally { if (null != cmd) { cmd.Dispose(); cmd = null; } if (null != rdr) { rdr.Dispose(); rdr = null; } } } catch { // Prevent exception filters from running in our space throw; } }