The connection is fine, but the query sentence seems problematic.
query1 = """SELECT * FROM `DATABASE` WHERE `coin` = 'LTC'"""
query2 = """SELECT * FROM `DATABASE` WHERE `coin` = 'LTC' AND `date` > '2019-01-01 15:06:23'"""
And then
import pandas as pd
result = pd.read_sql(query, connection)
It works perfectly fine with query1 but gives such error for query2: result = pd.read_sql(query, connection)
Traceback (most recent call last):
File "<ipython-input-25-c7c27cfd9a6b>", line 1, in <module>
result = pd.read_sql(query, connection)
File "C:\Users\luzhe\Anaconda3\lib\site-packages\pandas\io\sql.py", line 381, in read_sql
chunksize=chunksize)
File "C:\Users\luzhe\Anaconda3\lib\site-packages\pandas\io\sql.py", line 1413, in read_query
cursor = self.execute(*args)
File "C:\Users\luzhe\Anaconda3\lib\site-packages\pandas\io\sql.py", line 1386, in execute
raise_with_traceback(ex)
File "C:\Users\luzhe\Anaconda3\lib\site-packages\pandas\compat\__init__.py", line 404, in raise_with_traceback
raise exc.with_traceback(traceback)
File "C:\Users\luzhe\Anaconda3\lib\site-packages\pandas\io\sql.py", line 1382, in execute
self.con.rollback()
File "C:\Users\luzhe\Anaconda3\lib\site-packages\pymysql\connections.py", line 808, in rollback
self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
File "C:\Users\luzhe\Anaconda3\lib\site-packages\pymysql\connections.py", line 1122, in _execute_command
raise err.InterfaceError("(0, '')")
DatabaseError: Execution failed on sql: SELECT * FROM `DATABASE` WHERE `coin` = 'LTC' AND `date` > '2019-01-01 15:06:23'
(0, '')
unable to rollback
I want to know what this "unable to rollback" means and how to solve this multi-condition selection in PyMySQL.
unable to rollback
It means your query has not been successfully executed.
An unclosed connection is usually the cause for that error. You might not have closed the previous connection. You can usually do so with the close
method associated with the connection instance.