The official developer of SQLite has given a simple example, the address of this example is http://docwiki.embarcadero.com/RADStudio/XE4/en/IOS_Tutorial:_Using_SQLite_in_an_iOS_Application.
In this exampleDbexpressControls for database connection.DbexpressThis is not very useful, and I do not like it very much.
So I switched to Unidac and firedac to redo this demo, where firedac is a http://altd.embarcadero.com/download/radstudio/xe4/FireDAC_8.0.1.3279.exe, Unidac can be found in the box, here is not provided.
CodeIn fact, they are all similar and basically do not need to be modified. The problem with switching to the two controls is that Chinese characters are garbled and it takes a lot of time to share your experience with you. In addition, the SQLite files are not encrypted at present, and the two data controls with passwords cannot be connected. There is actually a way to solve the problem by adding a password to firedac. This control comes with an encrypted function. However, if you use the function encryption provided by it, the third-party management tool cannot be connected. It is very troublesome to remove the password every time you connect, my third-party management tools are SQLite expert professional 3 and navicat for SQLite. We recommend that you use SQLite expert professional to create a database. Otherwise, the encoding problem may be confusing.
Follow the official demo to create the corresponding database file. Remember to select Unicode as the encoding when creating the database. Otherwise, Chinese characters will be garbled. For Unidac
Select true for useunicode. In addition, all fields involved in the operation are of the widestring type. Otherwise, garbled characters will occur. A running Graph
For firedac, setting the stringformat attribute to Unicode takes some time to search for it. Then, the field operation is the same as before. The widestring type is used.
The code for adding a button is:
Procedure Tform2.btninsertclick (Sender: tobject ); VaR Shopitem: string; Begin Try If Inputquery ( ' Enter New shopitem ' , ' Shopitem ' , Shopitem) And Not (Shopitem. Trim = '' ) Then Begin Adqueryinsert. parambyname ( ' Shopitem ' ). Aswidestring: = Shopitem; adqueryinsert. execsql (); adtable1.refresh; linkfillcontroltofield1.bindlist. filllist; End ; Except T on E: exception Do Begin Showmessage (E. Message ); End ; End ; End ;
The widestring type is not a problem.