chiron_shen 发表于 2015-5-7 15:33:30

SQLite中获得的中文无法正常显示

_SQLite_FetchData 从数据库中查询到的中文在autoit中显示乱码 这个有办法解决吗?

netegg 发表于 2015-5-7 15:51:02

回复 1# chiron_shen
没问题啊

netegg 发表于 2015-5-7 15:53:27

#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, $aNames, $aNames, $aNames) & @CR)
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK ; 读出下一行
    MemoWrite(StringFormat(" %-10s%-10s%-10s%-10s ", $aRow, $aRow, $aRow, $aRow) & @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

netegg 发表于 2015-5-7 15:53:31

#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, $aNames, $aNames, $aNames) & @CR)
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK ; 读出下一行
    MemoWrite(StringFormat(" %-10s%-10s%-10s%-10s ", $aRow, $aRow, $aRow, $aRow) & @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

netegg 发表于 2015-5-7 15:54:36

不对,你用的sqlite是什么版本

chiron_shen 发表于 2015-5-7 16:13:05

谢谢你,我用的版本是3.8.9 看了你上面代码我验证了下,发现用autoit的函数写进去的中文是可以显示的,我一直不能显示的是在windows 命令模式下写入的中文 ,比如我用.import 导入一个csv文件中有中文,这时用autoit 获取出来就是乱码

netegg 发表于 2015-5-7 16:19:51

哦,那个需要转码,windows 命令行里的中文字没法直接用

caianhua1986 发表于 2015-5-11 19:09:02

回复 6# chiron_shen
要用Unicode编码的UTF8。中文系统默认的是ANSI。直接是乱码。
页: [1]
查看完整版本: SQLite中获得的中文无法正常显示