/ Check-in [8d8af114]
Login

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

Overview
Comment:Fix the sqlite3_db_readonly() API so that it reports true if the database is readonly because the file format write version (byte 18 of the header) is too large.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8d8af114dac301335ec10671c1e9a5a6d8266a60
User & Date: drh 2014-05-21 08:21:07
Context
2014-05-21
08:48
Do not burn memory remembering CHECK constraints in a read-only database. check-in: 34ddf02d user: drh tags: trunk
08:21
Fix the sqlite3_db_readonly() API so that it reports true if the database is readonly because the file format write version (byte 18 of the header) is too large. check-in: 8d8af114 user: drh tags: trunk
2014-05-17
16:56
Internally, use a 64-bit integers for segment level numbers. check-in: 8180e320 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  8522   8522   ** set the mask of hint flags for cursor pCsr. Currently the only valid
  8523   8523   ** values are 0 and BTREE_BULKLOAD.
  8524   8524   */
  8525   8525   void sqlite3BtreeCursorHints(BtCursor *pCsr, unsigned int mask){
  8526   8526     assert( mask==BTREE_BULKLOAD || mask==0 );
  8527   8527     pCsr->hints = mask;
  8528   8528   }
         8529  +
         8530  +/*
         8531  +** Return true if the given Btree is read-only.
         8532  +*/
         8533  +int sqlite3BtreeIsReadonly(Btree *p){
         8534  +  return (p->pBt->btsFlags & BTS_READ_ONLY)!=0;
         8535  +}

Changes to src/btree.h.

   190    190   struct Pager *sqlite3BtreePager(Btree*);
   191    191   
   192    192   int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
   193    193   void sqlite3BtreeIncrblobCursor(BtCursor *);
   194    194   void sqlite3BtreeClearCursor(BtCursor *);
   195    195   int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
   196    196   void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask);
          197  +int sqlite3BtreeIsReadonly(Btree *pBt);
   197    198   
   198    199   #ifndef NDEBUG
   199    200   int sqlite3BtreeCursorIsValid(BtCursor*);
   200    201   #endif
   201    202   
   202    203   #ifndef SQLITE_OMIT_BTREECOUNT
   203    204   int sqlite3BtreeCount(BtCursor *, i64 *);

Changes to src/main.c.

  3441   3441   
  3442   3442   /*
  3443   3443   ** Return 1 if database is read-only or 0 if read/write.  Return -1 if
  3444   3444   ** no such database exists.
  3445   3445   */
  3446   3446   int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
  3447   3447     Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
  3448         -  return pBt ? sqlite3PagerIsreadonly(sqlite3BtreePager(pBt)) : -1;
         3448  +  return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
  3449   3449   }

Changes to test/rdonly.test.

    28     28   do_test rdonly-1.1 {
    29     29     execsql {
    30     30       CREATE TABLE t1(x);
    31     31       INSERT INTO t1 VALUES(1);
    32     32       SELECT * FROM t1;
    33     33     }
    34     34   } {1}
           35  +do_test rdonly-1.1.1 {
           36  +  sqlite3_db_readonly db main
           37  +} {0}
    35     38   
    36     39   # Changes the write version from 1 to 3.  Verify that the database
    37     40   # can be read but not written.
    38     41   #
    39     42   do_test rdonly-1.2 {
    40     43     db close
    41     44     hexio_get_int [hexio_read test.db 18 1]
................................................................................
    43     46   do_test rdonly-1.3 {
    44     47     hexio_write test.db 18 03
    45     48     sqlite3 db test.db
    46     49     execsql {
    47     50       SELECT * FROM t1;
    48     51     }
    49     52   } {1}
           53  +do_test rdonly-1.3.1 {
           54  +  sqlite3_db_readonly db main
           55  +} {1}
    50     56   do_test rdonly-1.4 {
    51     57     catchsql {
    52     58       INSERT INTO t1 VALUES(2)
    53     59     }
    54     60   } {1 {attempt to write a readonly database}}
    55     61   
    56     62   # Change the write version back to 1.  Verify that the database