Santosh_mali
13th April 2018, 14:20
Hi All,

I am doing update operation using dynamic SQL.
Parsing and all is happening correct but db.update is returning value 509.

Please help if anybody knows how to resolve this issue.
Here is the code,

function dynamic.table.update( domain tcmcs.str8 inp.table,
domain tcmcs.long inp.index,
domain tcmcs.str8 inp.key1,
domain tcmcs.str4 inp.field,
domain tcmcs.str4 new.value)
{
string sql.string(512), str1(100)
long sql, var1, ret

db.retry.point()

sql.string = "select " & strip$(inp.table) & "." & strip$(inp.field) & " " &
"from " & strip$(inp.table) & " for update " &
"where " & strip$(inp.table) & "._index" & str$(inp.index) & " = { :1 }"

if (not sql) then
sql = sql.parse(sql.string)
endif

sql.where.bind(sql, 1, inp.key1)
sql.exec(sql)

while(true)
on case(sql.fetch(sql))
case eendfile:
break
case enorec:
break
case 0:
str1 = strip$(inp.table) & "." & strip$(inp.field) & ":=" & str$(new.value)
var1 = expr.compile(str1)
s.expr$(var1)

ret = db.update(sql, db.retry) |# on this line ret = 509
if ret = 0 then
commit.transaction()
endif
endcase
break
endwhile

sql.break(sql)
sql.close(sql)

sql = 0
}

mark_h
13th April 2018, 15:23
Is there in thing in any of the log files that might give more information. I was kind of expecting the db.update to have inp.table, but never used dynamic sql for updates that I recall.

Santosh_mali
13th April 2018, 15:49
Hi Mark,

Log file not showing any information.
inp.table is string so directly cannot be used in db.update.
instead used variable sql which used to bind the table.

mark_h
14th April 2018, 01:16
See if this thread helps - http://www.baanboard.com/baanboard/showthread.php?t=55388&highlight=dynamic+sql+update. Looks like the bind might be a little different for the table.

giggty
17th April 2018, 11:47
ret = db.update(sql, db.retry)
db.update requires pointer to table as its first argument, use db.bind()

Sahil Sharma
6th August 2018, 14:16
This error indicates that you have a bad memory cursor or that a bad table pointer has been specified.