Teradata - SQLSTATE equivalent in Big Query - stored-procedures

I'm trying to find a equivalent to the below queries in BIGQUERY.
We are working on a Teradata to Big Query conversion. We want to know the equivalent query or how to write in big query.
DECLARE a CONDITION FOR SQLSTATE '50000';
DECLARE b CONDITION FOR SQLSTATE '50001';
DECLARE EXIT HANDLER
FOR a , b
INSERT INTO Proc_Error ('50000 & 50001',
'updateSalesData', 'CONDITION HANDLER');
DECLARE EXIT HANDLER
FOR NOT FOUND
INSERT INTO Proc_Error ('NOT FOUND',
'updateSalesData', 'Generic no data found handler performed');
DECLARE EXIT HANDLER
FOR SQLWARNING
INSERT INTO Proc_Error ('SQLWARNING',
'updateSalesData', 'Generic exit warning handler performed');
DECLARE EXIT HANDLER
FOR SQLEXCEPTION
INSERT INTO Proc_Error ('SQLEXCEPTION',
'updateSalesData', 'Generic exit handler performed');
DECLARE CONTINUE HANDLER
FOR SQLEXCEPTION
INSERT INTO Proc_Error ('SQLEXCEPTION',
'updateSalesData', 'Generic continue handler performed');

Related

How can I use Firebird's Execute Block with Delphi TSQLQuery?

Using dbExpress TSQLQuery, I can't execute a query with execute block command because that command requires ? notation for parameters, and Delphi uses : for parameters, then, if in the body of that block creates variables and uses them as
select data from table where .... into :var;
that ":var" is interpreted as a parameter by TSQLQuery.
Which is the way for executing an execute block statement with Delphi?
If I write:
execute block(param1 char(1)=:param1)
I can load a value for :param1 from Delphi, but when I execute it with Query.Open or Query.ExecSQL an error returns indicating absence of parameter so ? because in Firebird execute block is written:
execute block(param1 char(1)=?param1)
Is there any way to resolve this with TSQLQuery?
first you can disable the TSQLQuery property for
ParamCheck := False;
Then at the beginning of execute block, remove the parameter path..
execute block (param1 char (1) = :param1)
and your query is passed (%s) instead of :param1.
I did so in my problem and solved it !
":var" is interpreted as a parameter by TSQLQuery
You can turn that off by setting the ParamCheck property to False.
the only way that worked for me was not putting ":" for internal vars in the block.
Ex. select data from table into var; and that's work!, then, as this is a block, evaluate the var with an if!
if (var = 1)
do something;
else
do anotherthing;
and resolved business!

Exit and Return in Proc TCL

I want to know the difference between Exit and Return inside a proc.
I have a script that contains a lot of proc, one of them uses exit and some value ex:
proc someProc {code} {
exit $code
}
and another one is like:
proc multiply {value} {
set number [expr {$value * 5}]
return $number
}
Does the exit stop the running script or what is the difference?
The exit command makes the current process stop. The running program will be gone afterwards (though the file containing the code will still be there). Its optional argument is the error code to hand to the OS; the default is zero, for no-error-at-all.
The return command makes the current procedure call stop. The optional argument provides a way to say what the result of the call to the procedure is; the default is the empty string (given that Tcl doesn't have NULL/null/nil/etc. at all).
Internally, exit does a system call to the “stop running this program” OS API, and return throws an exception that the general procedure management code transforms into the result of the call.

Handling error from one stored procedure into another in Sybase ASE 15.0

I need to execute a password reset on a Sybase ASE dataserver based on certain conditions:
if validations_here
begin
exec sp_password 'sso_passw', 'new_passw', #userid
end
sp_password might raise some errors, e.g. 10316 - "New password supplied is the same as the previous password". Although I couldn't find any documentation, I think they shouldn't be fatal errors and it should be possible to emulate them with raiserror.
Since it would be easier for the caller to handle it that way, I would like to get the error code and return it as part of a resultset, so I thought about SELECTing ##error. My code is as follows (I transcribed only those parts I think are relevant to the problem):
create procedure sp_desbloc_blanqueo_usr
#userid sysname,
#sso_pass varchar(20),
#new_pass varchar(20)
as
begin
declare #ret_code int
declare #ret_msg varchar(100)
declare #myerror int
select #ret_code = 0, #ret_msg = 'OK'
exec sp_password #sso_pass, #new_pass, #userid
set #myerror = ##error
if #myerror <> 0
begin
select #ret_code = #myerror, #ret_msg = 'Error occurred changing password'
-- It would be nice to have the actual error message as well
goto fin
end
fin:
select #ret_code as ret_code, #ret_msg as ret_msg
end
However, whenever I execute the stored procedure, I get 0 as ret_code and OK as ret_msg (even if parameters to sp_password are wrong).
How can I "catch" the error code of sp_password from my stored procedure?
Many "sp_" stored procedures set a nonzero return code when something goes wrong. Usually it is better to handle this return code than trying to catch errors raised inside the stored procedure. IIRC, this catching would not be possible with Transact-SQL; a 3rd generation language such as C would be required.
To get the return code of myproc stored procedure into variable #myvar, the syntax is
exec #myvar = myproc [arguments]
A simple example with sp_password:
declare #spreturn int
exec #spreturn = sp_password 'notmyoldpw', 'notmynewpw'
print "Return from sp_password is %1!", #spreturn
go
Server Message: Number 10315, Severity 14
Server 'SDSTRHA01_SY01', Procedure 'sp_password', Line 148:
Invalid caller's password specified, password left unchanged.
Server Message: Number 17720, Severity 16
Server 'SDSTRHA01_SY01', Procedure 'sp_password', Line 158:
Error: Unable to set the Password.
(1 row affected)
Return from sp_password is 1
(return status = 1)
The int variable #spreturn defined in the first line got sp_password return code, whose value was one as shown by (return status = 1) in the last message line. The reason why it was not zero is clear: there were two errors inside sp_password, 10315 and 17720. The point is to focus in this nonzero return code and ignore 10315 and 17720. In your stored proc, #spreturn ought to be checked against zero. If zero it ran OK, else something failed.

how can i stop a lua function block/call mid execution

is there a way to stop a lua pcall to a lua function block from mid execution? Im using multiple threads and would be good to cancel a function mid-flight.
The simplest way is to call error('my message') as this will abort the execution and will return nil, 'my message' as the result of pcall(). If you want to abort a running coroutine (or a "main" chunk) from "outside", the only way to do it I know about without modifying Lua VM is to attach a debug hook to coroutine or the main chunk and call error() from that debug hook:
print(1)
local count = 0
debug.sethook(function(event, line)
if count > 1 then error('done', 2) end
count = count + 1
end, "l")
print(2)
print(3)
print("not getting here")
You should see something like this:
1
2
3
script.lua:4: done
In the case of pcall, you will see the parameter of the error() call to be passed as the error message by pcall.
The conditions to check can get quite elaborate; for example, you can check for the hook to be called from a particular function with a certain number of commands executed before aborting.

How to exit a Lua script's execution?

I want to exit execution of Lua script on some condition .
Example :
content = get_content()
if not content then
-- ( Here i want some kind of exit function )
next_content = get_content()
--example there can lot of further checks
Here I want that if I am not getting content my script suppose to terminate is should not go to check to next.
Use os.exit() or just return from some "main" function if your script is embedded.
os.exit()
kill process by sending a signal
do return end
stop execution
The two methods are not equal if you want to write and execute some luacode in the interpreter after stopping the execution by launching your program using the -i flag.
th -i main.lua
extract from the lua api doc :
For syntactic reasons, a break or return can appear only as the last statement of a block (in other words, as the last statement in your chunk or just before an end, an else, or an until). For instance, in the next example, break is the last statement of the then block.
local i = 1
while a[i] do
if a[i] == v then break end
i = i + 1
end
Usually, these are the places where we use these statements, because any other statement following them is unreachable. Sometimes, however, it may be useful to write a return (or a break) in the middle of a block; for instance, if you are debugging a function and want to avoid its execution. In such cases, you can use an explicit do block around the statement:
function foo ()
return --<< SYNTAX ERROR
-- `return' is the last statement in the next block
do return end -- OK
... -- statements not reached
end
In lua 5.2.0-beta-rc1+, you can add a label at the end of your code called ::exit:: or something of the like, and then whenever you need to exit the program just call it like this:
goto exit

Resources