[DB-SIG] Problem with mxODBC insert statement

Chris Cogdon chris at cogdon.org
Tue Oct 12 22:27:55 CEST 2004


On Oct 12, 2004, at 13:18, Khawaja-Shahzad Butt wrote:

> Hello,
>
>  I don't know how to use SQL which way for mxODBC and
> python. I used this statement and got this error.
>
> q= "INSERT INTO
> rss_feed_items(item_date,item_title,item_author,item_permalink,item_des 
> cription)\
>    VALUES(%s)"%(item_dmodified);
>
> MS SQL server 2000 gave me this error for above query statement:
>
> ProgrammingError: ('37000', 170, "[Microsoft][ODBC SQL Server
> Driver][SQL Server]Line 1: Incorrect syntax near '06'.", 4612)
>
> or  can i use the ? instead of %s can you give me example since there  
> is
> none in egenix manual for mxODBC. What am i doing wrong.
> Also should always use auto_commit while using mxODBC

You should instead let 'execute' do the parameter insertion for you,  
viz:

cursor.execute ( "INSERT INTO  
rss_feed_items(item_date,item_title,item_author,item_permalink,item_desc 
ription) VALUES(%s,%s,%s,%s,%s)",
		(new_item_date, new_item_titme, new_item_author, new_item_permalink,  
new_description) )

This is because, while it LOOKS LIKE that execute is doing python-style  
%-formatting, it isn't really. The database connector knows what format  
each of the data types needs to be in, use it :)


-- 
    ("`-/")_.-'"``-._        Chris Cogdon <chris at cogdon.org>
     . . `; -._    )-;-,_`)
    (v_,)'  _  )`-.\  ``-'
   _.- _..-_/ / ((.'
((,.-'   ((,/   fL



More information about the DB-SIG mailing list