Mixed fields with SQLite

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Juergen Bauer
Posts: 4
Joined: Fri 13 Jul 2018 09:54

Mixed fields with SQLite

Post by Juergen Bauer » Fri 13 Jul 2018 10:03

Hello,
I have a SQLite database which contains unicode (NVARCHAR, NTEXT) and non-unicode (VARCHAR, TEXT) fields.
Now I would like to access these fields as TStringField or TWideStringField - as required.
How can I archieve this?

When I set UseUnicode to True, all the fields are treated as UniCode fields.
When I set UseUnicode to False, all the fields are treated as non unicode fields.

Thanks for your support.

Bye,
Jürgen

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Mixed fields with SQLite

Post by MaximG » Tue 17 Jul 2018 06:58

That's true, the described behavior will be defined by the value of the UseUnicode property. However, you can change it for each field you are interested in separately using DataTypeMapping: https://www.devart.com/unidac/docs/data ... apping.htm

For example:

Code: Select all

           uses  LiteDataTypeMapUni;
           ...
           UniQuery.DataTypeMap.AddFieldNameRule('VARCHARFIELD', ftString, 1024);

           UniQuery.DataTypeMap.AddFieldNameRule('NVARCHARFIELD', ftWideString, 1024);
           

Juergen Bauer
Posts: 4
Joined: Fri 13 Jul 2018 09:54

Re: Mixed fields with SQLite

Post by Juergen Bauer » Tue 17 Jul 2018 07:33

With this mappings, I have to define the field size too. Which is not useable.

Why do not map NVARCHAR fields -> ftWideString
and VARCHAR field-> ftString
as defined in the database?

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Mixed fields with SQLite

Post by MaximG » Thu 19 Jul 2018 14:34

When adding the DataTypeMapping rule, you do not need to explicitly set the field size value. In this case, the size of the created test field will be determined by the value specified in the DB when it is created. For example, for the TESTTABLE table (

Code: Select all

CREATE TABLE TESTTABLE (NAME VARCHAR(38)) 
), you can specify the following rule:

Code: Select all

UniQuery.DataTypeMap.AddFieldNameRule('NAME', ftString);
In this case, the size of the created field of ftString type will equal 38

Post Reply