Jump to content

SQLite & integrity checking


NewPlaza
 Share

Go to solution Solved by jchd,

Recommended Posts

Hello,

Does SQLite have a built in integrity check?

What I am asking is, does the statement

_SQLite_Startup()

open the db file and scan for any errors? I understand the data within the tables can be ANYTHING and that much can't be checked but what about the db being corrupt? I'm sure SQLite has a very specific file format it follows.  Is there a way that can be checked?

Link to comment
Share on other sites

_SQLite_Startup is only setup of the library/UDF for use.

_SQLite_Open doesn't check anything and doesn't even actually open the file. Actual operations are postponed until the first "active" SQL statement.

You can perform a full integrity check with:

_SQLite_Exec($hDB, "PRAGMA integrity_check;")

or, alternatively:

_SQLite_Exec($hDB, "PRAGMA integrity_check(integer);")

which will report only integer errors, if any.

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)

Link to comment
Share on other sites

Ha, I spoke too soon.  Thanks for the info.  Is there a return value for this? How can I check....

Something like this..

$CheckDB = _SQLite_Exec($hDB, "PRAGMA integrity_check;")

if 0 then error in db?

if 1 then db fine?

Please forgive my ignorance.  I am very new to SQLite.

Edited by NewPlaza
Link to comment
Share on other sites

  • Solution

My own oops! I completely forgot these return results!

If no error is found, the pragma returns a single row = "OK" and this is the only thing you want to know: in case of integrity error(s) better consider the DB corrupt and reload the last backup!

Here's a sketch use:

_SQLite_Startup()
If @error ... (abnormal condition)
Local $hDB = _SQLite_Open($DBFile)
If @error ... (abnormal condition)
Local $aRow
_SQLite_QuerySingleRow($hDB, "pragma integrity_check;", $aRow)
If @error ... (abnormal condition)
If $aRow[0] <> "OK" Then
    ; database is corrupt
Else
    ; DB is fine
EndIf

If you want to know more:

Local $iRows, $iCols, $aRows
_SQLite_GetTable($hDB, "pragma integrity_check;", $aRow, $iRows, $iCols)
; Here $aRows is an array containing a list of errors

Sorry for confusing you, it was late (and now it's even much later here!).

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)

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...