2011-06-15 74 views
-2

本地函數的GetList()如何返回一個列表,以及如何接取在Lua這些值

 local select_stmt = db:prepare("SELECT * FROM list") 
     return select_stmt:rows(); 
    end 


    local rows = getList(); 

    --**here i need to print the rows list, how I can print using for loop** 

--************************************************ 
    **here I want to fetch single record, I am unable to fetch and print it?** 

    local function getListRecord(listId) 


     local select_stmt = db:prepare("SELECT * FROM list where id = ?") 
     select_stmt:bind_names{ id = listId } 
     return select_stmt:get_unames()-- i AM GETTING ERROR HERE 

    end 

    local row = getListRecord(3); 

--I am unable to get the row here, please help me 
+0

Duplicate:http://stackoverflow.com/questions/6344068/how-to-return-array-list-in-lua-program – BMitch 2011-06-15 10:42:45

回答

0

這看起來一樣的,你昨天 How to return array list in lua program?

for line,tblLine in pairs(rows) do 
    for key,data in pairs(tblLine) do 
    print(key,data) 
    end 
end 

問,如果你想的問題從列表中返回一行,並且您知道索引使用

row = rows[3] 

As在其他回覆中提出,你需要回顧Lua書中編程的表格部分,因爲這是在Lua中做任何事情的關鍵。

+0

是的,學習你使用的語言是根本。你需要學習閱讀文檔和爲自己學習的能力,而不是盲目地尋求幫助。我建議你閱讀[Lua編程](http://www.lua.org/pil/),至少第2,4,5和7章。這裏是[LuaSQLite的文檔鏈接](http:// lua .sqlite.org/index.cgi/doc/tip/doc/lsqlite3.wiki),供您參考。 – Zecc 2011-06-15 09:47:00

相關問題