InsertOrUpdate SQL function
This commit is contained in:
parent
a6f4b94099
commit
c6e84b1056
42
atom
42
atom
@ -348,6 +348,48 @@ Update(){
|
||||
"${where_statement[@]}" \
|
||||
";" >&3
|
||||
}
|
||||
InsertIfUnset() {
|
||||
#InsertIfUnset table [no_id] < key value \n key value
|
||||
local \
|
||||
table="$1" \
|
||||
no_id="${2:-0}" \
|
||||
column \
|
||||
key \
|
||||
keys \
|
||||
results \
|
||||
value \
|
||||
values
|
||||
while read key value
|
||||
do
|
||||
keys+=( "$key" )
|
||||
values+=( "$value" )
|
||||
done
|
||||
if (( no_id ))
|
||||
then
|
||||
column="${keys[0]}"
|
||||
else
|
||||
column='id'
|
||||
fi
|
||||
if ! results=$(
|
||||
Select "$table" "$column" < <(
|
||||
for key in ${!keys[@]}
|
||||
do
|
||||
echo "${keys[$key]}" "${values[$key]}"
|
||||
done
|
||||
)
|
||||
)
|
||||
then
|
||||
results=$(
|
||||
Insert "$table" < <(
|
||||
for key in ${!keys[@]}
|
||||
do
|
||||
echo "${keys[$key]}" "${values[$key]}"
|
||||
done
|
||||
)
|
||||
)
|
||||
fi
|
||||
echo "$results"
|
||||
}
|
||||
InsertOrUpdate() {
|
||||
#InsertOrUpdate table set_key set_value [set_key set_value […]] < where_key where_value
|
||||
# [where_key where_value
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user