Value of SQLITE Sum Is TWideStringField?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
TinTin
Posts: 46
Joined: Sat 30 May 2009 14:09

Value of SQLITE Sum Is TWideStringField?

Post by TinTin » Mon 04 Apr 2011 03:48

I have 2 tables,it is master-detail Relation,they have a Float Field( Name is AMT,meaning is Amount ).
for example,the Sql is

select A.*, iFNull( (Select Sum(B.AMT) from F_LoanSub B Where B.LoanID = A.ID),0.00) As AMT2 from F_Loan A

Whether or not Using "IFNULL", "AM2 " Field In The UniQuery Is TWideStringField. If Table F_LoanSubSo Have No Data To Match Master Table ,It raise Error "

qryBase:Type Missing for Field "AMT2",expecting: Widestring actual: Float ".
I try modify SQL for Cast AM2 Field to Real,BUT IT Still error!

how to solve this problem? Thanks!

develop environment:
delphi xe+unidac(3.60.0.16)+sqlite expert,AMT Field is Float Type!

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

Post by AlexP » Mon 04 Apr 2011 09:12

Hello,

The problem is connected with thefact that DataSet in Delphi should have only one type for a column, and we can't change it.
If the float field in SQLite is empty, its type is string. If it is not empty, the type of this field is float.

You can try to add AMT2 field as a float field to your DataSet manually.

TinTin
Posts: 46
Joined: Sat 30 May 2009 14:09

Post by TinTin » Mon 04 Apr 2011 12:02

I have Sent sample to [email protected],Please Use my Sqlite3.dll AND SQLITE DB.

Thanks !

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

Post by AlexP » Mon 04 Apr 2011 15:09

Hello,

As I wrote you earlier, the problem is connected with the SQLLite behaviour, and you should contact to SQLite developers.

TinTin
Posts: 46
Joined: Sat 30 May 2009 14:09

Post by TinTin » Mon 04 Apr 2011 15:10

If I add All Field in designTime or Create Calc Field in Run Time,It raise error:Expect TWidestringField Actual TFloatField . But if dont do that,it runs normal:TFloatField!

TinTin
Posts: 46
Joined: Sat 30 May 2009 14:09

Post by TinTin » Mon 04 Apr 2011 15:19

I both love SQLITE and hate it. Sometimes it feels Eggs-pain!

PlutoPlanet
Posts: 10
Joined: Tue 28 Aug 2007 08:08

Re: Value of SQLITE Sum Is TWideStringField?

Post by PlutoPlanet » Fri 14 Jul 2017 08:21

A workaround for this issue is to add the typename within the SQL statement:
"<colname>::<typename>"

Example:

Code: Select all

SELECT count(*) as "mycnt::INT" FROM mytable

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

Re: Value of SQLITE Sum Is TWideStringField?

Post by MaximG » Fri 14 Jul 2017 09:54

The provided syntax ("mycnt :: INT") is not applicable when using SQLite. UniDAC allows obtaining the required type result by using Data Type Mapping : when using the

Code: Select all

SELECT count(*) as mycnt FROM mytable
query, you can get data as an integer value using the following rule:

Code: Select all

UniQuery.DataTypeMap.AddFieldNameRule ('mycnt', ftInteger);

Post Reply