SQLite,如何获取数据库中的所有表名? [英] SQLite, how to get all table names in database?

查看:271
本文介绍了SQLite,如何获取数据库中的所有表名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您认为从数据库获取所有表名称的正确方法是什么?将它们添加到列表中?

What do you think would be the right way to get all table names' from a database and add them to a list?

/ p>

Right now got that far:

final ArrayList<String> dirArray = new ArrayList<String>();

SqlHelper sqlHelper = new SqlHelper(this, "TK.db", null, 1);
SQLiteDatabase DB = sqlHelper.getWritableDatabase();
Cursor c = DB.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);

c.moveToFirst();
while (c.isAfterLast() == false) {
   dirArray.add("n" + c.getColumnIndex("name"));
   c.moveToNext();
 }
c.close();

但它输出一些android_metadata,而不是我的表名。因此猜测查询有问题。

But it outputs some "android_metadata" instead of my table name's. So guess there's something wrong with the query.

谢谢!

推荐答案

刚刚做了一个快速测试在SQLite Manager插件在FireFox与我使用的SQLite数据库,你使用的查询返回表名。

Just did a quick test in the SQLite Manager plugin in FireFox with the SQLite db i'm working with and the query you're using does return the table names. Are you creating the tables correctly and have you tested the exist to your expectations?

要进行迭代,请执行以下操作:

To iterate through, do something like:

    if (c.moveToFirst())
    {
        while ( !c.isAfterLast() ){
           dirArray.add( c.getString( c.getColumnIndex("name")) );
           c.moveToNext();
        }
    }

这篇关于SQLite,如何获取数据库中的所有表名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆