DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: tkzcol
今日帖子: 4
在线用户: 1
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 ljc8794 (ljc) ★☆☆☆☆ -
普通会员
2022/4/2 11:11:46
标题:
delphi11下fd连接sqlit,用FDSQLiteCollation1Compare实现自定义排序 浏览:1019
加入我的收藏
楼主: FDSQLiteCollation1Compare(ASender: TObject; len1: Integer;
  str1: Pointer; len2: Integer; str2: Pointer; var AResult: Integer);

这个方法哪位高手解释下怎么用啊
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/4/2 11:32:52
1楼: https://www.sqlite.org/datatype3.html#collation

https://docwiki.embarcadero.com/Libraries/Sydney/en/FireDAC.Phys.SQLite.TFDSQLiteCollation


https://docwiki.embarcadero.com/RADStudio/Sydney/en/Using_SQLite_with_FireDAC

Custom Collations
SQLite stores and handles all character data either in UTF8 or UTF16, depending on the OpenMode connection parameter. When SQLite needs to compare or sort a character data, it has to know what rules to use for this. The rules are known as a collation.

SQLite has several build-in collations. None of them produces a correct sorting for German, Cyrillic, Arabian, and so on phrases. You have to use the TFDSQLiteCollation component to build your own collation. Set CollationName, Flags, LocaleName, then set Active to True to register the collation with the SQLite engine. For example:

FDSQLiteCollation1.DriverLink := FDPhysSQLiteDriverLink1;
FDSQLiteCollation1.CollationName := 'UTF16NoCase';
FDSQLiteCollation1.Flags := [sfIgnoreCase];
FDSQLiteCollation1.Active := True;
The component setup above with default Collation_Kind=scCompareString implements a standard case-insensitive Unicode collation. The application can implement custom collations using Collation_Kind=scCustomUTF16 or scCustomUTF8 and implementing the OnCompare event handler. This is how you can use this collation:

SELECT * FROM "Employees" ORDER BY LastName COLLATE UTF16NoCase
To specify the default collation for a column you can do the following:

CREATE TABLE IF NOT EXISTS test_col (f1 VARCHAR(10) COLLATE UTF16NoCase)
Note: If there is no ability to specify the default collation for a connection, a database, or a table. You can find the above collation samples in the FireDAC\Samples\DBMS Specific\SQLite\UserCollation folder.
If you do not use custom collations, then by default SQLite uses a binary sorting order. For the TFDTable Live Data Window mode, it is important to have the same client side and database sorting orders. To enable client side binary sorting order, set FormatOptions.SortLocale to 0.
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 sail2000 (小帆工作室) ★☆☆☆☆ -
盒子活跃会员
2022/4/2 17:06:46
2楼: 建议在取数据时用 SQL 语句排
----------------------------------------------
delphi 是兴趣,和工作无关,即使它倒闭。又不靠它 delphi 吃饭,怕甚?
作者:
男 yookee (yookee) ★☆☆☆☆ -
盒子活跃会员
2022/4/2 20:36:22
3楼: 比如说
界面上放TFDSQLiteCollation控件,其DriverLink属性指向TFDPhysSQLiteDriverLink控件
然后
FDSC1.LocaleName := 'zh-CN';
FDSC1.Flags := [sfIgnoreCase];
FDSC1.CollationName := 'MC';
FDSC1.Active := True;
查询时
'SELECT * FROM TABLE1 COLLATE MC ORDER BY NAME'
实现NAME列按拼音排序
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行70.3125毫秒 RSS