2

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.

7
  • I guess it means the transaction failed. Is there a column called data in your table?
    – 10101010
    Commented Mar 12, 2019 at 8:46
  • What is pd here?
    – 10101010
    Commented Mar 12, 2019 at 8:48
  • @10101010 no i dont think so
    – IsaIkari
    Commented Mar 12, 2019 at 9:09
  • @10101010 But I do have a date in the columns
    – IsaIkari
    Commented Mar 12, 2019 at 9:10
  • Can I know what pd is? Is it referring to pandas?
    – 10101010
    Commented Mar 12, 2019 at 9:49

1 Answer 1

4

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.