Reputation: 25
thank you for your time.
School has been asking me to work with a local database, and as much help as I ask for, nothing has come. So, I'm attempting to make a super simple application that has a database, and build an application around it from there. I used a tutorial code from http://pedrobraz.com/hello-world/ , but it seems to give me the same error every time.
nativeReason = "Error Domain=com.plausiblelabs.pldatabase Code=3 \"An error occured parsing the provided SQL statement.\" UserInfo=0xcf52be0 {com.plausiblelabs.pldatabase.error.vendor.code=1, NSLocalizedDescription=An error occured parsing the provided SQL statement., com.plausiblelabs.pldatabase.error.query.string=INSERT INTO tablename (id, company) VALUES(?,?), com.plausiblelabs.pldatabase.error.vendor.string=no such table: tablename}";
I don't understand why though, since I was following exactly what the website stated. I've had this issue before with almost every app-generated table I create. I'll put the code I added here, but any suggestions as to an error would be greatly appreciated.
Titanium.UI.setBackgroundColor('#000');
var win = Ti.UI.createWindow({backgroundColor: "#fff"});
var db = Titanium.Database.open('myDatabase');
db.execute('CREATE TABLE IF NOT EXISTS tablename (id INTEGER PRIMARY KEY, company TEXT)');
var companyfield = Titanium.UI.createTextField({
hintText:'Name',
height:35,
top:200,
left:30,
width:250,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(companyfield);
var save = Titanium.UI.createButton({
title:'Save Info',
top:350,
left:30,
height:30,
width:250
});
win.add(save);
// ----- Create an event listener for the tableView ----- //
save.addEventListener('click', function(e) {
//this variable holds whatever was typed in the textbox
var passaction = companyfield.value;
//this opens the database
var db = Titanium.Database.open('myinfodb');
//this puts the data into the field
db.execute('INSERT INTO tablename (id, company) VALUES(?,?)', 1, passaction);
});
win.open();
Upvotes: 1
Views: 279
Reputation: 1619
Your error is :
In your code you provided :
var db = Titanium.Database.open('myDatabase'); //----> DB NAME = myDatabase
db.execute('CREATE TABLE IF NOT EXISTS tablename (id INTEGER PRIMARY KEY, company TEXT)');
and later in your code you wrote :
var db = Titanium.Database.open('myinfodb'); //----> DB NAME = myinfodb
db.execute('INSERT INTO tablename (id, company) VALUES(?,?)', 1, passaction);
So the issue is simple you are create two different databases.
Hence DB NAME = myDatabase contains table = tablename but DB NAME = myinfodb does not.
Upvotes: 1