-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite stored procedure as an SQL UDF #25
Comments
@kadler We were thinking UDF rather than UDTF, since XMLSERVICE returns a single value (XML string). What do you think? |
Not sure why I said UDTF. Probably because all the SQL services I wrote were UDTFs and also I'm used to this other kind of UDF. But yes, since it returns a single value it should be a scalar UDF. Something like |
Some thoughts:
|
Any XMLSERVICE replacement we would write in C. Hardly anyone in IBM has RPG skills outside the compiler team and it's pretty clear that the theory of getting more outside contributions due to being written in RPG has not panned out (some of that is due to it being byzantine Tonycode, but still).
VARCHARs for UDFs with "LANGUAGE C" is a standard C null terminated string (though oddly VARGRAPHICs are not null-terminated wchar_t or SQLWCHAR strings, but structs with length prefix).
The return value of a UDF is not the return value of a function, but instead is a parameter passed to you just like other parameters. This parameter is a buffer of the size specified by SQL create function statement and its lifetime is owned by the caller. If you need to store data between calls to OPEN/FETCH/CLOSE you can use a scratchpad - either of a required size or allocate the memory and store the pointer in the scratchpad. You can also enable final call which adds two more steps: FIRST/FINAL which happen once per statement (while OPEN/FETCH/CLOSE happen per-invocation of the UDF within a statement). |
A UDF does not require an SQL pre-compiler or embedded SQL.
The text was updated successfully, but these errors were encountered: