WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

SQLite

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Determine if File is SQLite DB

 Keywords:  Determine Check File SQLite Database

Because an SQLite File can use any extension or none at all I wrote this little udf to determine if a file is a valid SQLite DB and if so quickly pull up the tables as a persisted XML recordset.

;Winbatch 2010C - Determine if File is SQLite Database
;                 if True, Display tables as Z:row XML
;
;Driver download: http://www.ch-werner.de/sqliteodbc/
;
;Stan Littlefield, May 14, 2011
;//////////////////////////////////////////////////////////////////////////////////////
#DefineFunction isSqLite(cDB)
valid="53514C69746520666F726D6174203300"
retval=0
fs=FileSize(cDB)
binbuf = BinaryAlloc(fs+100)
If binbuf == 0
   Return(retval)
Else
   BinaryRead(binbuf, cDB)
   ret=BinaryPeekHex( binbuf, 0, 16)
   If ret==valid Then retval=1
EndIf
BinaryFree(binbuf)
Return(retval)
#EndFunction


cDB=DirScript():"SMS.sqlite"
If !FileExist(cDB) Then Exit

If isSqLite(cDB)
   cXML =DirScript():"sqlite.xml"
   If FileExist(cXML) Then FileDelete(cXML)
   cConn= "DRIVER=SQLite3 ODBC Driver;Database=":cDB:";LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;"
   oConn=CreateObject("ADODB.Connection")
   oConn.Open(cConn)
   oRS=oConn.OpenSchema(20)
   oRS.Save(cXML,1)
   oRS=0
   oConn.Close()
   oConn=0
   Run("notepad.exe", cXML)
Else
   Display(2,cDB,"Is Not an SQLite Database File")
EndIf

Exit

Article ID:   W18195
Filename:   Determine if File is SQLite DB .txt
File Created: 2011:06:07:13:33:56
Last Updated: 2011:06:07:13:33:56