Forum

Kognitio Console issues, advice, etc.
Contributor
Offline
Posts: 184
Joined: Wed May 29, 2013 2:10 pm
Location: Bracknell

Kog Scripts: how do I branch on resultset data?

by MikeAtkinson » Tue Jul 16, 2013 8:30 am

I'm running a Kog script and perform a query, how do I use the results from that query to do flow control?
Reply with quote Top
Contributor
Offline
Posts: 184
Joined: Wed May 29, 2013 2:10 pm
Location: Bracknell

Re: Kog Scripts: how do I branch on resultset data?

by MikeAtkinson » Wed Jul 17, 2013 4:40 pm

When an SQL statement is run the WCSerror and SQLState variables are set. If the SQL statement executes without error they are both set to the string "OK"

When an error occurs then SQLState will be set to an internal error string (something like "52S02") and WCSerror will be set to the Kognitio Analytics Platform error code (e.g. CI3013).

If the results of the query are assigned to a Lua table then the table status member variable will have a non-zero value on an error.

For example running the code:

Code: Select all

t = select * from non_existent;
will set t.status to 1.

These values may then be used for control flow, e.g.

Code: Select all

t = select * from non_existent;
if t.status ~= 0 then
     print("status=" .. t.status .. " error\n");
end;

if WCSerror ~= "OK" then
     print("WCSerror=" .. WCSerror .. " \n");
end;

if SQLState ~= "OK" then
     print("SQLState=" .. SQLState .. " \n");
end;
Which gives the output:
Running Script

select * from non_existent
42S02[Kognitio][WX2 Driver][latest] CI3013: Table SYS.NON_EXISTENT does not exist, offset 15 status=1 error
WCSerror=CI3013
SQLState=42S02
Reply with quote Top

Who is online

Users browsing this forum: No registered users and 1 guest

cron