SQLite string field instead of float

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Andrey
Posts: 6
Joined: Sun 14 Nov 2010 19:27

SQLite string field instead of float

Post by Andrey » Wed 24 Nov 2010 20:38

I use SQLite database and some tables there with Float fields.
If i use just fields from tables - they are treated normally - as Float fields, but if i use them in some formula (like field1 * field2 or SUM(field1) ) UniDAC treats result as String field (Even if i cast result as float).

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Thu 25 Nov 2010 08:37

Hello,

Thank you for the information.
We have reproduced the problem.
We will notify you as soon as we have any results.

bork
Devart Team
Posts: 649
Joined: Fri 12 Mar 2010 07:55

Post by bork » Wed 01 Dec 2010 12:41

Hello

We have checked this issue thoroughly. It seems like SQLite returns invalid data type for the column. I found the following information on the SQLite site:

http://www.sqlite.org/c3ref/column_blob.html:
The sqlite3_column_type() routine returns the datatype code for the initial data type of the result column. The returned value is one of SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB, or SQLITE_NULL. The value returned by sqlite3_column_type() is only meaningful if no type conversions have occurred as described below. After a type conversion, the value returned by sqlite3_column_type() is undefined. Future versions of SQLite may change the behavior of sqlite3_column_type() following a type conversion.
So we should wait for the sqlite3_column_type function to be fixed.

Andrey
Posts: 6
Joined: Sun 14 Nov 2010 19:27

Post by Andrey » Sun 05 Dec 2010 22:36

Are you sure that there is no other workaround? Because tools like Firefox SQLite Manager addon (https://addons.mozilla.org/en-US/firefox/addon/5817/) and SQLiteman (http://sqliteman.com/) treats such fields correctly.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Mon 06 Dec 2010 14:21

Hello,


We can't implement the kind of behavior the application you gave as an example has, because DataSet in Delphi should have only one type for a column, and we can't change it. In Delphi it is not allowed to change data type for a field in the column for each row, but as you can see, for example, in the SQLite Manager plugin, on the following data you get different data types in one column:

CREATE TABLE TEST (
ID INTEGER NOT NULL,
FLOAT1 FLOAT,
FLOAT2 FLOAT)

INSERT INTO TEST(ID) VALUES(1);
INSERT INTO TEST(ID, FLOAT1, FLOAT2) VALUES(2,2.3,1.2);

SELECT t.*, SUM(t.float1+t.float2) from test t group by t.id

so the fields FLOAT1 and FLOAT2 will be of string (ID=1) and float (ID=2) data types correspondingly, the 'SUM' fields will be of integer and float data types as well.

Post Reply