Is this wrong?
Hi Das,
I know this isn’t what you were asking and Kelly dealt with that.
But let me just throw in my 2¢ here. It is wrong because you are not
using a bind variable for your data. As a DBA, my constant mantra to
developers is “Always use bind variables”. Your application may be
working now but there will come a time when something will go wrong.
As an example, if you are searching for clients with a statement like
“where surname = [iLineItemsList.line_surname]”, what happens when the
client’s name is O’Reilly?
And depending on your application’s audience, you may need to worry
about SQL injection. There are plenty of references online to explain
this one.
But on a more positive note, using bind variables allows you to reuse a
prepared SQL statement. So when running the same query, such as your
example, if you are looking for multiple products one after another, you
would prepare your statement once and then execute it as often as
needed, just changing the value each time. This will speed up execution
as you don’t need to make 2 round trips to the DB server for each
execution. This may not be an issue for you but in a high transaction
system it can make a difference.
So, for instance, within your Products table class instantiated as a row
variable you can do something like this:
Begin statement
Sta: {select [$cinst.$selectnames()]}
Sta: {from [$cinst.$servertablenames]}
Sta: {where prod_id = @[lvProdId]} ;; note the @ symbol before the [
End statement
Do $cinst.$statementobject.$prepare() Returns lbOK
If not(lbOK)
; handle the $prepare error
Quit method
End If
For iLineItemsList.$line from 1 to iLineItemsList.$linecount step 1
Calculate lvProdId as iLineItemsList.line_prod_id ;; populate your
bind variable
Do $cinst.$statementobject.$execute() Returns lbOK
If lbOK
Do $cinst.$statementobject.$fetch($cinst)
; do whatever you need to with the product record
Else
; handle the $execute error
Break to end of loop
End If
End For
As I said, just my 2¢ worth. But you will find it easier to put bind
variables in now rather than having to modify your code later.
Best regards,
Graham
On 01/03/2018 08:47, Das Goravani wrote:
> Do iProdRow.$select(“WHERE prod_id='[iLineItemsList.line_prod_id]'”) Returns #F
>
> Is there something wrong with my usage of row/column inside square brackets as shown?
>
> If I calculate that value into #1 and stick that there, then it works
>
> With a reduced variable, just [#1] it works, but with the row and column, nope.
>
> I did an awful lot of programming with row and column I hope I don’t have to change it all
>
_____________________________________________________________
Manage your list subscriptions at lists.omnis-dev.com
Start a new message -> mailto:omnisdev-en@lists.omnis-dev.com