Using CASE statement in a SELECT

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Ken McClain
Posts: 12
Joined: Fri 20 Jan 2006 17:44

Using CASE statement in a SELECT

Post by Ken McClain » Mon 19 Aug 2013 14:39

I'm having a problem getting the data from the following SQL CASE statement to show
properly in a TDBGrid:

SELECT Stamp,CatID,
(CASE WHEN CatID = 0 THEN 'Info'
WHEN CatID = 1 THEN 'Warning'
WHEN CatID = 2 THEN 'Error'
WHEN CatID = 3 THEN 'Debug'
END) AS Category,
Message
FROM LogEntries

Problem: The newly created field 'Category' displays '(MEMO)' for its data
rather than the text.

Displays properly when run using 'SQLite Expert'

Any ideas?
Thanks

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

Re: Using CASE statement in a SELECT

Post by AlexP » Mon 19 Aug 2013 14:47

Hello,

When using the CASE construction,aggregate functions, etc., SQLite returns field type as Unknown, since it cannot define the result field type, therefore we map such fields as TMemoField. To solve the problem, you can use the Data Type Mapping technology in order to explicitly specify the type, to which such fields should be mapped for DataSet

Ken McClain
Posts: 12
Joined: Fri 20 Jan 2006 17:44

Re: Using CASE statement in a SELECT

Post by Ken McClain » Mon 19 Aug 2013 18:45

Thank you. That did it.

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

Re: Using CASE statement in a SELECT

Post by AlexP » Tue 20 Aug 2013 07:06

Hello,

Glad to see that the problem was solved. If you have any other questions, feel free to contact us.

Post Reply