Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Support ON/OFF as synonyms of 1/0 #374

Closed
campoy opened this issue Sep 21, 2018 · 4 comments · Fixed by #383
Closed

Support ON/OFF as synonyms of 1/0 #374

campoy opened this issue Sep 21, 2018 · 4 comments · Fixed by #383
Assignees
Labels
enhancement New feature or request

Comments

@campoy
Copy link

campoy commented Sep 21, 2018

Some drivers (notably Python's mysql-connector) set some variables by using ON and OFF rather than using 1 and 0.

Since these are currently not supported the behavior when these are set (which happens while the connection is being established) varies:

  • SET @@session.autocommit=OFF causes an error indicating that OFF is not a known column.
  • SET @@session.autocommit=ON fails to parse since ON is also a reserved keyword.

I did some hacky changes to prove this could be fixed by making ON and OFF non reserved keywords and I was then able to connect from a Jupyter Notebook.

I consider this change quite urgent, since it is blocking usage of gitbase from many different SQL drivers.

@campoy
Copy link
Author

campoy commented Sep 21, 2018

As a motivating example, once this is fixed we will be able to run programs like these:

from matplotlib import pyplot as plt
from mysql import connector as sql

print('querying data... (can take up to a minute)')

conn = sql.connect(user='root', passwd=None, db='mysql')
cursor = conn.cursor()
cursor.execute("""
    SELECT year, month, count(*) as n
    FROM (
      SELECT commit_author_when, YEAR(commit_author_when) as year, MONTH(commit_author_when) as month
      FROM commits
    ) as t
    GROUP BY year, month
    ORDER BY year, month;
""")

dates = []
counts = []
for (year, month, count) in cursor:
    dates.append('%04d%02d'%(year,month))
    counts.append(count)

plt.figure(figsize=(20,5))
plt.scatter(dates, counts)
plt.xticks(rotation=60)
plt.show()

Which generate the following graph:

screen shot 2018-09-21 at 2 26 49 pm

@ajnavarro ajnavarro added the enhancement New feature or request label Sep 24, 2018
@kuba-- kuba-- self-assigned this Sep 24, 2018
@campoy
Copy link
Author

campoy commented Sep 24, 2018

I'd love to use the engine from jupyter for the online meetup on Wednesday.
Do you think it'll be ready, @kuba-- ?

@ajnavarro
Copy link
Contributor

@campoy Can you test with pymysql? It should work out of the box. Some examples made by @smola long time ago, using gitbase: https://gist.github.com/smola/c5a190856eaa580bfcde372aeff2cb7f

@kuba--
Copy link
Contributor

kuba-- commented Sep 26, 2018

Related: vitessio/vitess#4220

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants