Page 1 of 1

BIT COLUMN BUG

Posted: Wed 11 Oct 2017 12:22
by egrobler
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

Re: BIT COLUMN BUG

Posted: Thu 12 Oct 2017 09:11
by MaximG
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);

Re: BIT COLUMN BUG

Posted: Thu 12 Oct 2017 11:29
by egrobler
DataTypeMapping is a clever implementation by you.
Thanks for the great support.

Re: BIT COLUMN BUG

Posted: Thu 12 Oct 2017 12:14
by MaximG
We are glad to see the problem resolved. Please don't hesitate to contact us with questions concerning LiteDAC usage.

Re: BIT COLUMN BUG

Posted: Sun 15 Oct 2017 15:31
by egrobler
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

Re: BIT COLUMN BUG

Posted: Wed 18 Oct 2017 09:14
by MaximG
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.