Please be aware that the SAP SQL Anywhere Forum will be shut down on August 29th, 2024 when all it's content will be migrated to the SAP Community.

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"


Sybase docs for bind variables

asked 06 Jan '16, 05:47

toasteez's gravatar image

accept rate: 0%

it seems that this form is supported:

sql = "select something from table where something = '%s'" %strvar


This is not ideal as it would leave code open to injection, does it support something as explained here:

(06 Jan '16, 06:45) toasteez

This works:

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

In pandas use the list method:

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

permanent link

answered 06 Jan '16, 07:03

toasteez's gravatar image

accept rate: 0%

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", ))
>  Phillips
permanent link

answered 07 Jan '16, 16:03

Tom%20Slee's gravatar image

Tom Slee
accept rate: 29%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 06 Jan '16, 05:47

question was seen: 4,057 times

last updated: 07 Jan '16, 16:03