Skip to content

BUG: fix read_sql delegation for queries without select statement (GH7324) #7326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jorisvandenbossche
Copy link
Member

Closes #7324.

The if 'select' in ...' check was introduced for mysql legacy compatibility, but introduced problem if the query did not contain a select statement (eg a stored procedure). This should solve this, and passes the test suite (locally).

@jreback
Copy link
Contributor

jreback commented Jun 3, 2014

you mean #7324, rigtht?

@jorisvandenbossche
Copy link
Member Author

yep, changed

@hayd
Copy link
Contributor

hayd commented Jun 4, 2014

should add something to release? otherwise looks good!

@jorisvandenbossche
Copy link
Member Author

yep, and maybe also a small test with a stored procedure

@jorisvandenbossche
Copy link
Member Author

added release note and test. Only problem for now is that the test is not working (see failed travis). Strange thing is that I get a Command out of sync error when I call read_sql("CALL proc") (https://github.com/jorisvandenbossche/pandas/blob/sql-delegation/pandas/io/tests/test_sql.py#L1097) after creating the procedure with engine.execute(proc) (which resultproxy is automatically closed by sqlalchemy). And If I run the read_sql a second time, it is OK. @hayd @danielballan any idea? (I can just add a try: .. except: pass for the first call, but that seems not really correct)

@jreback jreback added the SQL label Jun 4, 2014
@jreback jreback added this to the 0.14.1 milestone Jun 4, 2014
@danielballan
Copy link
Contributor

My guess is something with transactions. I spent a few minutes today and couldn't get it. I could be wrong, but I thought I'd share that thought in case someone has more time to look at this before I revisit it.

@jorisvandenbossche
Copy link
Member Author

@danielballan Thanks for the pointer, that solved it.

I tested the following approaches:

engine.execute(proc)
with engine.begin() as connection:
    connection.execute(proc)
connection = engine.connect()
trans = connection.begin()
try:
    r1 = connection.execute(proc)
    trans.commit()
except:
    trans.rollback()
    raise

And only the last did work, although I don't fully understand why, as I would think the other should be equivalent (http://docs.sqlalchemy.org/en/rel_0_8/core/connections.html#using-transactions), as sqlalchemy autocommits by default. But in any case, it works now (and it was only for the test, so not that important).

…7324)

The select check was introduced for mysql legacy compatibility, but introduced problem if the query did not contain a select statement (eg a stored procedure)
jorisvandenbossche added a commit that referenced this pull request Jun 5, 2014
BUG: fix read_sql delegation for queries without select statement (GH7324)
@jorisvandenbossche jorisvandenbossche merged commit fa8a5ca into pandas-dev:master Jun 5, 2014
@jorisvandenbossche jorisvandenbossche deleted the sql-delegation branch June 5, 2014 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO SQL to_sql, read_sql, read_sql_query
Projects
None yet
Development

Successfully merging this pull request may close these issues.

read_sql delegation dependent on occurence of 'select' in query
4 participants