Titanium sqlite ORDER BY 语句

2021-11-15 00:00:00 javascript sqlite titanium appcelerator

使用 Titanium appcelerator.如何使用单击按钮激活的 sql 查询对我的数据库进行排序.到目前为止,我的代码是:

Using Titanium appcelerator. How can i sort my database with an sql query which is activated on a button click. my code so far is:

SortButton.addEventListener('click',function(e){
    sortList();
});


function sortList()
{
    db.execute("SELECT * FROM SavedList ORDER BY SavedListed ASC");
}

推荐答案

你的代码 : db.execute("SELECT * FROM SavedList ORDER BY SavedListed ASC");是正确的.只需在 db.execute 之前打开数据库并在 db.execute 之后关闭它.它会起作用.

Your code : db.execute("SELECT * FROM SavedList ORDER BY SavedListed ASC"); is correct. Just open database before db.execute and close it after db.execute. It will work.

打开数据库:var db = Ti.Database.open('databaseName');

To open database : var db = Ti.Database.open('databaseName');

关闭数据库:db.close();

To close database: db.close();

相关文章