cancel
Showing results for 
Search instead for 
Did you mean: 

Bind Variables Python

Former Member
4,244

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"

PEP249

Sybase docs for bind variables

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member

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
Former Member

This works:

sql = "select something from table where something = :bindvar"

In pandas use the list method:

pd.read_sql(sql, db, params=[bindvar])