-
Notifications
You must be signed in to change notification settings - Fork 0
Add support for ADD UNIQUE indexes #3
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
base: master
Are you sure you want to change the base?
Conversation
| # Check if it's a single-line statement (ends with semicolon) | ||
| if( /;$/ ) { | ||
| # Process immediately | ||
|
|
||
| # Check if this is ADD INDEX or ADD UNIQUE | ||
| if( /ADD INDEX|add index|ADD UNIQUE|add unique/ ) { | ||
| isAddIndex = 1 | ||
|
|
||
| # Extract table name | ||
| if( match( $0, /`[^`]+/ ) ){ | ||
| alterTableName = substr( $0, RSTART+1, RLENGTH-1 ) | ||
| } | ||
|
|
||
| # Extract index name | ||
| if( match( $0, /(ADD INDEX|add index|ADD UNIQUE|add unique) `[^`]+/ ) ){ | ||
| indexMatch = substr( $0, RSTART, RLENGTH ) | ||
| if( match( indexMatch, /`[^`]+$/ ) ){ | ||
| alterIndexName = substr( indexMatch, RSTART+1, RLENGTH-1 ) | ||
| } | ||
| } | ||
|
|
||
| # Extract column list | ||
| if( isAddIndex && alterTableName != "" && alterIndexName != "" ) { | ||
| if( match( alterStatement, /\([^)]+\)/ ) ){ | ||
| columnList = substr( alterStatement, RSTART+1, RLENGTH-2 ) | ||
| gsub( /[ \t\n\r]+/, " ", columnList ) | ||
| gsub( /^ +| +$/, "", columnList ) | ||
| gsub( /`/, "\"", columnList ) | ||
|
|
||
| # Check if UNIQUE | ||
| uniquePrefix = "" | ||
| if( alterStatement ~ /ADD UNIQUE|add unique/ ) { | ||
| uniquePrefix = "UNIQUE " | ||
| } | ||
|
|
||
| print "CREATE " uniquePrefix "INDEX \"idx_" alterTableName "_" alterIndexName "\" ON \"" alterTableName "\" (" columnList ");" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # Reset | ||
| inAlterTable = 0 | ||
| } |
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.
I don't really understand why all these lines need to be added: seems that unique indexes are handled a bit lower in this file.
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.
unfortunately, can't say too much about this, but as I see according to the search over the previous version - ADD UNIQUE / UNIQUE does not appear anywhere in a file and current include. I tested several times and no error occurs.
Resolve issue when ADD UNIQUE skipped