System.Data.SQLite
Check-in [a47688aca5]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix issue that prevented SQLiteBlob creation from succeeding for tables that did not have an integer primary key.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a47688aca5f546b6dc28c94ca54951b0c4345764
User & Date: mistachkin 2017-06-10 00:56:00
Context
2017-06-10
17:38
Merge updates from trunk. check-in: 091bc3a48a user: mistachkin tags: branch-1.0.105
01:09
Simplify the new test case added in the previous check-in. check-in: ac29179121 user: mistachkin tags: trunk
00:56
Fix issue that prevented SQLiteBlob creation from succeeding for tables that did not have an integer primary key. check-in: a47688aca5 user: mistachkin tags: trunk
00:51
Correct cursor type checking in the sqlite3_cursor_rowid_interop() function. check-in: 99b0ca713e user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite/SQLiteDataReader.cs.

   515    515       {
   516    516           // CheckDisposed();
   517    517           VerifyForGet();
   518    518   
   519    519           if (_keyInfo == null)
   520    520               return null;
   521    521   
   522         -        int iRowId = _keyInfo.GetRowIdIndex(
   523         -            GetDatabaseName(i), GetTableName(i));
          522  +        string databaseName = GetDatabaseName(i);
          523  +        string tableName = GetTableName(i);
          524  +        int iRowId = _keyInfo.GetRowIdIndex(databaseName, tableName);
   524    525   
   525         -        if (iRowId == -1)
   526         -            return null;
          526  +        if (iRowId != -1)
          527  +            return GetInt64(iRowId);
   527    528   
   528         -        return GetInt64(iRowId);
          529  +        return _keyInfo.GetRowId(databaseName, tableName);
   529    530       }
   530    531   
   531    532       /// <summary>
   532    533       /// Retrieves the column as a <see cref="SQLiteBlob" /> object.
   533    534       /// This will not work for tables that were created WITHOUT ROWID
   534    535       /// -OR- if the query does not include the "rowid" column or one
   535    536       /// of its aliases -OR- if the <see cref="SQLiteDataReader" /> was

Changes to System.Data.SQLite/SQLiteKeyReader.cs.

   361    361                       return _rowIdInfo[i].column;
   362    362                   }
   363    363               }
   364    364           }
   365    365   
   366    366           return -1;
   367    367       }
          368  +
          369  +    ///////////////////////////////////////////////////////////////////////////////////////////////
          370  +
          371  +    internal long? GetRowId(
          372  +        string databaseName,
          373  +        string tableName
          374  +        )
          375  +    {
          376  +        if ((_keyInfo != null) &&
          377  +            (databaseName != null) &&
          378  +            (tableName != null))
          379  +        {
          380  +            for (int i = 0; i < _keyInfo.Length; i++)
          381  +            {
          382  +                if (_keyInfo[i].databaseName == databaseName &&
          383  +                    _keyInfo[i].tableName == tableName)
          384  +                {
          385  +                    long rowid = _stmt._sql.GetRowIdForCursor(_stmt, _keyInfo[i].cursor);
          386  +
          387  +                    if (rowid != 0)
          388  +                        return rowid;
          389  +                }
          390  +            }
          391  +        }
          392  +
          393  +        return null;
          394  +    }
   368    395   
   369    396       ///////////////////////////////////////////////////////////////////////////////////////////////
   370    397   
   371    398       #region IDisposable Members
   372    399       public void Dispose()
   373    400       {
   374    401           Dispose(true);

Changes to Tests/basic.eagle.

  4619   4619         [getOtherCount Method_GetXmlConfigFileName] == 2 && \
  4620   4620         [getOtherCount Method_GetCachedAssemblyDirectory] >= 2 && \
  4621   4621         [getOtherCount Method_GetCachedXmlConfigFileName] >= 2}
  4622   4622   } -cleanup {
  4623   4623     moveSystemDataSQLiteDllConfig true
  4624   4624   } -constraints {eagle command.object monoBug28 System.Data.SQLite\
  4625   4625   buildConfiguration.Debug} -result {True}}
         4626  +
         4627  +###############################################################################
         4628  +
         4629  +runTest {test data-1.89 {using SQLiteBlob without rowid PK index} -setup {
         4630  +  setupDb [set fileName data-1.89.db]
         4631  +} -body {
         4632  +  sql execute $db {
         4633  +    CREATE TABLE t1 (x GUID UNIQUE NOT NULL, y BLOB NOT NULL);
         4634  +    INSERT INTO t1 (x, y) VALUES(
         4635  +      '12345678-0000-0000-0000-000000000000',
         4636  +      X'010203040506070809'
         4637  +    );
         4638  +    INSERT INTO t1 (x, y) VALUES(
         4639  +      '12345679-0000-0000-0000-000000000000',
         4640  +      X'0102030405060708090A0B0C0D0E0F101113'
         4641  +    );
         4642  +  }
         4643  +
         4644  +  set sql(1) { \
         4645  +    SELECT rowid, y FROM t1 \
         4646  +    WHERE x = '12345678-0000-0000-0000-000000000000'; \
         4647  +  }
         4648  +
         4649  +  set sql(2) { \
         4650  +    SELECT rowid, y FROM t1 \
         4651  +    WHERE x = '12345679-0000-0000-0000-000000000000'; \
         4652  +  }
         4653  +
         4654  +  set dataReader [sql execute -execute reader -format datareader \
         4655  +      -behavior +KeyInfo -alias $db $sql(1)]
         4656  +
         4657  +  while {[$dataReader Read]} {
         4658  +    set blob [object invoke -alias \
         4659  +        System.Data.SQLite.SQLiteBlob Create $dataReader 1 true]
         4660  +
         4661  +    lappend result [$blob GetCount]
         4662  +
         4663  +    $blob Close
         4664  +  }
         4665  +
         4666  +  $dataReader Close; unset dataReader
         4667  +
         4668  +  set dataReader [sql execute -execute reader -format datareader \
         4669  +      -behavior +KeyInfo -alias $db $sql(2)]
         4670  +
         4671  +  while {[$dataReader Read]} {
         4672  +    set blob [object invoke -alias \
         4673  +        System.Data.SQLite.SQLiteBlob Create $dataReader 1 true]
         4674  +
         4675  +    lappend result [$blob GetCount]
         4676  +
         4677  +    $blob Close
         4678  +  }
         4679  +
         4680  +  $dataReader Close; unset dataReader
         4681  +
         4682  +  set result
         4683  +} -cleanup {
         4684  +  unset -nocomplain blob
         4685  +  unset -nocomplain dataReader
         4686  +
         4687  +  cleanupDb $fileName
         4688  +
         4689  +  unset -nocomplain result sql db fileName
         4690  +} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
         4691  +System.Data.SQLite} -result {9 18}}
  4626   4692   
  4627   4693   ###############################################################################
  4628   4694   
  4629   4695   reportSQLiteResources $test_channel
  4630   4696   
  4631   4697   ###############################################################################
  4632   4698   
  4633   4699   runSQLiteTestFilesEpilogue
  4634   4700   runSQLiteTestEpilogue
  4635   4701   runTestEpilogue