[Tutor] mysql formatting

Lloyd Kvam pythonTutor at venix.com
Wed Nov 3 01:12:16 CET 2004


On Tue, 2004-11-02 at 18:46, Marilyn Davis wrote:
> Can you folks please help me some more?
> 
> I'm having a trouble, now that I'm really trying to implement what I
> learned yesterday.
> 
> Here's the error:
> 
> _mysql_exceptions.ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'\'doorman\' set status = "\'MOVED\'" where in_id = \'60\' and out_address like "%\'wrgf\' at line 1')
> 
> 
> Here's my code:
> 
>      def execute_mysql(self, this, *args):
>          if log.level & log.sql:
>              log.it('About to execute:' + this + '<-->' + repr(args))
>          try:
>              self.cursor.execute(this, args)
>          except _mysql_exceptions.Warning, msg:
>              log.it('Mysql Warning: ' + str(msg))
>          except _mysql_exceptions.OperationalError, msg:
>              print "Are you using the right data base?  Try changing /b/local/doorman/configure.py TESTING = 0"
>              raise
> 
> And from my log:
> 
>    About to execute:update %s set status = "%s" where in_id = %s and out_address like "%%%s%%"<-->('doorman', 'MOVED', '60', 'wrgfgtfdpmrwe at hewpwbpsk.rashpie.com')

I am pretty sure it is the quotes.  Simply use %s where the data is
supposed to go and the module will quote it as necessary.  They make it
so easy on us that it is hard not to do too much.

   About to execute:update %s set status = %s where in_id = %s and
out_address like %%%s%%

<-->('doorman', 'MOVED', '60', 'wrgfgtfdpmrwe at hewpwbpsk.rashpie.com')


> 
> 
> Why am I getting those extra \' thingies?
> 
> Thank you so much!
> 
> Marilyn
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-- 
Lloyd Kvam
Venix Corp



More information about the Tutor mailing list