Python MySQL соединитель fetchall ничего не возвращает
import mysql.connector
from mysql.connector import errorcode
from mysql.connector import Error
config = {
'user': 'username',
'password': 'password',
'host': '127.0.0.1',
'database': 'databaseName',
'raise_on_warnings': True,
}
def ExecuteSciptFromFile(filename):
file = open(filename, 'r')
sql = file.readlines()
conn = cnx.cursor(buffered=True)
for command in sql:
try:
conn.execute(command)
cnx.commit()
for data in conn.stored_results():
print(data.fetchall())
except mysql.connector.OperationalError as err:
print "Command Skipped", err
conn.close()
cnx.close()
try:
cnx = mysql.connector.connect(**config)
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print "username or password is invalid"
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print "Zabbix DB does not exist or you mispelled it"
else:
print(err)
else:
ExecuteSciptFromFile('/path/path/to/my_request.sql')
Смотрите пример кода выше. когда я запускаю этот скрипт, fetchall ничего не возвращает. мой внешний файл sql в настоящее время содержит более одной строки, поэтому я вызываю метод readlines() в моей переменной sql. Из всех намерений и целей код выглядит правильно, и я должен увидеть вывод моего запроса:
create temporary table tempdb (itemid int, clock int, value double(16,4));
insert into tempdb (itemid, clock, value) select itemid, clock, value from
history where itemid = 25655 order by clock desc limit 10;
insert into tempdb (itemid, clock, value) select itemid, clock, value from
history where itemid = 25632 order by clock desc limit 10;
select * from tempdb;
В посте это не показано, но каждое выражение находится в отдельной строке, поэтому я не беспокоюсь о split(';'). По крайней мере, это мое предположение.
Любая помощь приветствуется.