Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread Database.LoadRows using Params !
Tue, Apr 12 2016 4:51 PMPermanent Link

kamran

Hi

I have the following code:

1. SQL Query:
select * from model where make_description like '%'+{make_description=''}+'%'

2. EWB Code:
field "make_description" is in table "model"
field "make_description" is in table "make"

After selecting make_description it is assigned to the make string
and then passed to the code below for filtering.

So the  Database.LoadRows should only show models that belong to the make.

 fNewCar_M.WL_Model.Close;
 fNewCar_M.WL_Model.Params.Clear;
 fNewCar_M.WL_Model.Params.Add('make_description =''%' + make + '%''');
 Database.LoadRows(fNewCar_M.WL_Model);

The Database.LoadRows is returning all rows (I think meaning that there is a problem with the params declarations)

So I can't work out what I am doing wrong here..

Many thanks


Kamran
Tue, Apr 12 2016 8:16 PMPermanent Link

Richard Harding

Wise Nutrition Coaching

Hi Kamran

Define the SQL query as

select * from model where make_description like {'%' + make_description=' + '%'} OR alternatively
select * from model where make_description like {make_description=' + '%'}


The QuotedStr is a useful function which could be used in the following line.

 fNewCar_M.WL_Model.Params.Add('make_description =''%' + make + '%''');

This would become

fNewCar_M.WL_Model.Params.Add('make_description = ' + QuotedStr('%' + make + '%'));

which makes it easier to read.


Richard
Tue, Apr 12 2016 8:24 PMPermanent Link

Richard Harding

Wise Nutrition Coaching

I got that wrong.  How about this for the SQL?

select * from model where make_description like {make_description = '%'}

Richard
Tue, Apr 12 2016 8:38 PMPermanent Link

kamran

Hi Richard

That works for me !

The learning never stops.  

Much appreciated.

Take care

Kamran

Richard Harding wrote:

I got that wrong.  How about this for the SQL?

select * from model where make_description like {make_description = '%'}

Richard
Wed, Apr 13 2016 2:54 AMPermanent Link

Uli Becker

Kamran,

>    fNewCar_M.WL_Model.Params.Add('make_description =''%' + make + '%''');

Adding the param like this is correct. Since the placeholders are are
already used in the param, they are wrong (doubled) in the query:

So you should change your query definition it from

select * from model where make_description like
'%'+{make_description=''}+'%'

to

select * from model where make_description like {make_description=''}

That should work.

Uli


Wed, Apr 13 2016 4:43 AMPermanent Link

Matthew Jones

kamran wrote:

> field "make_description" is in table "model"
> field "make_description" is in table "make"

Not sure if I understand this fully, but it always struck me as a
newbie to SQL that people seemed to spend a lot of time fixing issues
with the same column names (fields) in different tables. Plainly there
are often links between them, but wouldn't it be better if you could
guarantee no problems, or if there are to be problems, that you know
immediately?

It seemed obvious to me that each table should be two words with unique
initials. So "ModelData" and "MakeStore" perhaps. Then each column gets
a prefix of the table initials. So mdMakeDescription and
msMakeDescription. It clarifies JOINs, so JOIN MakeStore on (mdModelID
= msModelID). Copy and paste and join to the BarneyRubble table, and if
you don't fix it to be brModelID, it will instantly fail and tell you
you made a mistake.

Just a thought - I'm not saying this is the only true way, just one
that I found useful to stop issues where you have the same column name
and it complicates things.

--

Matthew Jones
Wed, Apr 13 2016 8:14 AMPermanent Link

kamran

Hi

Thanks to Richard, Uli and Matthew.

It all works now as intended.

Cheers.

Kamran
Image