1

I am trying the following query using a preloaded sqlite DB in a Monotouch project:

select * from my_table where id not in (1,2,3,4) and field not in ('תווים בעברית') order by RANDOM() limit 55;

but I keep getting a SQLiteException. If I replace the hebrew string with english characters it works fine.

How can I solve this issue?

Also notice that the same exact query works fine in an Android project (written in Java).

EDIT (Code)

var conn = new SQLiteConnection (System.IO.Path.Combine (folder, "mydb.db3"));

string sql = select * from my_table where id not in (1,2,3,4) and field not in ('תווים בעברית') order by RANDOM() limit 55;

IEnumerable<myObject> objects = conn.Query<myObject> (sql.ToString()); //Here is the exception

The Exception thrown:

SQLite.SQLiteException: near "lim": syntax error at SQLite.SQLite3.Prepare2 (IntPtr db, System.String query) [0x00000] in :0 at SQLite.SQLiteCommand.Prepare () [0x00000] in :0 at SQLite.SQLiteCommand+d_01[MyAppName.Question].MoveNext () [0x00000] in <filename unknown>:0 at System.Collections.Generic.List1[MyAppName.Question].AddEnumerable (IEnumerable1 enumerable) [0x00000] in <filename unknown>:0 at System.Collections.Generic.List1[MyAppName.Question]..ctor (IEnumerable1 collection) [0x00000] in <filename unknown>:0 at System.Linq.Enumerable.ToList[Question] (IEnumerable1 source) [0x00000] in :0 at SQLite.SQLiteCommand.ExecuteQuery[Question] () [0x00000] in :0 at SQLite.SQLiteConnection.Query[Question] (System.String query, System.Object[] args) [0x00000] in :0 at MyAppName.DBHelper.getQuestions (Int32 level) [0x000f1] in /Users/mmac/Documents/projects/MyAppNameMono/MyAppName/MyAppName/dal/DBHelper.cs:43 at MyAppName.AppDelegate.m_0 (System.Object ) [0x00002] in /Users/mmac/Documents/projects/MyAppNameMono/MyAppName/MyAppName/AppDelegate.cs:36

4

1 回答 1

1
near "lim": syntax error

此错误消息表明查询字符串的最后六个字符被截断,即 MonoTouch 没有正确计算字符串长度。

将此错误报告给 Xamarin,和/或尝试升级。

要解决此问题,请尝试将字符串值作为参数传递(首先这是避免格式问题和SQL 注入攻击的好主意):

string sql = "select ... field not in (?) ...";
string value = "תווים בעברית";
IEnumerable<myObject> objects = conn.Query<myObject>(sql, value);
于 2013-11-02T12:42:25.147 回答