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

Comma Seperated ALTER TABLE comamnds causes Error Code 1054 #27

Open
LostInTheWoods opened this issue Aug 21, 2013 · 3 comments
Open

Comma Seperated ALTER TABLE comamnds causes Error Code 1054 #27

LostInTheWoods opened this issue Aug 21, 2013 · 3 comments

Comments

@LostInTheWoods
Copy link

The .patch script generated produces comma separated statements like this:

ALTER TABLE a ADD COLUMN b tinyint(1) NOT NULL DEFAULT '0' AFTER c
, ADD COLUMN d tinyint(1) NULL DEFAULT '1' AFTER f;

But this is a known problem and produces Error Code: 1054
http://bugs.mysql.com/bug.php?id=60650

A suggested fix is to use separate ALTER TABLE statements:
ALTER TABLE a ADD COLUMN b tinyint(1) NOT NULL DEFAULT '0' AFTER c
ALTER TABLE a ADD COLUMN d tinyint(1) NULL DEFAULT '1' AFTER f;

Can this be implemented?

@mmatuson
Copy link
Owner

Yes, this can be implemented. I had plans to fix this but have not had the time to do it. Pull requests welcome.

@LostInTheWoods
Copy link
Author

Unfortunately, I don't know Python, so I don't feel able to contribute. But this tool is exactly what I need to nightly schema comparisons with CRON. If you manage to find time, that would be great. Thanks.

@vingc
Copy link

vingc commented Nov 4, 2013

I have coded one AWK script to improve the .patch script, content like this:
#!/bin/bash

################################## VARIABLES & FUNCTIONS ######################################
SRC_PATCH_SCRIPT="$1"
DST_PATCH_SCRIPT="$2"

################################## MAIN BODY ##############################################
awk '
BEGIN{
FS = ","
##% print "FS:" FS
}

($1 ~ /^ALTER TABLE [a-zA-Z0-9_]*/) && (NF >= 2) {
OFS="\n"
ret = match($1,/^ALTER TABLE [a-zA-Z0-9_-]*/)
if(ret == 0)
{
print $0
next
}
prefix = substr($1,RSTART,RLENGTH)
##print "prefix:" prefix
tmpRowStr = substr($1,RSTART+RLENGTH,length($1)-(RLENGTH+RSTART)+1)
##% print "tmpRowStr:" tmpRowStr

for(i=2; i<=NF; i++)
{
   ret = match($i,/^ ADD|DROP|MODIFY COLUMN `[a-zA-Z0-9_-]*`/)
   if(ret == 0)
   {

##% this field belongs to current Row
tmpRowStr = tmpRowStr "," $i
}
else
{
##% output old Row & create new Row
print prefix tmpRowStr ";"
tmpRowStr = $i
}
}
##% output the last field ,it belongs to new Row and has a ";" already.
print prefix tmpRowStr
next
}

1 {print $0}
' "$SRC_PATCH_SCRIPT" >"$DST_PATCH_SCRIPT"

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

No branches or pull requests

3 participants