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 wrap: on
line diff
--- a/s4-funcs.sh	Sat Feb 20 10:03:59 2016 +0859
+++ b/s4-funcs.sh	Fri Feb 26 22:36:04 2016 +0859
@@ -315,10 +315,12 @@
   rm -rf $tmpfiles
 }
 query() {
-  cat<<EOF >&5
-.once $sqo
-$@
-EOF
+  echo ".once $sqo" >&5
+  if [ -z "$1" ]; then
+    cat
+  else
+    echo "$@"
+  fi >&5
   cat $sqo
 }
 
@@ -2260,7 +2262,28 @@
        val=`getparquote $col`
        [ -z "$val" ] && continue
        err  query "update $tbl set $col=$val where rowid=$rowid"
-       query "update $tbl set $col=$val where rowid=$rowid;"
+       ## XX: THIS IS DIRTY hack to ensure non-foreign key in blog_s
+       sql="update $tbl set $col=$val where rowid=$rowid;"
+       if [ x"$tbl" = x"grp" -a x"$col" = x"gname" \
+	     -o x"tbl" = x"user" -a x"$col" = x"name" ]; then
+	 ## User name cannot be changed with interface provided with this
+	 ## script.  But we offer the trigger to change owner user
+	 ## of blog_s table.
+	 err "select quote($col) from $tbl where rowid=$rowid;"
+	 old=`query "select quote($col) from $tbl where rowid=$rowid;"`
+	 cat<<-EOF | query
+		BEGIN;
+		$sql
+		update blog_s set val=$val
+		where key='owner' and val=$old;
+		COMMIT;
+		EOF
+	 ## XX: DIRTY Hack Ends here
+	 ## We should keep blog's owner as a single column which has
+	 ## foreign key constraint with primary key of grp/user.
+       else
+	 query "$sql"
+       fi
      done
      # Then, set up $pval for further insertion of tbl_s and tbl_m
      for col in `gettblpkey $tbl`; do

yatex.org