s4

changeset 180:59bd085848ec

Group name change affects to blog owner * Now query() accepts stdin. * Update val of key='owner' in blog_s at group name change.
author HIROSE Yuuji <yuuji@gentei.org>
date Fri, 26 Feb 2016 22:36:04 +0859
parents 479b57681014
children fcfed35ca6d8
files s4-funcs.sh
diffstat 1 files changed, 28 insertions(+), 5 deletions(-) [+]
line diff
     1.1 --- a/s4-funcs.sh	Sat Feb 20 10:03:59 2016 +0859
     1.2 +++ b/s4-funcs.sh	Fri Feb 26 22:36:04 2016 +0859
     1.3 @@ -315,10 +315,12 @@
     1.4    rm -rf $tmpfiles
     1.5  }
     1.6  query() {
     1.7 -  cat<<EOF >&5
     1.8 -.once $sqo
     1.9 -$@
    1.10 -EOF
    1.11 +  echo ".once $sqo" >&5
    1.12 +  if [ -z "$1" ]; then
    1.13 +    cat
    1.14 +  else
    1.15 +    echo "$@"
    1.16 +  fi >&5
    1.17    cat $sqo
    1.18  }
    1.19  
    1.20 @@ -2260,7 +2262,28 @@
    1.21         val=`getparquote $col`
    1.22         [ -z "$val" ] && continue
    1.23         err  query "update $tbl set $col=$val where rowid=$rowid"
    1.24 -       query "update $tbl set $col=$val where rowid=$rowid;"
    1.25 +       ## XX: THIS IS DIRTY hack to ensure non-foreign key in blog_s
    1.26 +       sql="update $tbl set $col=$val where rowid=$rowid;"
    1.27 +       if [ x"$tbl" = x"grp" -a x"$col" = x"gname" \
    1.28 +	     -o x"tbl" = x"user" -a x"$col" = x"name" ]; then
    1.29 +	 ## User name cannot be changed with interface provided with this
    1.30 +	 ## script.  But we offer the trigger to change owner user
    1.31 +	 ## of blog_s table.
    1.32 +	 err "select quote($col) from $tbl where rowid=$rowid;"
    1.33 +	 old=`query "select quote($col) from $tbl where rowid=$rowid;"`
    1.34 +	 cat<<-EOF | query
    1.35 +		BEGIN;
    1.36 +		$sql
    1.37 +		update blog_s set val=$val
    1.38 +		where key='owner' and val=$old;
    1.39 +		COMMIT;
    1.40 +		EOF
    1.41 +	 ## XX: DIRTY Hack Ends here
    1.42 +	 ## We should keep blog's owner as a single column which has
    1.43 +	 ## foreign key constraint with primary key of grp/user.
    1.44 +       else
    1.45 +	 query "$sql"
    1.46 +       fi
    1.47       done
    1.48       # Then, set up $pval for further insertion of tbl_s and tbl_m
    1.49       for col in `gettblpkey $tbl`; do