Delphi Firedac under the Sqlite (ix) about sorting

Source: Internet
Author: User
Tags integer sort sqlite

SQLite internal is sorted by binary, can support ANSI; FRIEDAC supports Unicode sorting through tfdsqlitecollation, and can customize the sort by its Oncompare event. The following example tests the difference between the two sorts.

You can quickly complete the form design by pasting the following code directly onto a blank form:Object Dbgrid1:tdbgrid left = 0 top = 0 Width = 297 Height = 199 Align = Alleft DataSource = DataSource1 Ta BOrder = 0 Titlefont.charset = Default_charset Titlefont.color = Clwindowtext titlefont.height = -11 TitleFont.Nam E = ' Tahoma ' Titlefont.style = [] End object Button1:tbutton left = 303 top = Width = Height = Capt Ion = ' SQLite ' #20869 #32622#25490#24207 taborder = 1 OnClick = Button1Click End Object Button2:tbutton left = 303 top = Width = Caption = ' Firedac ' #40664 #35748#25490#24207 taborder = 2 OnClick = button2cli CK End Object Fdconnection1:tfdconnection left = top =-end Object Fdphyssqlitedriverlink1:tfdphyssqlitedriverl Ink left = 143 top = "End Object Fdguixwaitcursor1:tfdguixwaitcursor" Provider = ' Forms ' left = the top = E nd object Fdquery1:tfdquery Connection = FDConnection1 left = top = The End object Datasource1:tdatasource Dat Aset = FDQuery1 left = 132 top = The End object Fdsqlitecollation1:tfdsqlitecollation driverlink = FDPhysSQLiteDriverLink1 CollationName = ' mycollation ' localename = ' zh-cn ' left = top =

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Delphi/

Code:

procedureTform1.formcreate (Sender:tobject);varI:integer; Lcode:integer;begin{Set parameters to FDSQLiteCollation1}
Fdsqlitecollation1.driverlink: = FDPhysSQLiteDriverLink1; Fdsqlitecollation1.collationkind: = sccomparestring; This is the default value (Unicode is case-insensitive, calling winapi.comparestring under Win);
  Use other options to customize the collation Fdsqlitecollation1.localename: = ' ZH-CN ';
  Fdsqlitecollation1.flags: = [Sfignorecase];     Fdsqlitecollation1.collationname: = ' mycollation ';

  All of the following calls depend on this name fdsqlitecollation1.active: = True;
FDCONNECTION1.PARAMS.ADD (' Driverid=sqlite '); FDCONNECTION1.PARAMS.ADD (' Openmode=createutf8 ');  This is the default value, optional CreateUTF16 (Unicode) {Create Test table, three fields str (kanji), code (Unicode value corresponding to Chinese characters), ID (add order)} fdconnection1.execsql (' Create
TABLE MyTable (str string (a), code integer, id integer); Fdconnection1.execsql (' CREATE TABLE MyTable (str string (a) COLLATE mycollation, code integer, id integer) '); Add test data data at table design time {} forI: = 0 to99Todo
  beginLcode: = Random ($9fa5-$4e00); Fdconnection1.execsql (' INSERT into MyTable (str, code, ID) VALUES (: 1,: 2,: 3) ', [Widechar ($4e00 + lcode), Lcode, i+1]); End; Fdquery1.open (' SELECT * from MyTable '); No sort End;procedureTform1.button1click (Sender:tobject);beginFdquery1.open (' SELECT * from MyTable ORDER by str '); SQLite built-in sort End;procedureTform1.button2click (Sender:tobject);beginFdquery1.open (' SELECT * from MyTable ORDER by str COLLATE mycollation '); Firedac default Sort End;

Test Effect Diagram:

Author:cnblogs in case

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.