找回密码
 加入
搜索
查看: 2336|回复: 7

[AU3基础] SQLite中获得的中文无法正常显示

  [复制链接]
发表于 2015-5-7 15:33:30 | 显示全部楼层 |阅读模式
_SQLite_FetchData 从数据库中查询到的中文在autoit中显示乱码 这个有办法解决吗?
发表于 2015-5-7 15:51:02 | 显示全部楼层
回复 1# chiron_shen
没问题啊
发表于 2015-5-7 15:53:27 | 显示全部楼层
[au3]#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Global $edit

_Main()

Func _Main()

  Local $GUI, $hQuery, $aRow, $aNames

  $GUI = GUICreate("SQLite FetchData", 400, 260)
  $edit = GUICtrlCreateEdit("", 2, 2, 394, 256, BitOR($ES_READONLY, $ES_AUTOVSCROLL))
  GUISetState()

  _SQLite_Startup ()
  MemoWrite("_SQLite_LibVersion=" &_SQLite_LibVersion() & @CR)
  _SQLite_Open () ; 打开:内存:数据库
  _SQLite_Exec (-1, "CREATE table aTest (a,b,c);")
  _SQLite_Exec (-1, "INSERT INTO aTest(a,b,c) VALUES ('中','2','国');")
  _SQLite_Exec (-1, "INSERT INTO aTest(a,b,c) VALUES ('b','3',' ');")
  _SQLite_Exec (-1, "INSERT INTO aTest(a,b,c) VALUES ('a','1','Hello');")
  _SQlite_Query (-1, "SELECT ROWID,* FROM aTest ORDER BY a;", $hQuery)
  _SQLite_FetchNames ($hQuery, $aNames)
  MemoWrite(StringFormat(" %-10s  %-10s  %-10s  %-10s ", $aNames[0], $aNames[1], $aNames[2], $aNames[3]) & @CR)
  While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK ; 读出下一行
    MemoWrite(StringFormat(" %-10s  %-10s  %-10s  %-10s ", $aRow[0], $aRow[1], $aRow[2], $aRow[3]) & @CR)
  WEnd
  _SQLite_Exec (-1, "DROP table aTest;")
  _SQLite_Close ()
  _SQLite_Shutdown ()

  ; 循环至用户退出
  Do
  Until GUIGetMsg() = $GUI_EVENT_CLOSE
  GUIDelete()
EndFunc   ;==>_Main

Func memowrite($s_text)
  GUICtrlSetData($edit, $s_text & @CRLF, 1)
EndFunc   ;==>memowrite[/au3]
发表于 2015-5-7 15:53:31 | 显示全部楼层
[au3]#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Global $edit

_Main()

Func _Main()

  Local $GUI, $hQuery, $aRow, $aNames

  $GUI = GUICreate("SQLite FetchData", 400, 260)
  $edit = GUICtrlCreateEdit("", 2, 2, 394, 256, BitOR($ES_READONLY, $ES_AUTOVSCROLL))
  GUISetState()

  _SQLite_Startup ()
  MemoWrite("_SQLite_LibVersion=" &_SQLite_LibVersion() & @CR)
  _SQLite_Open () ; 打开:内存:数据库
  _SQLite_Exec (-1, "CREATE table aTest (a,b,c);")
  _SQLite_Exec (-1, "INSERT INTO aTest(a,b,c) VALUES ('中','2','国');")
  _SQLite_Exec (-1, "INSERT INTO aTest(a,b,c) VALUES ('b','3',' ');")
  _SQLite_Exec (-1, "INSERT INTO aTest(a,b,c) VALUES ('a','1','Hello');")
  _SQlite_Query (-1, "SELECT ROWID,* FROM aTest ORDER BY a;", $hQuery)
  _SQLite_FetchNames ($hQuery, $aNames)
  MemoWrite(StringFormat(" %-10s  %-10s  %-10s  %-10s ", $aNames[0], $aNames[1], $aNames[2], $aNames[3]) & @CR)
  While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK ; 读出下一行
    MemoWrite(StringFormat(" %-10s  %-10s  %-10s  %-10s ", $aRow[0], $aRow[1], $aRow[2], $aRow[3]) & @CR)
  WEnd
  _SQLite_Exec (-1, "DROP table aTest;")
  _SQLite_Close ()
  _SQLite_Shutdown ()

  ; 循环至用户退出
  Do
  Until GUIGetMsg() = $GUI_EVENT_CLOSE
  GUIDelete()
EndFunc   ;==>_Main

Func memowrite($s_text)
  GUICtrlSetData($edit, $s_text & @CRLF, 1)
EndFunc   ;==>memowrite[/au3]
发表于 2015-5-7 15:54:36 | 显示全部楼层
不对,你用的sqlite是什么版本
 楼主| 发表于 2015-5-7 16:13:05 | 显示全部楼层
谢谢你,我用的版本是3.8.9 看了你上面代码我验证了下,发现用autoit的函数写进去的中文是可以显示的,我一直不能显示的是在windows 命令模式下写入的中文 ,比如我用.import 导入一个csv文件中有中文,这时用autoit 获取出来就是乱码
发表于 2015-5-7 16:19:51 | 显示全部楼层
哦,那个需要转码,windows 命令行里的中文字没法直接用
发表于 2015-5-11 19:09:02 | 显示全部楼层
回复 6# chiron_shen
要用Unicode编码的UTF8。中文系统默认的是ANSI。直接是乱码。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-9 21:25 , Processed in 0.080821 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表