【问题标题】:SQLite Syntax Error when it should not不应该出现的 SQLite 语法错误
【发布时间】:2012-07-19 17:56:53
【问题描述】:

在单点触控应用程序中,我正在使用此代码插入一个值:

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);

其中存储库是扩展 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 字符一起使用?

【问题讨论】:

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


    【解决方案1】:

    参数化查询解决了这个问题。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多