BIT COLUMN BUG

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
egrobler
Posts: 29
Joined: Mon 03 Dec 2012 14:35

BIT COLUMN BUG

Post by egrobler » Wed 11 Oct 2017 12:22

To whom it may concern

I have sqlite tables that were exported from MySQL with bit columns that indicates a boolean field.
My problem is that TLiteQuery maps BIT to a ftWideMemo type instead of ftBoolean or even ftInteger.
I am migrating my app to TLiteQuery from another library which does the mapping correctly.

Example:

Code: Select all

create table test(id integer primary key, myInt INT, myBool BIT);
insert into test(myInt, myBool) values (3, 1);

PRAGMA table_info(test);
  cid|name  |type   |notnull|dflt_value|pk|
    0|id    |integer|      0|Null      | 1|
    1|myInt |INT    |      0|Null      | 0|
    2|myBool|BIT    |      0|Null      | 0|


aQuery := TLiteQuery.Create;
aQuery.Connection := ..
aQuery.SQL.Text := 'select * from test';
aQuery.Open;

which returns:
id:   ftInteger
myInt:  ftInteger
myBool: ftWideMemo

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

Re: BIT COLUMN BUG

Post by MaximG » Thu 12 Oct 2017 09:11

In the case when LiteDAC cannot define the field type (in your sample, the 'myBool' field), it creates such fields with the Memo type. For this, in order for such fields to be created as Boolean, you can use DataTypeMapping - a special mechanism provided by LiteDAc components : https://www.devart.com/litedac/docs/?da ... apping.htm


In your case, the returned by the query value of the Memo type of the 'myBool' field can be converted to the Boolean type :

Code: Select all

uses LiteDataTypeMap;
….
LiteQuery.DataTypeMap.AddFieldNameRule('myBool', ftBoolean);

egrobler
Posts: 29
Joined: Mon 03 Dec 2012 14:35

Re: BIT COLUMN BUG

Post by egrobler » Thu 12 Oct 2017 11:29

DataTypeMapping is a clever implementation by you.
Thanks for the great support.

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

Re: BIT COLUMN BUG

Post by MaximG » Thu 12 Oct 2017 12:14

We are glad to see the problem resolved. Please don't hesitate to contact us with questions concerning LiteDAC usage.

egrobler
Posts: 29
Joined: Mon 03 Dec 2012 14:35

Re: BIT COLUMN BUG

Post by egrobler » Sun 15 Oct 2017 15:31

Hi MaximG,

Is it not possible to do something like:

Code: Select all

DataTypeMap.AddDBTypeRule('BIT', ftBoolean)
I would like a generic solution where I can map the type from the sqlite table schema.
(B.t.w you have no DataTypeMap documentation in the LiteDac help file)

Regards
Eric

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

Re: BIT COLUMN BUG

Post by MaximG » Wed 18 Oct 2017 09:14

According to our documentation, LiteDAC supports two types of DataTypeMapping rules : DB data types Rules and Rules for a particular field. To implement the required behavior, we proposed using the second variant. In turn, we will consider adding a possibility of working with the BIT type using the proposed method in the future. You can leave your suggestion at our UserVoice page (https://devart.uservoice.com/forums/104 ... 931-sqlite). We will implement this behavior, in case if the suggested feature is of interest to our users.

Post Reply