测试在Luasqlite中是否存在一个表。

我正在使用Luasqlite

如果我想写一个检测表是否存在并返回布尔值的测试,该怎么做呢?

好像如果我尝试从一个不存在的表中选择一些东西作为我的测试,那么整个应用程序就会错误。

谢谢!

原文链接 https://stackoverflow.com/questions/3709967

点赞
stackoverflow用户44740
stackoverflow用户44740

你可以执行 table_info 的 pragma。

db:exec("pragma table_info('Publication');") -- 检查 'Publication'
2010-09-14 17:00:17
stackoverflow用户513763
stackoverflow用户513763

你也可以查询表 sqlite_master 以寻找你的表,例如:

found=false
db:exec([[select * from sqlite_master where name='my_table';]],
function(...) print(...) found=true return 0 end)
if found then print'table exists!' end
2011-07-28 12:58:11