Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You probably already got your hands on the <code>sqlite3</code> "Database Connection Handle" object. It is defined in <a href="http://www.sqlite.org/cgi/src/artifact/d9e42f2029d4c526f9ba960bda1980ef17429c30" rel="nofollow">sqliteInt.h</a>:</p> <pre><code>struct sqlite3 { sqlite3_vfs *pVfs; /* OS Interface */ int nDb; /* Number of backends currently in use */ Db *aDb; /* All backends */ int flags; /* Miscellaneous flags. See below */ int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ int errCode; /* Most recent error code (SQLITE_*) */ int errMask; /* &amp; result codes with this before returning */ </code></pre> <p>You can then test for read-only with the <code>openFlags</code> member against <code>O_RDWR</code>.</p> <pre><code>#define O_RDONLY 00000000 #define O_WRONLY 00000001 #define O_RDWR 00000002 </code></pre> <p>For sure this is not the same as the newer <code>sqlite3_db_readonly()</code>, but it might be enough in your context.</p> <p><strong>Edit</strong></p> <p>Following up on your comment you can do the following to "future-proof" your code:</p> <ul> <li>check if the <code>sqlite3</code> struct varies between 3.7.0.1 and the first version that supports <code>sqlite3_db_readonly()</code></li> <li>use some macros to map the right dupe of the <code>sqlite3</code> struct (or the right offset of <code>openFlags</code>) with the corresponding 3.x.y.z version since <code>SQLITE_VERSION_NUMBER</code> is defined in sqlite3.h.</li> <li>starting with the version that supports <code>sqlite3_db_readonly()</code> just invoke it.</li> </ul> <p>Note that a database will be opened read-only if its file can only be opened for read, whether the sqlite3_open_v2 function is used with the <code>SQLITE_OPEN_READONLY</code> or not. So in addition to the aforementioned <code>openFlags</code> you'll also need to separately verify if the file can be opened read-only. The C API provides the function <code>xAccess</code> in the <code>sqlite3_vfs</code> struct. I'm guessing that this work whether your application already has a lock on the db file. See <a href="http://www.sqlite.org/c3ref/vfs.html" rel="nofollow">http://www.sqlite.org/c3ref/vfs.html</a> for more info.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload