SQLite语法错误,它不应该

时间:2012-07-20 12:44:05

标签: c# sqlite xamarin.ios syntax-error

在monotouch应用程序中,我使用此代码插入一个值:

string sql = "insert or ignore into [translation] values (\"7d8281e2-3f0d-4f51-a6bd-bf91af90dc4a\",\"113a1275-e7a0-452d-a1e1-9043c1139584\",\"1\",\"Gömlek\")";
var cmd = _repository.Execute(sql);

其中repository是扩展SQLiteConnection的类的实例。这个确切的语句在RazorSql中完全正常。但是当我用我的代码执行它时,它给了我:

SQLite.SQLiteException: near ""Gömlek"": syntax error
  at SQLite.SQLite3.Prepare2 (IntPtr db, System.String query) [0x0001b] in /Users/serhat/Projects/MyApp.Mobile/trunk/MyApp.Mobile.iOSApp/Database/SQLite.cs:1564
  at SQLite.SQLiteCommand.Prepare () [0x00000] in /Users/serhat/Projects/MyApp.Mobile/trunk/MyApp.Mobile.iOSApp/Database/SQLite.cs:1000
  at SQLite.SQLiteCommand.ExecuteNonQuery () [0x00022] in /Users/serhat/Projects/MyApp.Mobile/trunk/MyApp.Mobile.iOSApp/Database/SQLite.cs:903
  at SQLite.SQLiteConnection.Execute (System.String query, System.Object[] args) [0x00040] in /Users/serhat/Projects/MyApp.Mobile/trunk/MyApp.Mobile.iOSApp/Database/SQLite.cs:299
  at MyApp.Mobile.iOSApp.LevelImporter.ImportCsv (Int32 level) [0x000f6] in /Users/serhat/Projects/MyApp.Mobile/trunk/MyApp.Mobile.iOSApp/Service/LevelImporter.cs:117
  at MyApp.Mobile.iOSApp.LevelImporter.DownloadLevel (Int32 level) [0x0002a] in /Users/serhat/Projects/MyApp.Mobile/trunk/MyApp.Mobile.iOSApp/Service/LevelImporter.cs:61
  at MyApp.Mobile.iOSApp.LevelImporter+<StartDownloading>c__AnonStorey12.<>m__2C (System.Object ) [0x00000] in /Users/serhat/Projects/MyApp.Mobile/trunk/MyApp.Mobile.iOSApp/Service/LevelImporter.cs:49

并且异常实例不包含其他信息。我错过了什么?

编辑:我认为这与字母“ö”有关。当我用“o”替换它时,查询工作正常。如何使用unicode字符?

1 个答案:

答案 0 :(得分:0)

参数化查询解决了问题。

insert or ignore into [tablename] values (?,?,?,?,?)