Skip to content
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

sqlparse.split can't split sqls correctly in one case #588

Closed
Shawn001 opened this issue Oct 16, 2020 · 6 comments
Closed

sqlparse.split can't split sqls correctly in one case #588

Shawn001 opened this issue Oct 16, 2020 · 6 comments
Labels
Milestone

Comments

@Shawn001
Copy link

@Shawn001 Shawn001 commented Oct 16, 2020

for example:

sqls2="grant insert,update,delete on test.test1 to lili@192.168.11.23; grant update,insert,select on test1.test2 to lili2@10.10.11.12;"
for st in sp.split(sqls2):
... print(st)
...
grant insert,update,delete on test.test1 to lili@192.168.11.23; grant update,insert,select on test1.test2 to lili2@10.10.11.12; ---------in one line still

sqls2="grant insert,update,delete on test.test1 to lili@192.%; grant update,insert,select on test1.test2 to lili2@10.10.11.12;"
for st in sp.split(sqls2):
... print(st)
...
grant insert,update,delete on test.test1 to lili@192.%;
grant update,insert,select on test1.test2 to lili2@10.10.11.12; ----have been splited into. two lines

the differnence between two sqls is :

first sqls2 : lili@192.168.11.23
second sqls2: lili@192.%

sqlparse version is:

print(sp.version)
0.4.1

@Shawn001 Shawn001 changed the title sqlparse.split can't split sqls correctly sqlparse.split can't split sqls correctly in one case Oct 16, 2020
@andialbrecht
Copy link
Owner

@andialbrecht andialbrecht commented Oct 16, 2020

hm... I can't reproduce this issue:

>>> import sqlparse
>>> sqls2="grant insert,update,delete on test.test1 to lili@192.168.11.23; grant update,insert,select on test1.test2 to lili2@10.10.11.12;"
>>> for st in sqlparse.split(sqls2):
...     print(st)
...
grant insert,update,delete on test.test1 to lili@192.168.11.23;
grant update,insert,select on test1.test2 to lili2@10.10.11.12;
>>> print(len(sqlparse.split(sqls2)))
2
>>>

@Shawn001
Copy link
Author

@Shawn001 Shawn001 commented Oct 16, 2020

it doesn't work with ` backtick quotes.

import sqlparse
sqls2="grant insert,update,delete on test.test1 to lili@`192.168.11.23`; grant update,insert,select on test1.test2 to lili2@10.10.11.12;"
for st in sqlparse.split(sqls2):
... print(st)
...
grant insert,update,delete on test.test1 to lili@`192.168.11.23`; grant update,insert,select on test1.test2 to lili2@10.10.11.12;
print(len(sqlparse.split(sqls2)))
1

@andialbrecht
Copy link
Owner

@andialbrecht andialbrecht commented Oct 16, 2020

ah! Thanks! They were eaten up by githubs markdown machinery 😋

@andialbrecht
Copy link
Owner

@andialbrecht andialbrecht commented Oct 16, 2020

hm... but still not reproducable by me 🤔

>>> import sqlparse
>>> sqls2="grant insert,update,delete on test.test1 to lili@`192.168.11.23`; grant update,insert,select on test1.test2 to lili2@10.10.11.12;"
>>> for st in sqlparse.split(sqls2):
...     print(st)
...
grant insert,update,delete on test.test1 to lili@`192.168.11.23`;
grant update,insert,select on test1.test2 to lili2@10.10.11.12;
>>> print(len(sqlparse.split(sqls2)))
2

@Shawn001
Copy link
Author

@Shawn001 Shawn001 commented Oct 16, 2020

could you test with sqls2="grant insert,update,delete on `test`.`test1` to `lili`@`192.168.11.23`; grant update,insert,select on `test1`.`test2` to `lili2`@`10.10.11.12`;" ?

@andialbrecht
Copy link
Owner

@andialbrecht andialbrecht commented Oct 19, 2020

Thanks! I can reproduce it with the statement above. Here's a little bit more simplified example:

>>> sqlparse.split("grant foo to user1@`myhost`; grant bar to user1@`myhost`;")
['grant foo to user1@`myhost`; grant bar to user1@`myhost`;']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants