[英]Titanium mobile - Uncaught Error: no such table
我度過了一個糟糕的時光,試圖弄清楚為什么我總是收到這個錯誤。 我已經搜索過這個論壇和其他論壇,但似乎沒有答案可以提供幫助,因此我將在這里提出問題。
我正在嘗試使用Titanium為Android創建基本的照片目錄應用程序。 目錄信息存儲在sqlite數據庫中。
我可以創建數據庫,確定-我可以在一個窗口中從中訪問一些信息。 然后,當我轉到另一個窗口並嘗試從表中獲取更多信息時,它給了我錯誤:
未捕獲的錯誤:沒有這樣的表:photos :,正在編譯SELECT ..........
參見下面的代碼:
這是從app.js打開的第一個窗口
該表在這里顯示很好-沒有錯誤
// create var for the currentWindow
var currentWin = Ti.UI.currentWindow;
// set the data from the database to the array
//function setData() {
// create table view
var tableview = Ti.UI.createTableView({
});
//var db = Ti.Database.open('catalogue');
//db.remove();
var db = Ti.Database.install('catalogue.sqlite','photos');
var rows = db.execute('SELECT * FROM photos GROUP BY title');
// create the array
var dataArray = [];
while(rows.isValidRow()) {
var title = rows.fieldByName('title');
var id = rows.fieldByName('id');
dataArray.push({title:title, id:id, url:'catalogue_detail.js'});
rows.next();
}
tableview.setData(dataArray);
// add the tableView to the current window
currentWin.add(tableview);
tableview.addEventListener('click', function(e){
if (e.rowData.url)
{
var win = Ti.UI.createWindow({
id:e.rowData.id,
title:e.rowData.title,
url:e.rowData.url
});
win.open();
}
});
// call the setData function to attach the database results to the array
//setData();
然后我從上面打開catalogue_detail.js並收到錯誤消息
catalogue_detail.js
var win = Titanium.UI.currentWindow;
var id = win.id
var tableview = Titanium.UI.createTableView({
});
var db = Titanium.Database.open('catalogue.sqlite');//I have chanegd this to 'photos' and I get the same error
var sql = db.execute('SELECT title, location, photographer FROM photos where id="' + id + '"');
var title = sql.fieldByName('title');
var location = sql.fieldByName('location');
var photographer = sql.fieldByName('photographer');
// create the array
var dataArray = [];
while(sql.isValidRow()) {
var title = sql.fieldByName('title');
var location = sql.fieldByName('location');
var photographer = sql.fieldByName('photographer');
dataArray.push({title:title, location:location, photographer:photographer});
sql.next();
}
tableview.setData(dataArray);
win.add(tableview);
因此,數據庫中名為“照片”的表在一個窗口中打開,然后在嘗試打開同一數據庫時出現錯誤?
我已經卸載了應用程序,重新創建了數據庫,重命名了表格等,但仍然是相同的錯誤...
我確信這是一件簡單的事情,但是我很困惑!
感謝您的協助。
JC
嘗試絕對路徑: Ti.Database.open('catalogue.sqlite');
和Ti.Database.install('/catalogue.sqlite');
。
還記得從查詢中檢索所有數據時關閉與數據庫的連接:
sql.close();
db.close();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.