在SQLiteDatabase.rawQuery字符串编码错误 [英] String encoding error in SQLiteDatabase.rawQuery
问题描述
我建立一个SQLite查询作为字符串
与的String.format
并将它传递给 SQLiteDatabase.rawQuery
。我通过在最后的整型参数是很难coded到零(我在寻找任何大于零的值)。这在我所有的测试工作正常,但我发现从外地崩溃报告。我使用的崩溃报告的网站,不给我详细的系统/环境的信息。这里是code,它崩溃:
I am building a SQLite query as a String
with String.format
and passing it to SQLiteDatabase.rawQuery
. The integer parameter I'm passing at the end is hard coded to zero (I'm looking for any value greater than zero). This works normally in all my testing, but I'm getting crash reports from the field. I'm using a crash reporting website that does not give me detailed system/environment information. Here is the code that is crashing:
String query = String.format("SELECT * FROM %s WHERE %s > %d",
TableName,
ColumnName,
0);
Cursor c = db.rawQuery(query, null);
被抛出例外的是以下内容:
The exception being thrown is the following:
android.database.sqlite.SQLiteException: no such column: Û°: , while
compiling: SELECT * FROM TableName WHERE ColumnName > Û°
和最后几行的堆栈跟踪飞机坠毁前是:
And the last few lines in the stack trace before the crash are:
SQLiteCompiledSql.java:-2:in android.database.sqlite.SQLiteCompiledSql.native_compile
SQLiteCompiledSql.java:68:in android.database.sqlite.SQLiteCompiledSql.<init>
SQLiteProgram.java:143:in android.database.sqlite.SQLiteProgram.compileSql
这看起来像它必须是一个编码错误。但是,我不知道怎么跟这个是什么原因。我使用 SQLiteOpenHelper
作为一个高层次的方式来创建并连接到我的数据库,所以我不会明确设置编码。此外,错误报告是少数,但他们来到这里仅仅在运行ICS的设备,所以它可能是这是在ICS中SQLite的类中使用默认设置一些新的东西。
This looks like it must be an encoding error. However, I don't know how to tell what is the cause of this. I'm using SQLiteOpenHelper
as a high level way to create and connect to my database, so I'm not explicitly setting an encoding. Also, the error reports are few but they've only come in on devices running ICS, so it's possible that this is something new in the defaults used in the SQLite classes in ICS.
推荐答案
我同意查询
,而不是 rawQuery
是一个更好的解决方案,但的String.Format()
有选择的区域设置的形式。不使用这种咬我在几个类似的情况:
I agree that query
rather than rawQuery
is a better solution, but String.Format()
has a form that selects the locale. Not using this has bitten me in a few similar circumstances:
String query = String.format(Locale.US,
"SELECT * FROM %s WHERE %s > %d",
TableName,
ColumnName,
0);
这篇关于在SQLiteDatabase.rawQuery字符串编码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!