[DB-SIG] mysql string length?

Python python at venix.com
Tue Apr 18 23:53:29 CEST 2006


On Tue, 2006-04-18 at 13:00 -0500, Lukasz Szybalski wrote:
> > When i try :
> > c.execute("Insert into table_x(body) VALUES(%s)",(body))
> > This will work but how do i make :
> >
> > sql="Insert into table_x(body) VALUES(%s)",(body)
> > c.execute(sql)  #complains that i give it a tuple, which i did when

c.execute( sql, (body,) )

(I'm pretty sure that with a single value this would also work:
	c.execute( sql, body )
but I do not have time to actually test that right now.)

> > you look at sql
> >
> > One problem i see here is that it works in one way but no the other.
> > So how do i add id and  make it work both ways?
> >
> > c.execute("Insert into  table_x(id,body) VALUES(%d,%s)",(id),(body))

c.execute("Insert into  table_x(id,body) VALUES(%s,%s)", (id,body) )

Notes:
	the placeholders are *ALWAYS* %s.  This is not Python string
formatting.

	There are two arguments, the SQL command string and the tuple of values
to be substituted into the database.


> > ??does not work
> 
-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:  603-653-8139
fax:    320-210-3409
-- 
Lloyd Kvam
Venix Corp



More information about the DB-SIG mailing list