Skip to content

Instantly share code, notes, and snippets.

@yagitoshiro
Created August 7, 2011 23:55
Show Gist options
  • Save yagitoshiro/1130949 to your computer and use it in GitHub Desktop.
Save yagitoshiro/1130949 to your computer and use it in GitHub Desktop.
simple sqlite script(excerpt) for titanium mobile
// 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