changeset 636:b73ef3fd0e19

Table update done in 1 .read outside of shell loop.
author HIROSE Yuuji <yuuji@gentei.org>
date Wed, 29 Apr 2020 19:03:17 +0900
parents ae37fefb7a2b
children 2b1339d50b30
files s4-funcs.sh
diffstat 1 files changed, 36 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/s4-funcs.sh	Wed Apr 29 18:28:47 2020 +0900
+++ b/s4-funcs.sh	Wed Apr 29 19:03:17 2020 +0900
@@ -3550,6 +3550,7 @@
     ## Insertion to master table, done
   fi
      
+  transaction=$tmpd/sqlfile.sql; touch $transaction
   for kt in s m; do
     tb2=${tbl}_$kt
     for col in `gettbl_${kt}_cols $tbl`; do
@@ -3606,15 +3607,25 @@
 
 	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
+	  if [ -n "$transaction" ]; then
+	    cat<<-EOF >> $transaction
+		$sql
+		DELETE FROM $tb2 WHERE type='string' AND val='';
+		EOF
+	  else
+	    query "$sql
+delete from $tb2   where type='string' and val='';"
+	    ## err repl:normal done
+	  fi
 	else
+	  # Binary update line is TOO LONG to pipelining
 	  sqlfile="$tmpd/sqlf.$$"
-	  echo "$sql" > $sqlfile
-	  ## err repl:sqlfile=`ls -lF $sqlfile`
-	  query ".read $sqlfile"
-	  ## err repl:done
+	  if [ -n "$transaction" ]; then
+	    echo "$sql" >> $transaction
+	  else
+	    echo "$sql" > $sqlfile
+	    query ".read $sqlfile"
+	  fi
 	fi
 	# Rest of kt==m: set multiple mode
 	nr=`getparcount $col`
@@ -3674,18 +3685,32 @@
 	sql="replace into $tb2 values($pval, \"$col\", $type, $val, $bin);"
 	if [ x"$bin" = x"NULL" ]; then
 	  ## err Normal-query: `echo $sql`
-	  query "$sql"
+	  if [ -n "$transaction" ]; then
+	    echo "$sql" >> $transaction
+	  else
+	    query "$sql"
+	  fi
 	else
 	  sqlfile="$tmpd/query.$$"
-	  echo "$sql" > $sqlfile
 	  ## err sqlfile=`ls -lF $sqlfile`
-	  query ".read $sqlfile"
+	  if [ -n "$transaction" ]; then
+	    echo "$sql" >> $transaction
+	  else
+	    echo "$sql" > $sqlfile
+	    query ".read $sqlfile"
+	  fi
 	fi
 	## err p2t done
       done
     done
   done
-  return 0
+  [ -n "$transaction" -a -s "$transaction" ] && cat <<-EOF | query
+	-- We cannot use transaction here, because groupupdate may use it.
+	SAVEPOINT pa2table_insert;
+	.read $transaction
+	RELEASE SAVEPOINT pa2table_insert;
+	EOF
+  return $?
   ##err donee
 )
 genform() {

yatex.org