Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Cannot use FieldByName on aliases with SQLite driver


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Nov 15, 2017 2:24 PM Last Post By: Manuel Bachmann Threads: [ Previous | Next ]
Manuel Bachmann

Posts: 2
Registered: 3/14/17
Cannot use FieldByName on aliases with SQLite driver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 12, 2017 6:27 AM
Hi folks,

I encounter the following problem when trying to use the Delphi dbExpress driver for SQLite :

TSQLQuery, which abstracts both the SQL request and its result, normally allows to refer to a result field by its column name, with the FieldByName method.

So if I, for instance, do my request this way :
 query.SQL.Text := 'select NAME, FNAME from PERSONS';
 query.Open;

I can later request the FNAME field directly by its name :
 fname := query.FieldByName('FNAME').AsString;


This works well, but the problem arises when defining aliases :
 query.SQL.Text := 'select NAME, FNAME as FIRSTNAME from PERSONS';
 query.Open;
 fname := query.FieldByName('FIRSTNAME').AsString;

Apparently the FIRSTNAME alias I defined for FNAME cannot be requested, as this throws an
exception :
 fname := query.FieldByName('FIRSTNAME').AsString;


Of course, this feature works well for other dbExpress drivers I used, such as the MySQL one.

Is this a bug ? A known limitation ? I tried the docs but they are very sparse.

(PS : here is a sample code if somebody wants to reproduce -tried it with Delphi 10.1 "Berlin" :
http://www.tarnyko.net/repo/SQLite3FieldByName_Bug.zip )
Manuel Bachmann

Posts: 2
Registered: 3/14/17
Re: Cannot use FieldByName on aliases with SQLite driver  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 15, 2017 2:24 PM   in response to: Manuel Bachmann in response to: Manuel Bachmann
Ok, got it. You have to do the following :
  connection.Params.Values['ColumnMetaDataSupported'] := 'False';

The value is True by default ; when True, only column original names -not their aliases- are returned.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02