You are not logged in.

#1 2008-06-13 00:48:57

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,694
Website

Strings with /' characters after return

I use embedded procedures a fair bit in my database driven web sites programming, so I decided to pre-buld my queries to expedite and simplify the process.
I wrote the following script:

#!/usr/bin/python
#
import MySQLdb
from uid_gdbm import *

proc_params = ('manage_codes','add',555,'Just a test') <-- test list

def buildquery():
    
    items = len(proc_params)
    #print items
    prog_name = proc_params[0]
    
    args ="%("
    stgcount = ""

    for i in range(1, len(proc_params)-1):
        args += repr(proc_params[i])
        stgcount += "'%s'"
        for j in range (1, len(proc_params)-2):
            args += ","
            stgcount +=","

    myquery = "\"call " + prog_name + "(" + stgcount + "'%s'" + ")\" " + args + repr(proc_params[(items -1)]) + ")"
    print myquery  < -- prints : "call manage_codes('%s','%s','%s')" %('add','555','Just a test') 
    return myquer <-- but after retuning it I get :"call manage_codes(\'%s\',\'%s\',\'%s\')" %(\'add\',\'555\',\'Just a test\')

as a result I get a MySQL error: 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 \'"call manage_codes(\'%s\',\'%s\',\'%s\')" %(\'add\',\'555\',\'Just a test\')\' at line 1')

Any ideas as to why this is  happening and more importantly how cay I get read of the \' escape characters?

Thanks.

Offline

Board footer

Powered by FluxBB