2011-12-22 54 views
0

我嘗試使用SQLite創建桌面應用程序。我使用SQLite創建「test.db」數據庫文件,其表名爲「test1」,具有「id」和「name」字段。我嘗試下面的代碼從數據庫中獲取數據:如何使用數據庫的鈦桌面應用程序

<script type="text/javascript"> 
var db = Titanium.Database.openFile('test.db'); 
var rows = db.execute("select * from test1"); 
alert('result set is: ' + rows.fieldByName('id') + ' : ' + rows.fieldByName('name')); 
</script> 

但是這段代碼不起作用。請告訴我使用SQLite的另一種方式。

感謝

+0

,您是否試圖警報(行)? – 2011-12-23 06:48:22

+0

您的數據庫打不開,請嘗試Titanium.Database.install,然後提醒您的數據庫,並查看它顯示的內容。 http://developer.appcelerator.com/apidoc/mobile/1.7.2/Titanium.Database.install-method.html – 2011-12-23 10:26:20

回答

0
var db = Titanium.Database.openFile(db_path); 
     result=db.execute("SELECT * FROM images WHERE ev='"+ev_id+"'AND path='"+Titanium.App.getHome()+"/Resources/"+filename+"'"); 
     if(result.rowCount()) 
     { 
      width_ratio=w/result.fieldByName("width"); 
     height_ratio=h/result.fieldByName("height"); 
} 
相關問題