Created
August 7, 2011 23:55
-
-
Save yagitoshiro/1130949 to your computer and use it in GitHub Desktop.
simple sqlite script(excerpt) for titanium mobile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Before proceeding, you must create sqlite database "test.db" in Resources directory. | |
Ti.Database.install('test.db', 'tests'), | |
function insert(data){ | |
var sql = "INSERT INTO samples (id, title, sample) VALUES (?, ?, ?)"; | |
try{ | |
this.db.execute(sql, data.id, data.title, data.sample); | |
}catch(e){ | |
Ti.API.info('insert error:' + sql); | |
} | |
} | |
var columns = ['id', 'title', 'sample']; | |
function read(columns){ | |
var len = columns.length - 1; | |
var resultSet = this.db.execute(sql); | |
var results = []; | |
var result = null; | |
while(resultSet.isValidRow()){ | |
result = {}; | |
for(i = 0; i <= len; i++){ | |
result[columns[i]] = resultSet.fieldByName(columns[i]); | |
} | |
results.push(result); | |
resultSet.next(); | |
} | |
resultSet.close(); | |
return results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment