1 # ===================================================================== 2 # makedb.rc: (re)build the flat-file database that can be associated 3 # with a TW page. 4 # 5 # Copyright (c) 2012 Carlo Strozzi 6 # 7 # This program is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; version 2 dated June, 1991. 10 # 11 # This program is distributed in the hope that it will be useful, 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 # GNU General Public License for more details. 15 # 16 # You should have received a copy of the GNU General Public License 17 # along with this program; if not, write to the Free Software 18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 # 20 # ===================================================================== 21 22 # Extension "+fsc" stands for "field-schema". 23 csaOpen --fast --relaxed $tw_pstem+$TNS_DB_SCHEMA+fsc || csaExit.fault 24 tmp_schema = $CSA_RESULT 25 26 csvtotable --input $'cgi.attachment' | 27 sorttable -u --output $tmp_schema Column Table 28 csaStatus || csaExit.fault 0003 csvtotable/sorttable 29 30 # Extension "+tsc" stands for "table-schema", i.e. "file-schema". 31 csaOpen --fast --relaxed $tw_pstem+$TNS_DB_SCHEMA+tsc 32 33 # Make sure column and table names are compliant. 34 * = `{awktable -i $tmp_schema -- 'BEGIN{ 35 # Print file-schema table header. 36 print "\001Table\t\001Path\t\001Edit" > "'$CSA_RESULT'" 37 } 38 $Column !~ /^[a-zA-Z][_a-zA-Z0-9]*[a-zA-Z0-9]$/ || 39 $Table !~ /^[a-zA-Z][-_a-zA-Z0-9]*[a-zA-Z0-9]$/ {exit 1} 40 {print $Table} 41 seen_[$Table] == "" { 42 print $Table,"'$tw_pstem+'" $Table "+rdb",\ 43 "'$tw_pstem+'" $Table "+edt" > "'$CSA_RESULT'" 44 seen_[$Table] = $Table 45 }'} 46 47 ~ $bqstatus 0 || csaExit.fault 1052 48 49 db_tables = $*; csaUniq db_tables; * = $db_tables 50 51 # Make rebuilding atomic by using TPC. 52 while (!~ $1 ()) { 53 csaIsFullPath --exists --quiet $tw_pstem+$1.csv || 54 csaExit.fault 1053 $1.csv 55 csaOpen --fast --relaxed $tw_pstem+$1+rdb || csaExit.fault 56 csvtotable --input $tw_pstem+$1.csv | sorttable | 57 istable --echo > $CSA_RESULT 58 csaStatus || csaExit.fault 0003 csvtotable/sorttable/istable 59 shift 60 } 61 62 # End of program.