简体   繁体   English

Android:sqlite_master总是返回空光标

[英]Android: sqlite_master always returning empty cursor

I am trying to get a list of all of the tables in a database at runtime in my app, so I am using this command: 我试图在运行时在应用程序中获取数据库中所有表的列表,所以我在使用以下命令:

select * from sqlite_master;

However, no matter what, the resulting Cursor is empty. 但是,无论如何,结果游标为空。 I know there are tables in the database because I can read and write from them, and this very same query returns what I expect when run it in the adb shell. 我知道数据库中有表,因为我可以从它们中读取和写入数据,并且该查询与在adb shell中运行该表时返回的查询完全相同。

What could I be missing? 我可能会缺少什么?

I had a similar problem that I was scratching my head about for a while, but it simply turned out that I hadn't opened the database. 我有一个类似的问题,我已经花了一段时间了,但事实证明我没有打开数据库。 Just a reminder for whomever else looks at this question. 提醒其他任何人看这个问题。

Just a guess. 只是一个猜测。 Do you maybe use the same sqlite connection from two seperated threads? 您是否可能使用来自两个单独线程的相同sqlite连接? If you do, that's the problem . 如果这样做, 那就是问题所在

Good luck. 祝好运。

How about this. 这个怎么样。

SELECT name FROM 
   (SELECT * FROM sqlite_master UNION ALL
    SELECT * FROM sqlite_temp_master)
WHERE type='table'
ORDER BY name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM