You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
592 B
Python
25 lines
592 B
Python
#-*- coding:utf-8 -*-
|
|
|
|
try:
|
|
import MySQLdb as mdb
|
|
except:
|
|
import pymysql as mdb
|
|
mdb.install_as_MySQLdb()
|
|
|
|
from sys import argv
|
|
|
|
script, sql_host, sql_port, sql_user, sql_passwd, sql_db, sql_stmt = argv
|
|
|
|
connection = mdb.connect(host = sql_host, port = int(sql_port), user = sql_user, passwd = sql_passwd, db = sql_db)
|
|
cursor = connection.cursor()
|
|
try:
|
|
cursor.execute(sql_stmt)
|
|
records = cursor.fetchall()
|
|
fmttedRecords = '\n'.join(' '.join(str(col) for col in record) for record in records)
|
|
print fmttedRecords
|
|
|
|
finally:
|
|
cursor.close()
|
|
connection.close()
|
|
|