All pastes #1711080 Raw Edit

mess around w/ updatedb

public shellscript v1 · immutable
#1711080 ·published 2009-12-11 15:44 UTC
rendered paste body
  # Remove *ALL* linebreaks from the updatedb.msql file        while read line ; do printf %s "$line" ; done < updatedb.msql > mega  # Add linebreaks after every ") ;". ") ;" occurs at the end of a table def.        perl -p -e 's,\) ;,) ;\n,g' mega | grep ^create | grep table > create-tables  # Process all "create table" statements  # For every column definition in a table definition (ie. in a line),  # generate a "alter table $tbl add" and "alter table $tbl modify"  # statement.  # Effect:  # For every col. def. in a table def., there will be a statement  # which would add a "new" column to an existing table and also  # a statement, which would modify the size/type of an existing  # column def..        sed 's,^create table ,,' create-tables | while read L; do          # Name of the table is at the beginning of the line,          # before the first (          tbl="${L%%(*}"           # All the column def.s are in $tbl(...)          # Cut away everything before the first "(" (ie. the name          # of the table)          cs="${L#*(}"           # Now process every column definition seperately          echo "${cs%);}" | sed 's/,/\n/g' | grep -v '^$' | while read C; do            # Generate alter table add and modify lines            printf 'alter table %s add\n (\n\t%s\n ) ;\n' "$tbl" "$C"            printf 'alter table %s modify\n (\n\t%s\n ) ;\n' "$tbl" "$C"             echo          done        done > rieterTables.msql