0

I am using HANA Python Connector's Cursor.execute(sql,hanaparams) method, the parameters to this method are sql statement and hanaparams.My query is like this.

"SELECT * FROM TABLE WHRE COLUMN1 IN(?)" and My PARAMETES ARE VALUE1 ,VALUE2; LIKE LIST/TUPLE;

I am unable to retrieve resultset, Whereas when i run this in HANA with Query and Input Parameters Hard Coded in ,it runs perfectly fine

I am following this tutorial https://developers.sap.com/tutorials/hana-clients-python.html

Any pointers how should i Pass multiple values in Params

1 Answers1

0

Something simple like this seems to work just fine. Count of ? must be equal to count of parameters you have. In your case it takes only VALUE1.

from hdbcli import dbapi

conn = dbapi.connect(
    key='HDBKEY'
)

cursor = conn.cursor()
parameters = [11, "2020-12-24"]
params = '?,'*len(parameters)
params2 = params[0:-1]
sql_command2 = f"SELECT {params2} FROM DUMMY;"
cursor.execute(sql_command2, parameters)
rows = cursor.fetchall()
for row in rows:
    for col in row:
        print ("%s" % col, end=" ")
        print (" ")
cursor.close()
conn.close()

So instead of SELECT * FROM TABLE WHERE COLUMN1 IN(?) it should be SELECT * FROM TABLE WHERE COLUMN1 IN(?, ?)

Reinis Verbelis
  • 396
  • 3
  • 8
  • Thanks For Reply @Reinis Verbelis, The Input Param Can become Val1,Val2,Val3. So let us say Input param is List. In this case how do we pass Input Params – akshindesnowflake Sep 02 '21 at 06:10
  • To be honest I am not sure, but you could make up the SQL query to include as many `?` as there are items in the list. Made an edit in my example. Seems to work fine – Reinis Verbelis Sep 02 '21 at 07:38
  • Thanks For Reply @Reinis Verbelis, I tried same approach where i concatenated params with LIST_AGG function and passed that as Input Param , unfortunately it is not working. – akshindesnowflake Sep 02 '21 at 08:13
  • Not sure I understand. Maybe you can post you code. – Reinis Verbelis Sep 02 '21 at 08:55