don't encourage sqlite to store floating point values as text
This commit is contained in:
parent
58b9d78afa
commit
5154f61f1b
50
atom
50
atom
@ -38,6 +38,8 @@ declare -r \
|
|||||||
\
|
\
|
||||||
oldIFS="$IFS"
|
oldIFS="$IFS"
|
||||||
|
|
||||||
|
shopt -s extglob
|
||||||
|
|
||||||
#parse arguments
|
#parse arguments
|
||||||
OPTERR=0
|
OPTERR=0
|
||||||
while getopts ':c:l:T:F:hD' opt
|
while getopts ':c:l:T:F:hD' opt
|
||||||
@ -273,7 +275,7 @@ openDatabase() {
|
|||||||
fi
|
fi
|
||||||
sqlite3 "$database" < $schema
|
sqlite3 "$database" < $schema
|
||||||
fi
|
fi
|
||||||
sqlite3 "$database" \
|
sqlite3 -bail "$database" \
|
||||||
< "$tempdir/sqlite.in" \
|
< "$tempdir/sqlite.in" \
|
||||||
> "$tempdir/sqlite.out" &
|
> "$tempdir/sqlite.out" &
|
||||||
exec 3> "$tempdir"/sqlite.in
|
exec 3> "$tempdir"/sqlite.in
|
||||||
@ -346,12 +348,17 @@ Insert() {
|
|||||||
(( ${#insert_keys} )) && insert_keys+=","
|
(( ${#insert_keys} )) && insert_keys+=","
|
||||||
insert_keys+='`'"$key"'`'
|
insert_keys+='`'"$key"'`'
|
||||||
(( ${#insert_values} )) && insert_values+=","
|
(( ${#insert_values} )) && insert_values+=","
|
||||||
if [[ $value == NULL ]]
|
case $value in
|
||||||
then
|
'NULL')
|
||||||
insert_values+="NULL"
|
insert_values+="NULL"
|
||||||
else
|
;;
|
||||||
insert_values+='"'"${value//\"/\"\"}"'"'
|
+([0-9])?(.+([0-9])))
|
||||||
fi
|
insert_values+=$value
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
insert_values+='"'"${value//\"/\"\"}"'"'
|
||||||
|
;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
echo "INSERT INTO $table" \
|
echo "INSERT INTO $table" \
|
||||||
"( $insert_keys )" \
|
"( $insert_keys )" \
|
||||||
@ -389,7 +396,17 @@ Update(){
|
|||||||
what=value
|
what=value
|
||||||
;;
|
;;
|
||||||
value)
|
value)
|
||||||
set_statement="${set_statement}="'"'"${argument//\"/\"\"}"'"'
|
case $argument in
|
||||||
|
'NULL')
|
||||||
|
set_statement+=" is NULL"
|
||||||
|
;;
|
||||||
|
+([0-9])?(.+([0-9])))
|
||||||
|
set_statement+=" = $argument"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set_statement+=" = "'"'"${argument//\"/\"\"}"'"'
|
||||||
|
;;
|
||||||
|
esac
|
||||||
what=key
|
what=key
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -397,12 +414,17 @@ Update(){
|
|||||||
while read key operator value
|
while read key operator value
|
||||||
do
|
do
|
||||||
(( ${#where_statement} )) && where_statement+=( "AND" )
|
(( ${#where_statement} )) && where_statement+=( "AND" )
|
||||||
if [[ $value == NULL ]]
|
case $value in
|
||||||
then
|
'NULL')
|
||||||
where_statement+=( "$key is NULL" )
|
where_statement+=( "$key is NULL" )
|
||||||
else
|
;;
|
||||||
where_statement+=( "$key $operator "'"'"${value//\"/\"\"}"'"' )
|
+([0-9.]))
|
||||||
fi
|
where_statement+=( "$key $operator $value" )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
where_statement+=( "$key $operator "'"'"${value//\"/\"\"}"'"' )
|
||||||
|
;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
echo "UPDATE '$table' SET" \
|
echo "UPDATE '$table' SET" \
|
||||||
"$set_statement" \
|
"$set_statement" \
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user