Showing 1 changed files with 13 additions and 13 deletions
+13 -13
.fgfs/fgaddon
... ...
@@ -2,7 +2,7 @@
2 2
 
3 3
 set -e
4 4
 
5
-declare -A data=(
5
+declare -A datatypes=(
6 6
         [/sim/description]=text
7 7
         [/sim/long-description]=text
8 8
         [/sim/author]=text
... ...
@@ -109,7 +109,7 @@ function trap_exit () {
109 109
     fi
110 110
 
111 111
     for data_presence_check in ${missing_data_check[@]}; do
112
-        if [[ -v data[$data_presence_check] ]]; then
112
+        if [[ -v datatypes[$data_presence_check] ]]; then
113 113
             local missing_data=$(sqlite_request "select count(setxml.file)
114 114
                                                  from aircrafts inner join setxml
115 115
                                                  where aircrafts.id = setxml.variantof and setxml.\`$data_presence_check\` = ''")
... ...
@@ -161,9 +161,8 @@ function update_database () {
161 161
     echo $(sqlite_request "select printf('[ %i/%i ] $ac', count(sx), count(distinct ac)) from recover_setxml")
162 162
 
163 163
     for sx in $(sqlite_request "select distinct sx from recover_setxml where ac = '$ac'"); do
164
-        for col in ${!data[@]}; do
165
-            data[$col]=
166
-        done
164
+        unset data
165
+        declare -A data
167 166
 
168 167
         echo " -> $sx"
169 168
         getfromrepo ${ac}/$sx-set.xml > $setxml
... ...
@@ -224,7 +223,7 @@ function update_database () {
224 223
             fi
225 224
 
226 225
             # continue parsing (while loop) until everything's found
227
-            for col in ${!data[@]}; do
226
+            for col in ${!datatypes[@]}; do
228 227
                 test -z "${data[$col]}" && continue 2
229 228
             done
230 229
             break # everything's found
... ...
@@ -239,10 +238,11 @@ function update_database () {
239 238
             insert_col='file, variantof, '
240 239
             update_values=''
241 240
             for col in ${!data[@]}; do
241
+                test ${datatypes[$col]%% *} == 'text' && single_quote="'" || single_quote=""
242 242
                 insert_col+="\`$col\`, "
243
-                insert_values+="'${data[$col]//\'/\'\'}', "
243
+                insert_values+="$single_quote${data[$col]//\'/\'\'}$single_quote, "
244 244
                 if test -n "${data[$col]}"; then
245
-                    update_values+="\`$col\` = '${data[$col]//\'/\'\'}', "
245
+                    update_values+="\`$col\` = $single_quote${data[$col]//\'/\'\'}$single_quote, "
246 246
                 fi
247 247
             done
248 248
             sqlite_request "insert into setxml (${insert_col%,*}, installed) values (${insert_values%,*}, 0)
... ...
@@ -344,17 +344,17 @@ trap trap_exit EXIT
344 344
 stty -echoctl
345 345
 
346 346
 declare -A hangar
347
-data_pattern=$(printf "%s|" ${!data[@]})
347
+data_pattern=$(printf "%s|" ${!datatypes[@]})
348 348
 data_pattern=${data_pattern:0:-1}
349
-data_test_null=$(printf '${data[%s]}' ${!data[@]})
349
+data_test_null=$(printf '${data[%s]}' ${!datatypes[@]})
350 350
 
351 351
 if test -e $database; then
352 352
     cp $database $in_ram_database
353 353
 
354 354
     sql_cols=$(sqlite_request "pragma table_info(setxml)" | awk -F'|' '{printf("%s %s ", $2, $3)}')
355 355
     script_cols="file text variantof integer "
356
-    for col in ${!data[@]}; do
357
-        script_cols+="$col ${data["$col"]} "
356
+    for col in ${!datatypes[@]}; do
357
+        script_cols+="$col ${datatypes["$col"]%% *} "
358 358
     done
359 359
     script_cols+="installed integer " # last space is important
360 360
     if test "$sql_cols" != "$script_cols"; then
... ...
@@ -399,7 +399,7 @@ sqlite_request 'create unique index if not exists "index_aircrafts" on aircrafts
399 399
 sqlite_request "create table if not exists setxml (
400 400
                     file text,
401 401
                     variantof integer,
402
-                    $(for col in ${!data[@]}; do printf "'%s' %s, " $col ${data[$col]}; done)
402
+                    $(for col in ${!datatypes[@]}; do printf "'%s' %s, " $col "${datatypes[$col]}"; done)
403 403
                     installed integer)"
404 404
 
405 405
 sqlite_request 'create unique index if not exists "index_setxml" on setxml (file, variantof)'