sqlite / python - named parameters without enclosing quotes? -


when using prepared statements named parameters in sqlite (specifically python sqlite3 module http://docs.python.org/library/sqlite3.html ) there anyway include string values without getting quotes put around them ?

i've got :

columnname = '''c1''' cur = cur.execute('''select distinct(:colname) t1''', {'colname': columnname}) 

and seems sql end :

select distinct('c1') t1 

which isn't use of course, want :

select distinct(c1) t1 . 

is there way prompt execute method interpret supplied arguments in such way doesn't wrap quotes around them ?

i've written little test program explore it's worth here :

import sys import sqlite3 def getdatabaseconnection():     defaultdbpath = ':memory:'      conn = sqlite3.connect(defaultdbpath, detect_types=sqlite3.parse_decltypes|sqlite3.parse_colnames)     conn.text_factory = str      return conn  def initializedbtables(conn):     conn.execute('''     create table t1(       id integer primary key autoincrement,       c1 string);''')        cur = conn.cursor()     cur.row_factory = sqlite3.row  # fields name       v in ['a','a','a','b','b','c']:         cur.execute('''insert t1 values (null, ?)''', v)      columnname = '''c1'''     cur = cur.execute('''select distinct(:colname) t1''', {'colname': columnname})      #should end 3 output rows, in     #fact end 1     row in cur:         print row   def main():     conn = getdatabaseconnection()     initializedbtables(conn)  if __name__ == '__main__':     main() 

would interested hear of anyway of manipulating execute method allow work.

in select distinct(c1) t1 c1 not string value, piece of sql code. parameters (escaped in execute) used insert values, not pieces of code.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -