SQLite的"没有这样的表" [英] SQLite "no such table"

查看:224
本文介绍了SQLite的"没有这样的表"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了Eclipse中Adnroid内程序读取一个CSV文件并输入信息到一个SQLite数据库,并使用

I've made an Adnroid program in Eclipse that reads a csv file and inputs the info into an SQLite database, and using

dbCursor = database.query(DATABASE_TABLE, new String[]{KEY_ROWID, KEY_ITEMTYPE, KEY_QUANTITY},  null, null, null, null, null);  

    int iRow = dbCursor.getColumnIndex(KEY_ROWID);
    int iType = dbCursor.getColumnIndex(KEY_ITEMTYPE);
    int iQuantity = dbCursor.getColumnIndex(KEY_QUANTITY);

        for(dbCursor.moveToFirst(); !dbCursor.isAfterLast(); dbCursor.moveToNext()){
            allData = allData + " " + dbCursor.getString(iRow) + "\t " + dbCursor.getString(iType) + "\t\t\t " + dbCursor.getString(iQuantity) + "\n";      
        }

,然后在一个TextView盒打印出ALLDATA已经工作就好了。

and then printing out allData in a textview box has worked just fine.

然后我就想用

dbCursor = database.rawQuery("SELECT KEY_ROWID , SUM(KEY_ITEMTYPE) FROM DATABASE_TABLE GROUP BY KEY_ROWID", null);          
for(dbCursor.moveToFirst(); !dbCursor.isAfterLast(); dbCursor.moveToNext()){

    allDataSum = allDataSum + " " + dbCursor.getString(0);
} //I know this will probably not print what I want correctly but that's a problem for another day

当我尝试打印此我得到的错误10-25 22:06:35.016:I /数据库(1911年):sqlite的返回:错误code = 1,味精=没有这样的表:DATABASE_TABLE。

When I try to print this I get the error "10-25 22:06:35.016: I/Database(1911): sqlite returned: error code = 1, msg = no such table: DATABASE_TABLE".

然后我打开DDMS文件资源管理器和数据库复制到我的桌面,然后试图用一个命令工具查看数据库,但同样得到了一个错误,SQL错误:没有这样的表:库存

I then opened DDMS File Explorer and copied the database onto my desktop and then tried viewing the database with a command tool but again got an error, "SQL error: no such table: inventory".

模拟器怎么能告诉我什么,我想从.query看到()(而不是从.rawQuery)时,显然没有在数据库中没有表?关于我的一切使用查询和rawQuery是相同的,所以它不是不开放的rawQuery分贝或类似的东西的情况。

How can the emulator show me what I want to see from .query() (but not from .rawQuery) when apparently there is no table in the database? Everything about I use the query and rawQuery is identical, so it's not a case of not opening the db for rawQuery or something like that.

推荐答案

看来,你正在使用名为DATABASE_TABLE,KEY_ROWID一个静态变量,并包含您的实际名称KEY_ITEMTYPE。当您使用此与rawQuery,你必须做的。

It appears that you're using a static variables named DATABASE_TABLE, KEY_ROWID, and KEY_ITEMTYPE containing your actual names. When you use this with rawQuery, you'll have to do

dbCursor = database.rawQuery("SELECT " + KEY_ROWID + ", SUM(" + KEY_ITEMTYPE + ") FROM " + DATABASE_TABLE + " GROUP BY " + KEY_ROWID, null);

请注意,当你使用使查询 database.query 您不必在引号这些变量,这就是为什么它的工作原理。

Notice that when you make the query using database.query you don't have these variables in quotes, that's why it works.

这篇关于SQLite的"没有这样的表"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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