SQL.Text doesn't seem to be working in Delphi 10.3

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
SteveInIT
Posts: 9
Joined: Wed 22 Apr 2015 17:42

SQL.Text doesn't seem to be working in Delphi 10.3

Post by SteveInIT » Mon 17 Feb 2020 20:13

I have an import routine that sets up data in an array and loops to HiArr

On each loop it assigns the last name and first name like so...

ILName := ArrayofUser[x].LName; //ImportLastName
IFName := ArrayofUser[x].FName; //ImportFirstName

Now I need to see if the ILName and IFName already exist in the table.

**FADC is another unit that holds the tables in the project
**I prefix all TUniQuerys with UQ, so I know what they are (just telling for readability)

FADC.UQUserTBLTest.SQL.Clear;
FADC.UQUserTBLTest.SQL.Text := 'SELECT * from UserTBLTest WHERE UserLName = ' + ILName +
' AND UserFName = ' + IFName;
FADC.UQUserTBLTest.Open;

First record being imported from the array is ILName of 'Barr**', ILFName of 'Mary'

Debugger Exception is Project Inventory.exe raised exception classs EMSError with message 'Invalid column name 'Mary', Invalid Column name 'Barr**'.'.

Funny thing is I can do this earlier....

FADC.UQUserTBLTest.SQL.Text := 'SELECT * from UserTBLTest WHERE UserTypeIDNo = ' + InttoStr(UserTypeIDNo) +
' AND DistrictIDNo = ' + InttoStr(DistrictIDNo);

And get no "invalid column name" errors. Same format.

Anyone have a clue what I'm doing wrong?

Thanks!

SteveInIT
Posts: 9
Joined: Wed 22 Apr 2015 17:42

Re: SQL.Text doesn't seem to be working in Delphi 10.3

Post by SteveInIT » Mon 17 Feb 2020 22:41

Forgot to mention, I'm using MS SQL Server 2012

SteveInIT
Posts: 9
Joined: Wed 22 Apr 2015 17:42

Re: SQL.Text doesn't seem to be working in Delphi 10.3

Post by SteveInIT » Tue 18 Feb 2020 21:10

Ok, I finally got it.

Instead of what is in the original post, when working with the strings for the SQL.Text statement, you need to hyphenate as follows around the variables:

FADC.UQUserTBLTest.SQL.Text := 'SELECT * from UserTBLTest WHERE UserLName = ''' + ILName + ''' and UserFName = ''' + IFName +''''; // + '' + ILName + '' + ' AND UserFName = ' + '' + IFName + '';

SteveInIT
Posts: 9
Joined: Wed 22 Apr 2015 17:42

Re: SQL.Text doesn't seem to be working in Delphi 10.3

Post by SteveInIT » Tue 18 Feb 2020 21:14

I had some commented text in there....

Instead of what is in the original post, when working with the strings for the SQL.Text statement, you need to hyphenate as follows around the variables:

FADC.UQUserTBLTest.SQL.Text := 'SELECT * from UserTBLTest WHERE UserLName = ''' + ILName + ''' and UserFName = ''' + IFName +'''';

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: SQL.Text doesn't seem to be working in Delphi 10.3

Post by Stellar » Mon 24 Feb 2020 12:56

Glad to see that the issue was resolved.
Feel free to contact us if you have any further questions about our products.

Post Reply