I have the following table and the following stored procedure (simplified to the bare basics needed to demonstrate the problem):
CREATE TABLE T(C INT);
CREATE PROCEDURE PROC(IN T TABLE(C INT), OUT X INT) AS BEGIN
X = 5;
END;
From HANA Studio, I can CALL PROC(T, ?)
and get 5. However, I have not found any good way to do the same from the hdbcli Python driver.
callproc
doesn't seem to have any way to accept table parameters. Passing the table name as a string doesn't work:
>>> from hdbcli import dbapi
>>> conn = dbapi.connect(userkey='testkey')
>>> cur = conn.cursor()
>>> cur.callproc('PROC', ('T', '?'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/hdbcli/dbapi.py", line 498, in callproc
ret = self.__callproc(callproc, parameters)
File "/usr/local/lib/python3.6/site-packages/hdbcli/dbapi.py", line 257, in __callproc
return self.__cursor.callproc(operation, parameters)
hdbcli.dbapi.Error: (8, 'invalid argument: Input parameter is inadequate as table parameter: line 1 col 13 (at pos 12)')
execute
can execute the procedure, but it doesn't seem to provide any way to access the output parameter. There's no result set for it:
>>> cur.execute('CALL PROC(T, ?)')
True
>>> cur.fetchone()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/hdbcli/dbapi.py", line 434, in fetchone
raise ProgrammingError(0,"No result set")
hdbcli.dbapi.ProgrammingError: (0, 'No result set')
I've found one extremely awkward workaround, which I'm posting as an answer, but it's horribly verbose and doesn't interact well with default parameter values. Is there a good way to access the output parameter?