Mercurial > hgrepos > hgweb.cgi > s4
changeset 285:e87d6bc1e62a
Remove old function and unneccesary subshelling
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Mon, 15 Aug 2016 10:08:27 +0859 |
parents | 28284f903ddc |
children | 1c4f13f0813e |
files | s4-funcs.sh |
diffstat | 1 files changed, 172 insertions(+), 200 deletions(-) [+] |
line wrap: on
line diff
--- a/s4-funcs.sh Sat Aug 06 22:39:52 2016 +0859 +++ b/s4-funcs.sh Mon Aug 15 10:08:27 2016 +0859 @@ -2691,33 +2691,34 @@ fi fi fi - # XX: Subshelling here is unnecessary 2015-07-05 - (ts=${tbl}_s tm=${tbl}_m val="" pval="" formaster="" - if [ -n "$rowid" ]; then - # Update of existing record - for col in `gettblcols $tbl`; do - val=`getparquote $col` - [ -z "$val" ] && continue - err 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 + + ts=${tbl}_s tm=${tbl}_m val="" pval="" formaster="" + if [ -n "$rowid" ]; then + # Update of existing record + for col in `gettblcols $tbl`; do + val=`getparquote $col` + [ -z "$val" ] && continue + err 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. + ## 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. + aa else query "$sql" fi @@ -2727,200 +2728,171 @@ val=`query "select $col from $tbl where rowid=$rowid;"|sed -e 's/\"/\"\"/g'` pval="$pval${pval:+, }\"$val\"" done - else - # New entry - # Generate values() for primary keys - for col in `gettblpkey $tbl`; do - # Genuine primary keys for _m and _s - val=`getvalquote $tbl $col` - [ -z "$val" ] && continue - pval="$pval${pval:+, }$val" - done + else + # New entry + # Generate values() for primary keys + for col in `gettblpkey $tbl`; do + # Genuine primary keys for _m and _s + val=`getvalquote $tbl $col` + [ -z "$val" ] && continue + pval="$pval${pval:+, }$val" + done err pval=$pval - for col in `gettblfkey $tbl`; do - # args for values() to insertion into master table - val=`getvalquote $tbl $col` - [ -z "$val" ] && continue - formaster=$formaster"${formaster:+, }$val" - done - formaster="$pval${formaster:+, }$formaster" + for col in `gettblfkey $tbl`; do + # args for values() to insertion into master table + val=`getvalquote $tbl $col` + [ -z "$val" ] && continue + formaster=$formaster"${formaster:+, }$val" + done + formaster="$pval${formaster:+, }$formaster" err formaster=$formaster - if [ -z "$formaster" ]; then - echo "項目を全て埋めてください" | html pre - return 1 - fi - err "replace into $tbl values($formaster);" - query "replace into $tbl values($formaster);" - ## Insertion to master table, done - fi + if [ -z "$formaster" ]; then + echo "項目を全て埋めてください" | html pre + return 1 + fi + err "replace into $tbl values($formaster);" + query "replace into $tbl values($formaster);" + ## Insertion to master table, done + fi - for kt in s m; do - tb2=${tbl}_$kt - for col in `gettbl_${kt}_cols $tbl`; do - ptype=`getpartype $col "limit 1"` + for kt in s m; do + tb2=${tbl}_$kt + for col in `gettbl_${kt}_cols $tbl`; do + ptype=`getpartype $col "limit 1"` - # First, check update of existing entries in _m - if [ $kt = m ]; then - # sessID|address.1.22|string|Somewhere-x.y.z - sql="" + # First, check update of existing entries in _m + if [ $kt = m ]; then + # sessID|address.1.22|string|Somewhere-x.y.z + sql="" err dots from query "select var from par where var like '$col.%';" - for v in `query "select var from par where var like '$col.%';"`; do - # v=address.1.22 - st_rowid=${v##*.} - origcol=${v%%.*} # original column derived from + for v in `query "select var from par where var like '$col.%';"`; do + # v=address.1.22 + st_rowid=${v##*.} + origcol=${v%%.*} # original column derived from err Updating for $v st_rowid=$st_rowid, partype=`getpartype $v` - ##case `getpartype $v` in - err CASE `gettbl_coltype $tbl/$origcol` in - err edit flag = `getpar action.$v` - case `getpar action.$v` in - rm) - if [ x`getpar confirm.$v` = x"yes" ]; then - newsql="delete from $tb2" - else - echo "削除確認未チェック" | html p - fi ;; - edit) - case `gettbl_coltype $tbl/$origcol` in - image|document|binary) - file=$tmpd/`getparfilename $v` - err type=file=$file - [ -z "$file" ] && continue - bn=${file##*/} - bin="X'"$(hexize $file)"'" - ct=`file --mime-type $file|cut -d' ' -f2` - type=\"file:$ct\" - newsql="update $tb2 set val='$bn', type=$type, bin=$bin" - cachedir=`getcachedir "$tbl/$rowid"` - err getcache tbl/rowid=$tbl/$rowid, rm -r $cachedir - rm -r $cachedir - ;; - *) - newsql="update $tb2 set val=(select val from par where var \ + ##case `getpartype $v` in + err CASE `gettbl_coltype $tbl/$origcol` in + err edit flag = `getpar action.$v` + case `getpar action.$v` in + rm) + if [ x`getpar confirm.$v` = x"yes" ]; then + newsql="delete from $tb2" + else + echo "削除確認未チェック" | html p + fi ;; + edit) + case `gettbl_coltype $tbl/$origcol` in + image|document|binary) + file=$tmpd/`getparfilename $v` + err type=file=$file + [ -z "$file" ] && continue + bn=${file##*/} + bin="X'"$(hexize $file)"'" + ct=`file --mime-type $file|cut -d' ' -f2` + type=\"file:$ct\" + newsql="update $tb2 set val='$bn', type=$type, bin=$bin" + cachedir=`getcachedir "$tbl/$rowid"` + err getcache tbl/rowid=$tbl/$rowid, rm -r $cachedir + rm -r $cachedir + ;; + *) + newsql="update $tb2 set val=(select val from par where var \ like '$col.%.$st_rowid')" - ;; - esac - ;; - *) # maybe "keep", do not modify value - continue - ;; - esac - # err newsql=$newsql - sql=$sql$nl"$newsql where rowid=$st_rowid;" - done + ;; + esac + ;; + *) # maybe "keep", do not modify value + continue + ;; + esac + # err newsql=$newsql + sql=$sql$nl"$newsql where rowid=$st_rowid;" + done - if [ x"$bin" = x"NULL" ]; then - err repl:normal sql=`echo $sql` - query "$sql + if [ x"$bin" = x"NULL" ]; then + err repl:normal sql=`echo $sql` + query "$sql delete from $tb2 where type='string' and val='';" - err repl:normal done - else - sqlfile="$tmpd/sqlf.$$" - echo "$sql" > $sqlfile - err repl:sqlfile=`ls -lF $sqlfile` - query ".read $sqlfile" - err repl:done - fi - # Rest of kt==m: set multiple mode - nr=`getparcount $col` - else - nr=1 # for kt==s, number of records is 1 - fi + err repl:normal done + else + sqlfile="$tmpd/sqlf.$$" + echo "$sql" > $sqlfile + err repl:sqlfile=`ls -lF $sqlfile` + query ".read $sqlfile" + err repl:done + fi + # Rest of kt==m: set multiple mode + nr=`getparcount $col` + else + nr=1 # for kt==s, number of records is 1 + fi - i=0 - while [ $i -lt $nr ]; do - limit="limit 1 offset $i" - i=$((i+1)) # increase beforehand against continue - val=`getvalquote $tbl $col "$limit"` - [ -z "$val" -o x"$val" = x'""' -o x"$val" = x"NULL" ] && continue + i=0 + while [ $i -lt $nr ]; do + limit="limit 1 offset $i" + i=$((i+1)) # increase beforehand against continue + val=`getvalquote $tbl $col "$limit"` + [ -z "$val" -o x"$val" = x'""' -o x"$val" = x"NULL" ] && continue err $col=$val - bin=NULL + bin=NULL err partype$col=`getpartype $col "$limit"` - case $ptype in - file) file=$tmpd/`getparfilename $col "$limit"` + case $ptype in + file) file=$tmpd/`getparfilename $col "$limit"` err parfile-$col=$file - [ -z "$file" ] && continue - bin="X'"$(hexize $file)"'" - ct=`file --mime-type $file|cut -d' ' -f2` - type=\"file:$ct\" ;; - "*"*) continue ;; # foreign table - *) type=\"string\" ;; - esac - case `gettbl_coltype $tbl/$col` in - password) # special care for password - # name={password,pswd1,pswd2} - p1=`getpar pswd1 "$limit"` - if [ -z "$p1" ]; then - continue # SKIP password setting, if p1 is empty - else - pswd=`getpar pswd "$limit"` p2=`getpar pswd2 "$limit"` + [ -z "$file" ] && continue + bin="X'"$(hexize $file)"'" + ct=`file --mime-type $file|cut -d' ' -f2` + type=\"file:$ct\" ;; + "*"*) continue ;; # foreign table + *) type=\"string\" ;; + esac + case `gettbl_coltype $tbl/$col` in + password) # special care for password + # name={password,pswd1,pswd2} + p1=`getpar pswd1 "$limit"` + if [ -z "$p1" ]; then + continue # SKIP password setting, if p1 is empty + else + pswd=`getpar pswd "$limit"` p2=`getpar pswd2 "$limit"` ## err pswd=$pswd - if pwcheck "$pswd"; then - if [ x"$p1" = x"$p2" ]; then - case "$p1" in - ??????????*) ;; - *) echo "パスワードは10字以上にしてください。" | html p - return 6;; - esac - val="\"`echo $p1|mypwhash`\"" - else - echo "2つの新パスワード不一致" | html p - return 7 - fi - else - echo "旧パスワード違います" | html p - return 8 - fi - fi - ;; - esac - err p2t: "replace into $tb2 values($pval, \"$col\", $type, $val, bin...);" - #query "replace into $tb2 values($pval, \"$col\", $type, $val, $bin);" - sql="replace into $tb2 values($pval, \"$col\", $type, $val, $bin);" - if [ x"$bin" = x"NULL" ]; then - err Normal-query: `echo $sql` - query "$sql" - else - sqlfile="$tmpd/query.$$" - echo "$sql" > $sqlfile - err sqlfile=`ls -lF $sqlfile` - query ".read $sqlfile" - fi - err p2t done - done - done - done - return 0 - err donee) + if pwcheck "$pswd"; then + if [ x"$p1" = x"$p2" ]; then + case "$p1" in + ??????????*) ;; + *) echo "パスワードは10字以上にしてください。" | html p + return 6;; + esac + val="\"`echo $p1|mypwhash`\"" + else + echo "2つの新パスワード不一致" | html p + return 7 + fi + else + echo "旧パスワード違います" | html p + return 8 + fi + fi + ;; + esac + err p2t: "replace into $tb2 values($pval, \"$col\", $type, $val, bin...);" + #query "replace into $tb2 values($pval, \"$col\", $type, $val, $bin);" + sql="replace into $tb2 values($pval, \"$col\", $type, $val, $bin);" + if [ x"$bin" = x"NULL" ]; then + err Normal-query: `echo $sql` + query "$sql" + else + sqlfile="$tmpd/query.$$" + echo "$sql" > $sqlfile + err sqlfile=`ls -lF $sqlfile` + query ".read $sqlfile" + fi + err p2t done + done + done + done + return 0 + ##err donee ) -par2table_old() { - # copy current parameters of par into destination table - # $1=dst-table $2=definition-file - # Using $user and $session - rowid=`getpar rowid` - if [ -n "$rowid" ]; then - rm=`getpar rm` cfm=`getpar confirm` - if [ x"$rm$cfm" = x"yesyes" ]; then - sq $db "delete from $1 where rowid=$rowid and owner=\"$user\"" - return - fi - fi - cat $2 \ - | (cols="" - while IFS=: read prompt name type args; do - [ x"$name" = x"stage" ] && continue - if [ -n "$rowid" ]; then - val=`getpar $name|sed -e 's/\"/\"\"/g'` - sq $db "update $1 set $name=\"$val\" where rowid=$rowid and owner=\"$user\"" - else - eav=$eav${eav+,}" max(case var when '$name' then val end)" - fi - done - [ -n "$rowid" ] && return - cond="where sessid='$session' group by sessid" - sq $db "replace into $1 select $eav,\"$user\" from par $cond" - # Think over again about putting $user - ) -} genform() { # $1 = form definition file # $2, $3 (optional)= table name and ROWID