Running MySQL query from Python 2.4 while not installing modules (MySQLdb) -



Running MySQL query from Python 2.4 while not installing modules (MySQLdb) -

i need run mysql query python 2.4 cannot download/install modules python.

the reason cannot download because script run on servers (redhat) , our customers not allow download , install anything.

i've been trying utilize subprocess, query i'm using giving me syntax error.

the query works outside of python if run query browser, adding quotes , commas within subprocess command [] makes things little confusing.

the command i'm trying run follows:

subprocess.call(['mysql', '-d db', '--user="user"', '--password="password"', '-e', '"select cu, control_name presetprofile not cu='' , not control_name='' outfile '/directory/for/output.file' fields terminated ':' lines terminated '\n';"', shell=true])

the syntax error points single quote before : after fields terminated by.

file "<stdin>", line 1 subprocess.call(['mysql', '-d db', '--user="user"', '--password="password"', '-e', '"select cu, control_name presetprofile not cu='' , not control_name='' outfile '/directory/for/output.file' fields terminated ':' lines terminated '\n';"', shell=true]) ^ syntaxerror: invalid syntax

once output file created, can stop using subprocess , regular file processing.

your query this: '"select cu, control_name presetprofile not cu='' , not control_name='' outfile '/directory/for/output.file' fields terminated ':' lines terminated '\n';"'

notice have ' within string -- you'll need escape them or utilize triple quotes.

'"select cu, control_name presetprofile not cu=\'\' , not control_name=\'\' outfile \'/directory/for/output.file\' fields terminated \':\' lines terminated \'\\n\';"'

also you'll want drop shell=true bit -- managing escaping hard plenty if you're dealing python. 1 time need un-escape 1 time again shell things more messy.

python mysql syntax-error subprocess

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -