Magellan Linux

Diff of /alx-src/branches/alx-web-070/scripts/sql-schema/mcore-sql-schema.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 8487 by niro, Fri Feb 5 12:06:33 2016 UTC revision 8488 by niro, Fri Feb 5 12:29:42 2016 UTC
# Line 64  mysqldo() Line 64  mysqldo()
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

Legend:
Removed from v.8487  
changed lines
  Added in v.8488