64 |
&& return 0 || return 1 |
&& return 0 || return 1 |
65 |
} |
} |
66 |
|
|
|
mysql_insert() |
|
|
{ |
|
|
local cmdline="$@" |
|
|
#local table="$1" |
|
|
local table="${cmdline%%,*}" |
|
|
local argv |
|
|
local insert_line |
|
|
local update_line |
|
|
local key |
|
|
local value |
|
|
local counter |
|
|
|
|
|
OLD_IFS=${IFS} |
|
|
IFS=, |
|
|
declare -i counter=0 |
|
|
#for argv in ${cmdline/$1/} # first value is the table_name |
|
|
for argv in ${cmdline#*,} # first value is the table_name |
|
|
do |
|
|
key="${argv%=*}" |
|
|
value="${argv#*=}" |
|
|
|
|
|
if [ ${counter} -eq 0 ] |
|
|
then |
|
|
insert_keys="${key}" |
|
|
insert_values="'${value}'" |
|
|
update_line="${key}='${value}'" |
|
|
else |
|
|
insert_keys+=",${key}" |
|
|
insert_values+=",'${value}'" |
|
|
update_line+=",${key}='${value}'" |
|
|
fi |
|
|
(( counter ++ )) |
|
|
done |
|
|
IFS=${OLD_IFS} |
|
|
|
|
|
echo "INSERT INTO ${table} (${insert_keys}) VALUES(${insert_values}) ON DUPLICATE KEY UPDATE ${update_line};" |
|
|
#mysqldo "insert into ${table} (${insert_keys}) values(${insert_values}) on duplicate key update ${update_line};" |
|
|
} |
|
|
|
|
|
|
|
67 |
# creates a mysql table with help of a defined array TABLE_DEFINITION: |
# creates a mysql table with help of a defined array TABLE_DEFINITION: |
68 |
# array values are a struct like this: |
# array values are a struct like this: |
69 |
# first array element is the table name, everything else are column descriptions |
# first array element is the table name, everything else are column descriptions |