Create SQLite DB and Table

 Keywords:  reate SQLite SQLite3 ODBC DB Table ADO ADODB Meta Data

;Winbatch 2010C - quick and easy create SQLite DB and Table
;
;Consider this an alternative to using an INI or Registry Entries
;to hold system or meta data for you application. It does require the
;SQLite3 ODBC driver [ http://www.ch-werner.de/sqliteodbc/ ]
;
;Stan Littlefield April 24, 2011
;///////////////////////////////////////////////////////////////////////////////////

cDB=DirScript():"Test.SQLITE"
;NOTE: The Extension is not required

If FileExist(cDB) Then FileDelete(cDB) ;just inc case you run script multiple times

;set up the standard Connection
cConn= "DRIVER=SQLite3 ODBC Driver;Database=":cDB:";LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;"

;This is interesting, normally you would use ADOX to create a new Database, but SQLite does not
;support ADOX - however, making a standard ADO Connection, if the DB does not exists it will
;be created
oConn=CreateObject("ADODB.Connection")
oConn.Open(cConn)

;DB is created, now create a new table and insert values
oConn.Execute("create table myValues(one varchar(20), two smallint);")
oConn.Execute("insert into myValues values('menuopt',3);")
oConn.Execute("insert into myValues values('lastnumber', 26);")

;display what you just inserted
oRS=oConn.Execute("select * from myValues;")

Message("",oRS.GetString())
oRS.Close()
oRS=0
oConn.Close()
oConn=0
Exit
;///////////////////////////////////////////////////////////////////////////////////

Article ID:   W18194
Filename:   Create SQLite DB and Table.txt