私のsqliteには、カメラからの名前と画像を保存するための次のコードがあります。Eclipseコンソールから、名前とイメージパスを取得していることがわかります。console.log(addRecord)は名前と画像パスを取得していますが、トランザクション行とqueryDB関数に「未定義のSqlを実行できません」というメッセージが表示されるので、挿入ステートメントを間違えていると思いますか?また、データ型テキストはimageURIに対して正しいですか?助けていただければ幸いです。
function onDeviceReady() {
var db = window.openDatabase("database", "1.0", "Profiles", 5000);
if(db) {
console.log('The device is ready');
db.transaction(populateDB, errorCB, successCB, insertRecord); // only do stuff if db exists
}
else{
console.log('There is a problem');
}
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS USERS');//get rid of this once working?
tx.executeSql('CREATE TABLE IF NOT EXISTS USERS (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, username VARCHAR NOT NULL, imagePath TEXT)');
console.log('The table USERS is created');
}
//Insert the details
function insertRecord(tx) {
userName = document.getElementById('userName').value;
imagePath;
var addRecord = 'INSERT INTO USERS (username, imagePath) VALUES ("' + userName + '","' + imagePath + '")';
console.log(addRecord);
tx.executeSql(addRecord, [userName, imagePath], queryDB, errorCB);
}
// Query the database
function queryDB(tx) {
var getUsers = "SELECT * FROM USERS ORDER BY id ASC', [], querySuccess, errorCB";
db.transaction(function (tx) {
tx.executeSql(getUsers, [], querySuccess, queryFailure);
}, errorCB, successCB);
}
// Query the success callback
function querySuccess(tx, results) {
console.log("You are in the querysuccess function");
}
// Transaction error callback
function errorCB(err) {
console.log("Error processing SQL: " + err.code);
}
function queryFailure(err) {
console.log("Error processing SQL: " + err.code);
}
// Transaction success callback
function successCB() {
console.log('The db and table are working');
}