DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: laidabin
今日帖子: 0
在线用户: 4
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/4/24 13:40:13
标题:
再次呼叫emailx45大师,fmxlinux里 sqlite数据库中文乱字符 浏览:1672
加入我的收藏
楼主: 首先谢谢大师热心帮助。有个这样的问题请教您:
1、用sqlite expert创建一个空的数据库,encoding编码选择utf-8。
现在使用FDBatchMove1,从一个老旧的数据库(sybase asa 8)将数据导入到该数据库中。数据能在sqlite expert能正常打开,数据显示正常。
2、使用fmxlinux创建一个linux程序(ubuntu),用firedac连接该sqlite数据库,再用fdquery打开表,显示中文为乱字符,英文和数据显示正常。
3、使用 FDQuery1.SaveToFile('test.json',sfJSON);将数据导出为json文件,打开json,文件里中文显示正常。
然后使用 FDQuery2.LoadFromFile('test.json',sfJSON);导入数据,中文仍然为乱字符。
4、删除表中所有数据,在linux里手动录入数据,使用 FDQuery1.SaveToFile('test.json',sfJSON);将数据导出为json文件,然后使用 FDQuery2.LoadFromFile('test.json',sfJSON);导入数据,中文显示正常。
百思不得其解,恳请大师指导,谢谢!!!
----------------------------------------------
-
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2022/4/24 14:03:08
1楼: 1. 你的原始数据库的中文,是什么编码?

2. 你的 FdQuery 里面对应的字段,是什么类型?TStringField 还是 TWideStringField

3. 排除导入数据的错误可能,你自己创建的数据库,在 FmLinux 的程序里面,自己输入中文数据,然后再显示,会如何?

排除问题,要逐个环节来。你现在好几个环节没分开,很难查验问题在哪个环节。
----------------------------------------------
-
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/4/24 14:31:02
2楼: 楼上大师,我已经说了:
4、删除表中所有数据,在linux里手动录入数据,使用 FDQuery1.SaveToFile('test.json',sfJSON);将数据导出为json文件,然后使用 FDQuery2.LoadFromFile('test.json',sfJSON);导入数据,中文显示正常。
也就是在linux里录入数据是正常的,导入导出也是正常的。
----------------------------------------------
-
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2022/4/24 15:52:29
3楼: 楼上,你手动录入数据,显示正常,就行了。

你加上一个导出 Json 再导入,又是多此一举了。又多了一个环节。那谁知道坏了或者好了,是哪个环节导致的?

就好比发烧了,有10种药,一把吃下去,病好了,没办法知道是哪个药有用。

一样一样的来,才好判断。

----------
如果你的程序,运行时,手动录入的数据,保存进数据库,下次打开,从数据库里面读出来的数据显示正常,说明:1. 数据库没问题;2. 程序没问题。

那么,自然就是导入的数据的原始数据有问题了。
----------------------------------------------
-
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2022/4/24 16:47:08
4楼: 用delphi 写入的sqlite 中文.
在java, php上都读取乱码,  反之亦然.. 

原因不明, 官方也不修复.. 经理让我保存中文时用base64, 突然我觉得太牛B了.
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
男 sunway0112 (ws) ★☆☆☆☆ -
普通会员
2022/4/24 17:06:10
5楼: 用UNIDAC试试
----------------------------------------------
-
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2022/4/24 19:52:31
6楼: 我用 Delphi 在 SQLite 里面读写中文都没有问题啊。

唯一需要注意的是:
1. SQLITE 采样 UTF8;
2. SQLITE 里面的字段用 NVarChar,不要用 VarChar;
3. 对应上述字段类型,Delphi 的 DataSet 里面的 Field 是 TWideStringField 而不是 TStringField;

其实,如果是中文的 WINDOWS,上述注意事项不用理会也不会有问题。但如果用其它系统,系统语言又可能不是中文,就要注意。
----------------------------------------------
-
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/4/24 20:47:52
7楼: 楼上,我也很奇怪。新建的sqlite是utf8的,然后从一个老数据库导入数据。然后用fmx编译一个程序管理这个数据库。
1、数据库一切正常,无论在windows下用sqlite expert查看,还是在linux(ubuntu、kylinx)下用sqlite dbbrowser查看都正常,而且均显示数据库字符编码是utf8。
2、如果我把程序编译为win32,一切正常。
3、如果我把程序编译为linux x86,所有中文显示乱字符。如果我在linux里录入新的数据,则同一个表内,原始中文数据是乱字符,新录入的数据是正常。
----------------------------------------------
-
作者:
男 nevergrief (孤独骑士) ★☆☆☆☆ -
盒子活跃会员
2022/4/24 21:36:05
8楼: to 步惊云,你导入数据的时候,要执行语句设置utf8编码之类的语句,然后再导入。估计导入工具提供这样的功能。
----------------------------------------------
只有偏执狂才能生存!
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/4/24 22:06:45
9楼: 数据库没有任何问题,因为可以在linux用db.browser查看所有数据。
----------------------------------------------
-
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/4/24 22:30:19
10楼: 终于搞好了,原来是连接参数中的字符表示类型要设为unicode。

第一千万次雄辩地证明,出错了,99.999%是我错了,delphi错不到0.001。
伟大的delphi。
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/4/25 0:19:00
11楼: you can try this sample: no code it's necessary!

or use "MAP" options in FDConnection to convert AUTOMATICALLY a SourceType on Database, to TartgetType:

Ex.  Integer to Int64, Ansi-type to Unicode-type (char(20) to VarChar)

note: normally you can try with many possibilities to avoid wrong data at end. ... tests... tests... tests...

good luck
此帖子包含附件:
PNG 图像
大小:138.1K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/4/25 0:22:47
12楼: liveBinding...
此帖子包含附件:
PNG 图像
大小:21.4K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/4/25 0:33:12
13楼: ADD-ON:

You can use "FDConnection" option SQLiteAdvanced... to add some SQLite parametrization according with your SQLite DLL version...
see on SQLite site about what's used!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/4/25 0:42:45
14楼: exporting by BatchMove
此帖子包含附件:
PNG 图像
大小:89.3K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/4/25 3:05:58
15楼: ubuntu 20
此帖子包含附件:
PNG 图像
大小:868.8K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/4/25 8:39:59
16楼: 谢谢emailx45。用batchmove可以成功地在不同数据库间迁移数据,但会丢失主键和外键,而且表名全部变成大写,不知道怎么解决。
另外,怎么为s已经有数据的sqlite数据库设置密码?
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/4/25 10:59:52
17楼: I'm not user of "SQLite" database, then, it's better study about it. OK?
try on HELP from RAD Studio or on SQLite official site
https://docwiki.embarcadero.com/RADStudio/Sydney/en/Using_SQLite_with_FireDAC

you can use "BatchMove" to create a target table, instead a text file... as in my example:

----------
Note: you can use another fDQuery/Table/Dataset to insert the records-resulted directally!
if you use another database, then, you can use another FDConnection + FDQuery to other database+table
if you use same database (in and out) then, you need just another FDQuery to another table reference!

you can create a second table in your database or another database SQLite and use it as your "target" to 
"FDBatchMoveDataSetWriter1.Dataset = ???"
----------

--BatchMove ---> ReadDataset  ---> WriteDataset components!!!
ex.:
FDBatchMove1
FDBatchMoveDataSetReader1  == FDQuery1  <--- source
FDBatchMoveDataSetWriter1  == FDMemTable or FDQuery2, FDTable...<-- target

using a FDMemtable for tests:
FDBatchMoveDataSetReader1.Dataset = MyFDQuerySourceDatas
FDBatchMoveDataSetWriter1.Dataset = MyFDMemtableTarget
...
//FireDAC.Comp.BatchMove.TFDBatchMove.Execute
if FDBatchMove.Execute > 0 then
... FDMemtable.SaveFile('myData.FDS');


FDMemtable.LoadFromFile('myData.FDS'); // fields = fields in FDQuerySource
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行103.0273毫秒 RSS