I’m new to using SQlite, so I’d apperciate it if ya’ll would go over this code and find any errors.
[code]
local function config:init(options)
local path = system.pathForFile(“config.cfg”, system.DocumentsDirectory )
config_DBHandle = sqlite3.open(path) – Open SQLite DB
if not(onDevice)
print(path)
print(config_DBHandle)
end
–One Time Init
– OTI- needs to create the database with default values. Get info from Word file.
config_DBHandle:exec[=[
CREATE TABLE IF NOT EXISTS mydb.config (
id NOT NULL AUTO_INCREMENT,
option VARCHAR(45) NULL ,
value VARCHAR(255) NULL ,
PRIMARY KEY (id) )
]=]
end
local function config:get(option,value)
for row in config_DBHandle:nrows(‘SELECT * FROM config WHERE option=’’ … option …’’’ ) do return row.id,row.content end
end
local function config:set(option,value)
if config_DBHandle:exec(‘INSERT INTO config WHERE option=’’ … option… ‘’ VALUES=(’ … value … ‘)’)
if not(onDevice)
print(‘DB SUCCESS!’)
end
end
end [import]uid: 7467 topic_id: 1677 reply_id: 301677[/import]