windows store apps开发使用SQLite-net 查询语句中文乱码问题
来源:互联网 发布:淘宝虚拟发布类目 编辑:程序博客网 时间:2024/04/30 16:38
查询英文又会出问题,正在解决中已解决
情况是这样:1.表名含有中文,或者查询条件含中文时,查询时会返回Unrecognized token +中文乱码
2.使用parameter时,不会将?替换
搜索了很久,大多数是教你怎么添加sqlite runtime for win8 插件,怎么添加sqlite-net驱动,千篇一律,中文的和老外的差不多
然后参考安卓对付乱码的方法,把字符串转为utf-8,还是不行,感觉本来字符就是utf-8的。
仔细思考,首先肯定不是查询语句的utf-8问题,其次不会是sqlite的问题,因为数据库是我在另一程序中用System.Data.Sqlite生成的,含中文表名,在SQLiteSpy中显示正常。
考虑可能是1.sqlite runtime for win8不支持中文 2.sqlite-net驱动问题
到了今天早上,不甘心又仔细搜索,终于找到了这篇帖子http://bbs.csdn.net/topics/390254870,找到了解决办法,看来还是我知识太浅,还要多加学习
下面把方法贴出来
在 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 = Prepare_2(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; }
0 0
- windows store apps开发使用SQLite-net 查询语句中文乱码问题
- Windows Store apps开发[3]应用程序栏(AppBar)的使用
- Windows Store apps开发[5]导航栏(AppBar)的使用
- Windows Store apps开发[29]使用Blend设计ButtonStyle
- Windows Store apps开发[47]使用默认程序打开文件
- Windows Store apps开发[48]MessageDialog的使用
- Windows Store apps开发[56]使用外部字体
- Windows Store apps开发[28]在Windows 8 Apps中通过C#使用Web Service
- Windows Store apps开发[22]Windows 8: WinRT中文件的正确读写方法
- Windows Store apps开发[25]Metro style apps改名为Windows Store apps
- Windows Store apps开发[1]平台简介
- Windows Store apps开发[13]应用程序生命周期
- Windows Store apps开发[44]AppBar总结
- Windows Store apps开发[49]自定义MessageDialog
- Windows Store apps开发[50]自定义Popup
- Windows Store apps开发[23]创建Windows Store应用程序包
- hibernate中文动态查询语句乱码问题
- hibernate中文动态查询语句乱码问题
- 继承
- 这段程序应该怎么改?
- 请问VC 如何实现 chrome浏览器 网页自动填表单
- ORACLE物化视图--物化视图日志如何避免系统时间变化带来的影响
- Android性能优化笔记
- windows store apps开发使用SQLite-net 查询语句中文乱码问题
- 冬季的一缕阳光从指尖悄悄滑过
- 软件开发模型(II)
- 图的最短路径-升级版
- 学习鸟哥的Linux私房菜笔记(4)——文件
- 《linux性能及调优指南》 3.3 内存瓶颈
- Delphi6中使用TADOConnection和TADQuery组件连接访问数据库总结
- Contents & Index
- iOS开发-mutating method sent to immutable object错误