UniDAC AddWhere procedure error!

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ibdac1pro
Posts: 48
Joined: Fri 25 Aug 2006 02:19

UniDAC AddWhere procedure error!

Post by ibdac1pro » Wed 03 Nov 2010 01:17

UniDAC AddWhere procedure error occurrence!

Source code example.
.....
UniQuery1.AddWhere(' Field_Name LIKE '''+Edit1.Text+'%'' ');
.....

When execution error occurrence.
"Column name 'Field_Name' incorrect."

In use UniDac latest version(3.5).

Please test and reply.

halenpolen
Posts: 31
Joined: Sun 27 Jun 2010 20:50

Re: UniDAC AddWhere procedure error!

Post by halenpolen » Wed 03 Nov 2010 07:43

ibdac1pro wrote:UniDAC AddWhere procedure error occurrence!

Source code example.
.....
UniQuery1.AddWhere(' Field_Name LIKE '''+Edit1.Text+'%'' ');
.....

When execution error occurrence.
"Column name 'Field_Name' incorrect."

In use UniDac latest version(3.5).

Please test and reply.
Make sure there is column Field_Name in your table . I tried it, no error.

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

Post by AlexP » Wed 03 Nov 2010 07:59

Hello,

I can not reproduce the problem.
Please specify your database name and version.
Check that the "Field_Name" column really exists in the table.
Also please set the TUniQuery.Debug property to true (you should add the UniDACVcl unit to the uses clause of any unit in your project to make the Debug property work) and check the query text after execution.

ibdac1pro
Posts: 48
Joined: Fri 25 Aug 2006 02:19

Post by ibdac1pro » Wed 03 Nov 2010 09:04

DataBase Name: Sql Server 2008 SP2

Really Table and Query(SQL) Text.
-------------------------------------------------------------------
WITH GetItemSum ( ItemSeq, ATOT, QTOT )
AS ( SELECT B.ItemSeq,
ISNULL(SUM(B.DomAmt), 0) ATOT,
ISNULL(SUM(B.Qty), 0) QTOT
FROM _TSLInvoice A
JOIN _TSLInvoiceItem B ON A.CompanySeq = B.CompanySeq
AND A.InvoiceSeq = B.InvoiceSeq
WHERE A.CompanySeq = 1
AND A.InvoiceDate BETWEEN '20070101' and '20070531'
GROUP BY B.ItemSeq )
SELECT A.*, B.ItemNo, B.ItemName
FROM GetItemSum A
JOIN _TDAItem B ON A.ItemSeq = B.ItemSeq
AND B.CompanySeq = 1
-------------------------------------------------------------------

Program source.
AddWhere(' B.ItemName LIKE '''+Item.Text+'%'' '); ==> Error
AddWhere(' B.ItemNo LIKE '''+Item.Text+'%'' '); ==> Error
Unrecognized field : 'B.ItemName', 'B.ItemNo'

AddWhere(' A.ItemSeq LIKE '''+Item.Text+'%'' '); ==> No Error
AddWhere(' A.QTOT > 0 '); ==> No Error
Recognized field : 'A.ItemSeq', 'A.QTOT'

I'm used WITH statement.

Testing under WITH statement.

Please test and replay.

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

Post by AlexP » Wed 03 Nov 2010 10:45

Hello,


This problem is connected with the fact that the AddWhere method inserts the WHERE statement into the first found SELECT clause.
If you want to use the AddWhere method you should rewrite your query so that it becomes a 'simple' query without the WITH statement, or you can use parameters in the query like

.......
SELECT A.*, B.ItemNo, B.ItemName
FROM GetItemSum A
JOIN _TDAItem B ON A.ItemSeq = B.ItemSeq
WHERE PATINDEX(:param, B.ItemName)>0

UniQuery.ParamByName('param').asString := Item.Text+'%'

Post Reply