Jump to content

Recommended Posts

Posted

My SQLite.au3 include contains this entry on line 43

Global Const $SQLITE_READONLY = 8 ; /* Attempt to write a readonly database */

But, is not in the Help file.  The right page, I think is _SQLite_Open.htm, and does not contain a reference to opening a SQLite db as ReadOnly.  Should this be added to the Help File?

 

BUT, what I really want to know is this: What is the best way to determine whether a SQLite db should be opened as ReadOnly?

I have WAL files active.  Can I check for WAL and if exists, force open ReadOnly?  ie, if a user is already logged on, simply for other users to Read Only?

Is this the right question to ask?

 

 

Skysnake

Why is the snake in the sky?

Posted

The reason to open a database as readonly would be if you only want to read from it and not alter its contents, even by mistake.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

The reason to open a database as readonly would be if you only want to read from it and not alter its contents, even by mistake.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

Exactly.  I want to allow only the first connection to have default (full) access, all subsequent connections must be read only...

 

Skysnake

Why is the snake in the sky?

Posted
12 minutes ago, Skysnake said:

But, is not in the Help file.  The right page, I think is _SQLite_Open.htm, and does not contain a reference to opening a SQLite db as ReadOnly.  Should this be added to the Help File?

Look again: these constants are SQLite error return codes, not DB open filemodes.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted (edited)

Hmm.  Thx @jchd, BUT, this is possible ito https://www.sqlite.org/c3ref/open.html. So, (1) I must be able to this with AutoIt and (2) my original question, what is the best way to trigger such a state?

SQLITE_OPEN_READONLY

from https://www.sqlite.org/c3ref/c_open_autoproxy.html

SQLite.au3 Line 62

Global Const $SQLITE_OPEN_READONLY = 0x01 ; /* Database opened as read-only */

 

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Posted

Rephrase - I have a SQLite db that uses WAL files.  How can I determine that a pre-existing connection is already active, and force subsequent connections to READ ONLY?

Skysnake

Why is the snake in the sky?

Posted

You can open a DB file as read only using two ways:

o) pass the $SQLITE_OPEN_READONLY as the second parameter to _SQlite_Open
o) use an URI filename, like in _SQlite_Open(" file:/somedir/MyDB.sq3?mode=ro", 0) but I'm not sure if the URI option prevails over the declared mode.

You can't know if other process is using the file. That would need a centralized server, which SQLite doesn't have for obvious reasons.

The problem with opening a DB as RO is that if there is a hot journal or something in WAL files needing to update the actual DB file, then the RO will prevent that.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted (edited)
2 minutes ago, jchd said:

The problem with opening a DB as RO is that if there is a hot journal or something in WAL files needing to update the actual DB file, then the RO will prevent that.

:(

No I am really glad I asked first. Thx @jchd, much appreciated!

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Posted

If you're unsure that the first, initial and unique process has finished writing the DB and releasing the connection, you can also use the access rights extension and sqlite3_set_authorizer() to block unwanted writes.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted (edited)

Thx @jchd, you are a star!

My idea so far was to have the first connection write a file to disk, much like the Postgre .pid file for the service, then check if .pid exists or not... not foolproof... other option is to force default connection as READONLY and only use write when necessary.

Best option is to move to real db server... like Postgre or Firebird :)

Thx

Skysnake

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Posted

I mean that if you definitely require that users can't write to the DB, you'll have to use Windows access rights and disallow use of anything alse than your application (e.g. third-party SQLite managers). Then compile the SQLite DLL with the userauth extension (in source tree under ext/misc). User authentication this way is rather weak since it relies on user not being able to access the file otherwise (that's where the OS filesystem permissions enter the game).

Then if the only program able to access the file is your application and if user are authorized, then it's pretty simple to track who reads and writes and when.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...