-
Notifications
You must be signed in to change notification settings - Fork 127
Add a support for CREATE TABLE queries #126
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9692d97
Add test_create_table - see #35
f57fccb
Black reformat
1ac0911
Merge branch 'master' into create-table-support
macbre 9bfdb1b
Merge branch 'master' into create-table-support
macbre dea85b7
Merge branch 'master' into create-table-support
macbre 79b9674
Merge branch 'master' into create-table-support
macbre c1f2783
Parser: add _is_create_table_query property
macbre afcd63a
Add test_create_table_as_select
macbre fb230c0
Proper handling of columns list in CREATE TABLE queries
macbre b76c632
Parser: improve docs
macbre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| from sql_metadata import Parser | ||
|
|
||
|
|
||
| def test_is_create_table_query(): | ||
| assert Parser("BEGIN")._is_create_table_query is False | ||
| assert Parser("SELECT * FROM `foo` ()")._is_create_table_query is False | ||
|
|
||
| assert Parser("CREATE TABLE `foo` ()")._is_create_table_query is True | ||
| assert ( | ||
| Parser( | ||
| "create table abc.foo as SELECT pqr.foo1 , ab.foo2 FROM foo pqr, bar ab" | ||
| )._is_create_table_query | ||
| is True | ||
| ) | ||
|
|
||
|
|
||
| def test_create_table(): | ||
| parser = Parser( | ||
| """ | ||
| CREATE TABLE `new_table` ( | ||
| `item_id` int(9) NOT NULL AUTO_INCREMENT, | ||
| `foo` varchar(16) NOT NULL DEFAULT '', | ||
| PRIMARY KEY (`item_id`,`foo`), | ||
| KEY `idx_foo` (`foo`) | ||
| ) CHARACTER SET utf8; | ||
| """ | ||
| ) | ||
|
|
||
| assert parser.tables == ["new_table"] | ||
| assert parser.columns == ["item_id", "foo"] | ||
|
|
||
|
|
||
| def test_create_table_as_select(): | ||
| parser = Parser( | ||
| """ | ||
| create table abc.foo | ||
| as SELECT pqr.foo1 , ab.foo2 | ||
| FROM foo pqr, bar ab; | ||
| """ | ||
| ) | ||
|
|
||
| assert parser.tables == ["abc.foo", "foo", "bar"] | ||
| assert parser.columns == ["foo.foo1", "bar.foo2"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@collerek - thanks for these two helpers 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to help :)