Index: Setup/data/verify.lst ================================================================== --- Setup/data/verify.lst +++ Setup/data/verify.lst @@ -897,10 +897,11 @@ Tests/tkt-aba4549801.eagle Tests/tkt-ac47dd230a.eagle Tests/tkt-ae5267b863.eagle Tests/tkt-b167206ad3.eagle Tests/tkt-b4a7ddc83f.eagle + Tests/tkt-baf42ee135.eagle Tests/tkt-bb4b04d457.eagle Tests/tkt-c010fa6584.eagle Tests/tkt-c28d7fe915.eagle Tests/tkt-ccfa69fc32.eagle Tests/tkt-d4728aecb7.eagle Index: System.Data.SQLite/SQLiteDataReader.cs ================================================================== --- System.Data.SQLite/SQLiteDataReader.cs +++ System.Data.SQLite/SQLiteDataReader.cs @@ -1483,24 +1483,40 @@ string dataType = null; // If we have a table-bound column, extract the extra information from it if (String.IsNullOrEmpty(strColumn) == false) { + string baseCatalogName = String.Empty; + + if (row[SchemaTableOptionalColumn.BaseCatalogName] != DBNull.Value) + baseCatalogName = (string)row[SchemaTableOptionalColumn.BaseCatalogName]; + + string baseTableName = String.Empty; + + if (row[SchemaTableColumn.BaseTableName] != DBNull.Value) + baseTableName = (string)row[SchemaTableColumn.BaseTableName]; + + string baseColumnName = String.Empty; + + if (row[SchemaTableColumn.BaseColumnName] != DBNull.Value) + baseColumnName = (string)row[SchemaTableColumn.BaseColumnName]; + string collSeq = null; bool bNotNull = false; bool bPrimaryKey = false; bool bAutoIncrement = false; string[] arSize; // Get the column meta data _command.Connection._sql.ColumnMetaData( - (string)row[SchemaTableOptionalColumn.BaseCatalogName], - (string)row[SchemaTableColumn.BaseTableName], + baseCatalogName, + baseTableName, strColumn, ref dataType, ref collSeq, ref bNotNull, ref bPrimaryKey, ref bAutoIncrement); if (bNotNull || bPrimaryKey) row[SchemaTableColumn.AllowDBNull] = false; + bool allowDbNull = (bool)row[SchemaTableColumn.AllowDBNull]; row[SchemaTableColumn.IsKey] = bPrimaryKey && CountParents(parentToColumns) <= 1; row[SchemaTableOptionalColumn.IsAutoIncrement] = bAutoIncrement; row["CollationType"] = collSeq; @@ -1528,19 +1544,19 @@ if (wantDefaultValue) { // Determine the default value for the column, which sucks because we have to query the schema for each column using (SQLiteCommand cmdTable = new SQLiteCommand(HelperMethods.StringFormat(CultureInfo.InvariantCulture, "PRAGMA [{0}].TABLE_INFO([{1}])", - row[SchemaTableOptionalColumn.BaseCatalogName], - row[SchemaTableColumn.BaseTableName] + baseCatalogName, + baseTableName ), _command.Connection)) using (DbDataReader rdTable = cmdTable.ExecuteReader()) { // Find the matching column while (rdTable.Read()) { - if (String.Compare((string)row[SchemaTableColumn.BaseColumnName], rdTable.GetString(1), StringComparison.OrdinalIgnoreCase) == 0) + if (String.Compare(baseColumnName, rdTable.GetString(1), StringComparison.OrdinalIgnoreCase) == 0) { if (rdTable.IsDBNull(4) == false) row[SchemaTableOptionalColumn.DefaultValue] = rdTable[4]; break; @@ -1550,29 +1566,29 @@ } // Determine IsUnique properly, which is a pain in the butt! if (wantUniqueInfo) { - if ((string)row[SchemaTableOptionalColumn.BaseCatalogName] != strCatalog - || (string)row[SchemaTableColumn.BaseTableName] != strTable) + if (baseCatalogName != strCatalog + || baseTableName != strTable) { - strCatalog = (string)row[SchemaTableOptionalColumn.BaseCatalogName]; - strTable = (string)row[SchemaTableColumn.BaseTableName]; + strCatalog = baseCatalogName; + strTable = baseTableName; tblIndexes = _command.Connection.GetSchema("Indexes", new string[] { - (string)row[SchemaTableOptionalColumn.BaseCatalogName], + baseCatalogName, null, - (string)row[SchemaTableColumn.BaseTableName], + baseTableName, null }); } foreach (DataRow rowIndexes in tblIndexes.Rows) { tblIndexColumns = _command.Connection.GetSchema("IndexColumns", new string[] { - (string)row[SchemaTableOptionalColumn.BaseCatalogName], + baseCatalogName, null, - (string)row[SchemaTableColumn.BaseTableName], + baseTableName, (string)rowIndexes["INDEX_NAME"], null }); foreach (DataRow rowColumnIndex in tblIndexColumns.Rows) { @@ -1582,11 +1598,11 @@ // BUGFIX: Make sure that we only flag this column as "unique" // if we are not processing of some kind of multi-table // construct (i.e. a join) because in that case we must // allow duplicate values (refer to ticket [7e3fa93744]). // - if (parentToColumns.Count == 1 && tblIndexColumns.Rows.Count == 1 && (bool)row[SchemaTableColumn.AllowDBNull] == false) + if (parentToColumns.Count == 1 && tblIndexColumns.Rows.Count == 1 && allowDbNull == false) row[SchemaTableColumn.IsUnique] = rowIndexes["UNIQUE"]; // If its an integer primary key and the only primary key in the table, then its a rowid alias and is autoincrement // NOTE: Currently commented out because this is not always the desired behavior. For example, a 1:1 relationship with // another table, where the other table is autoincrement, but this one is not, and uses the rowid from the other. ADDED Tests/tkt-baf42ee135.eagle Index: Tests/tkt-baf42ee135.eagle ================================================================== --- /dev/null +++ Tests/tkt-baf42ee135.eagle @@ -0,0 +1,54 @@ +############################################################################### +# +# tkt-baf42ee135.eagle -- +# +# Written by Joe Mistachkin. +# Released to the public domain, use at your own risk! +# +############################################################################### + +package require Eagle +package require Eagle.Library +package require Eagle.Test + +runTestPrologue + +############################################################################### + +package require System.Data.SQLite.Test +runSQLiteTestPrologue + +############################################################################### + +runTest {test tkt-baf42ee135-1.1 {base catalog/table name not set} -setup { + setupDb [set fileName tkt-baf42ee135-1.1.db] +} -body { + sql execute $db { + CREATE TABLE ""(x); + } + + set dataReader [sql execute -execute reader -format datareader \ + -alias $db "SELECT x FROM \"\";"] + + set dataTable [$dataReader -alias GetSchemaTable] + + getRowsFromDataTable $dataTable +} -cleanup { + unset -nocomplain dataTable dataReader + + cleanupDb $fileName + + unset -nocomplain db fileName +} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\ +System.Data.SQLite} -result {{{ColumnName x} {ColumnOrdinal 0} {ColumnSize\ +2147483647} NumericPrecision NumericScale {IsUnique False} {IsKey False}\ +BaseServerName {BaseCatalogName main} {BaseColumnName x} {BaseSchemaName\ +sqlite_default_schema} BaseTableName {DataType System.Object} {AllowDBNull\ +True} {ProviderType 13} {IsAliased False} {IsExpression False} {IsAutoIncrement\ +False} {IsRowVersion False} {IsHidden False} {IsLong False} {IsReadOnly False}\ +ProviderSpecificDataType DefaultValue DataTypeName {CollationType BINARY}}}} + +############################################################################### + +runSQLiteTestEpilogue +runTestEpilogue