NewPlaza Posted September 9, 2013 Posted September 9, 2013 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?
jchd Posted September 9, 2013 Posted September 9, 2013 _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 hereRegExp tutorial: enough to get startedPCRE 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)
NewPlaza Posted September 10, 2013 Author Posted September 10, 2013 (edited) 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 September 10, 2013 by NewPlaza
Solution jchd Posted September 10, 2013 Solution Posted September 10, 2013 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 hereRegExp tutorial: enough to get startedPCRE 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)
NewPlaza Posted September 10, 2013 Author Posted September 10, 2013 That my friend is what I need. Thanks for all your help.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now