on 2016 Jan 06 5:47 AM
Is it possible to use Bind variables with Python?
I am using sqlanydb latest release and have tried without success each of the methods mentioned here
my preferred method is pyformat but this raises error:
select something from table where something = %(bindvar)s': b"Syntax error near '%' on line 1"
Request clarification before answering.
You can use the question mark format:
import sqlanydb
conn = sqlanydb.connect(dsn="SQL Anywhere 17 Demo",uid="dba",pwd="sql",charset="utf-8")
sql = "select Surname from GROUPO.Customers where city = ?"
cur = conn.cursor()
cur.execute(sql, ("Newmarket", ))
print(cur.fetchone()[0])
> Phillips
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This works:
sql = "select something from table where something = :bindvar"
In pandas use the list method:
pd.read_sql(sql, db, params=[bindvar])
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
52 | |
6 | |
5 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.