ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> db-sig
db-sig
Re: [DB-SIG] mysql string length?
by Engelbert Gruber other posts by this author
Apr 17 2006 5:57AM messages near this date
Re: [DB-SIG] mysql string length? | Re: [DB-SIG] mysql string length?
On Mon, 17 Apr 2006, Andy Todd wrote:

> >>>>> stmt = "INSERT INTO table_x (body) VALUES (%s)" # [1]
> >>>>> cursor.execute(stmt, (body,))
> >> [1] note that there are no quote marks around the %s
> > 
> > this works here (debian testing, python 2.3.5, 4.0.21) ::
> > 
> > import MySQLdb
> > """
> > create table table_x (
> >    id int auto_increment primary key,
> >    body text
> >    )
> > """
> > db = MySQLdb.connect(passwd="",db="test")
> > c = db.cursor()
> > body = "0....5...."*28
> > sql = "INSERT INTO table_x (body) VALUES('%s')"
> > c.execute( sql % (body))
> > c.execute("select body from table_x")
> > for row in c.fetchall():
> >      print len(row[0])
> > 
> > i wont bet on fetching 1Mb.
> > 
> > cheers
> 
>  You've just repeated the original poster's code. As I suggested the problem 
>  is that he's using string substitution when he should be using parameter 
>  substitution. In these cases %s means two completely different things.

yes but it works here, even with ``body = "0....5...."*280`` so i cannot 
blame it on not using 'paramstyle', or what ?

>  Please read the sections on 'paramstyle' and the cursor '.execute' method in 
>  the DB-API 2.0 definition [1].

of course you are right it is ::

   c.execute("INSERT INTO table_x (body) VALUES('%s')"% (body))

or paramstyle without quotes ::

   c.execute(INSERT INTO table_x (body) VALUES(%s)", (body))

but both work here with bodylength up to 65535 bytes not 255.

sorry for dupplication, but i fail to see the point.


-- 
_______________________________________________
DB-SIG maillist  -  DB-SIG@[...].org
http://mail.python.org/mailman/listinfo/db-sig
Thread:
Lukasz Szybalski
Andrew Chambers
Lukasz Szybalski
Andy Todd
Engelbert Gruber
Andy Todd
Engelbert Gruber
Lukasz Szybalski
Lukasz Szybalski
Andy Todd
Lukasz Szybalski
M.-A. Lemburg
Ian Bicking
Gerhard Häring
Ian Bicking
Carsten Haese
Gerhard Häring
Carsten Haese
Carsten Haese
Python
Engelbert Gruber
Andy Dustman

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved