【问题标题】:How to return a list and how to acess those values in lua如何返回一个列表以及如何访问 lua 中的值
【发布时间】:2011-06-15 08:20:01
【问题描述】:

本地函数getList()

        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

【问题讨论】:

标签: database sqlite lua


【解决方案1】:

这看起来和你昨天问的问题一样 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]

正如其他回复中所建议的,您需要查看《Lua 编程》一书中的表格部分,因为这是在 Lua 中做任何事情的关键。

【讨论】:

  • 是的,学习你使用的语言是基础。您需要学习阅读文档和自己学习的能力,而不是盲目地寻求帮助。我建议你阅读Programming in Lua,至少第2、4、5和7章。这里也有a link to LuaSQLite's docs,供你参考。
猜你喜欢
  • 2021-05-14
  • 1970-01-01
  • 2019-03-10
  • 2023-03-31
  • 2015-04-18
  • 1970-01-01
  • 1970-01-01
  • 2021-12-13
  • 2019-01-19
相关资源
最近更新 更多