SQLite.SQLiteAsyncConnection sqlConn = new SQLite.SQLiteAsyncConnection(db_Path, false); 
string sql = "SELECT * FROM test where name='中文'";
System.Threading.Tasks.Task<List<model.test>> UserTask = sqlConn.QueryAsync<model.test>(sql);
                 sqlite 进行中文查询含“中文”的时候报错。英语字母就可以。
错误为:SQLiteClient.SQLiteException: unrecognized token: "'中文的乱码'"
各位大侠 帮帮忙呀

解决方案 »

  1.   

    SQLite 默认的编码貌似和vs默认的编码不一样。
    还要如果如果“中文”2个字是你用你写的程序写入的,那么你这样查询读出是没问题的
    如果“中文”2个字是你用sqlite数据库管理软件录入,那么你这样查训就会出问题。
    反正是你不转换一致的编码的话
    sqlite的管理器看着正常的中文数据,VS看着就是乱的
      

  2.   

    谢谢了  我已经解决了  在 sqlite.cs 类中添加        [DllImport("sqlite3", EntryPoint = "sqlite3_prepare16_v2", CallingConvention = CallingConvention.Cdecl)]
            public static extern Result Prepare16_2(IntPtr db, [MarshalAs(UnmanagedType.LPWStr)] string sql, int numBytes, out IntPtr stmt, IntPtr pzTail);
    把默认的
                 public static IntPtr Prepare2 (IntPtr db, string query)
                {
           IntPtr stmt;
    var r = Prepare2 (db, query, query.Length, out stmt,    IntPtr.Zero);
    if (r != Result.OK) {
    throw SQLiteException.New (r, GetErrmsg (db));
    }
    return stmt;
         }改为
            public static IntPtr Prepare2(IntPtr db, string query)
            {
                IntPtr stmt;
                int num = System.Text.Encoding.Unicode.GetByteCount(query);
                var r = Prepare16_2(db, query, num, out stmt, IntPtr.Zero);
                if (r != Result.OK)
                {
                    throw SQLiteException.New(r, GetErrmsg(db));
                }
                return stmt;
            }