Monotouch - sqlite和希伯来字符

时间:2013-11-01 20:43:02

标签: sqlite xamarin.ios

我在Monotouch项目中使用预加载的sqlite DB尝试以下查询:

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

但我不断收到SQLiteException。如果我用英文字符替换希伯来字符串,它可以正常工作。

我该如何解决这个问题?

另请注意,相同的查询在Android项目(用Java编写)中工作正常。

编辑(代码)

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

抛出异常:

  

SQLite.SQLiteException:near“lim”:语法错误     在SQLite.SQLite3.Prepare2(IntPtr db,System.String查询)[0x00000] in:0     在SQLite.SQLiteCommand.Prepare()[0x00000]中:0     在SQLite.SQLiteCommand + d_ 0 1[MyAppName.Question].MoveNext () [0x00000] in <filename unknown>:0 at System.Collections.Generic.List 1 [MyAppName.Question] .AddEnumerable(IEnumerable 1 enumerable) [0x00000] in <filename unknown>:0 at System.Collections.Generic.List 1 [MyAppName.Question] .. ctor(IEnumerable 1 collection) [0x00000] in <filename unknown>:0 at System.Linq.Enumerable.ToList[Question] (IEnumerable 1 source)[ 0x00000] in:0     在SQLite.SQLiteCommand.ExecuteQuery [Question]()[0x00000] in:0     在SQLite.SQLiteConnection.Query [问题](System.String查询,System.Object [] args)[0x00000] in:0     在/Users/mmac/Documents/projects/MyAppNameMono/MyAppName/MyAppName/dal/DBHelper.cs:43中的MyAppName.DBHelper.getQuestions(Int32级别)[0x000f1]     在/Users/mmac/Documents/projects/MyAppNameMono/MyAppName/MyAppName/AppDelegate.cs:36

中的MyAppName.AppDelegate.m _0(System.Object)[0x00002]

1 个答案:

答案 0 :(得分:1)

near "lim": syntax error

此错误消息表示查询字符串的最后六个字符被切断,即MonoTouch无法正确计算字符串长度。

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

要解决此问题,请尝试将字符串值作为参数传递(这首先是一个好主意,以避免格式化问题和SQL injection attacks):

string sql = "select ... field not in (?) ...";
string value = "תווים בעברית";
IEnumerable<myObject> objects = conn.Query<myObject>(sql, value);