Index: trunk/MagicSoft/Mars/datacenter/scripts/sourcefile
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 9047)
+++ trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 9053)
@@ -51,8 +51,4 @@
       then 
          echo "could not make dir "$@
-         if ! [ "$todofile" = "" ] && ls $todofile >/dev/null 2>&1
-         then 
-            rm -v $todofile
-         fi
          if ls $lockfile >/dev/null 2>&1
          then 
@@ -117,5 +113,5 @@
 jmerrorlog=$runlogpath/jobmanager-error`date +%F`.log
 jmscriptlog=$runlogpath/jobmanager`date +%F`.log
-steps=$mars/steps.rc
+steps=$mars/resources/steps.rc
 # resetting values
 pno=0
@@ -144,8 +140,4 @@
 function finish()
 {
-   if ! [ "$todofile" = "" ] && ls $todofile >/dev/null 2>&1
-   then 
-      rm -v $todofile
-   fi
    if ! [ "$lockfile" = "" ] && ls $lockfile >/dev/null 2>&1
    then 
@@ -185,6 +177,5 @@
    starttime=NULL
    returncode=NULL
-   failedcode=NULL
-   failedcodeadd=NULL
+   programid=NULL
    failedtime=NULL
 }
@@ -196,6 +187,5 @@
    echo " starttime=$starttime"
    echo " returncode=$returncode"
-   echo " failedcode=$failedcode"
-   echo " failedcodeadd=$failedcodeadd"
+   echo " programid=$programid"
    echo " failedtime=$failedtime"
    echo "-- check: -$check-"
@@ -225,9 +215,5 @@
                           returncode=$check
                        fi
-                       failedcode=$com
-                       if ! [ "$comadd" = "" ]
-                       then
-                          failedcodeadd=$comadd
-                       fi
+                       programid=$com
                        failedtime="Now()"
                        check="ok"
@@ -259,56 +245,12 @@
    needs=`grep "$coltab[.]Needs:" $steps | sed -e "s/$coltab[.]Needs://"`
    influences=`grep "$coltab[.]Influences:" $steps | sed -e "s/$coltab[.]Influences://"`
-   primary=`grep "$table[.]Primary:" $steps | sed -e "s/$table[.]Primary://"`
+   prims=( `grep "$table[.]Primary:" $steps | sed -e "s/$table[.]Primary://"` )
 #   echo " column $column - table $table - coltab $coltab"
 #   echo " needs: $needs"
 #   echo " influences: $influences"
-#   echo " primary: $primary"
+#   echo " prims: ${prims[@]}"
 }
 
 # function to get todolist
-function getdolist()
-{
-   echo "getting todolist..."
-   getdbsetup
-   getstepinfo
-   # get query
-   query=" select $primary from $table where "
-   if ! echo $needs | grep '#' > /dev/null
-   then
-      for need in $needs
-      do
-         query=$query" not isnull($need) and"
-      done
-   fi
-   query=$query" isnull($column) "
-   query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) "
-   query=$query" order by fPriority desc "
-#   echo " QUERY: "$query
-   if ! process=`mysql -s -u $us --password=$pw --host=vela $db -e " $query "`
-   then
-      echo "ERROR could not query processes from db -> exit"
-      printprocesslog "ERROR could not query processes from db (program: $program, function getdolist)"
-      finish
-   fi
-
-   if [ "$process" = "" ]
-   then
-      echo "  => nothing to do"
-      finish
-   else
-      todofile=$listpath/ToDo-$table-$column.txt
-
-      if ls $todofile > /dev/null 2>&1
-      then
-         echo "$todofile exists already"
-         printprocesslog "WARN $todofile exists already (program: $program, function getdolist)"
-         finish
-      fi
-      echo "found processes, writing todofile..."
-      echo $process > $todofile
-   fi
-}
-
-# function to get todo (process)
 function gettodo()
 {
@@ -318,5 +260,15 @@
    getstepinfo
    # get query
-   query=" select $primary from $table where "
+   query=" select "
+   for (( i=0 ; i < ${#prims[@]} ; i++ ))
+   do
+      if [ $i -lt `expr ${#prims[@]} - 1` ]
+      then 
+         query=$query" ${prims[$i]}, "
+      else
+         query=$query" ${prims[$i]} "
+      fi
+   done
+   query=$query" from $table where "
    if ! echo $needs | grep '#' > /dev/null
    then
@@ -327,12 +279,15 @@
    fi
    query=$query" isnull($column) "
-   query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) "
+   query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fProgramId) and isnull(fReturnCode) "
    query=$query" order by fPriority desc "
-   query=$query" limit 0, 1 "
-#   echo " QUERY: "$query
+   if [ "$@" != "" ]
+   then 
+      query=$query" limit 0, $@ "
+   fi
+   echo " QUERY: "$query
    if ! process=`mysql -s -u $us --password=$pw --host=vela $db -e " $query "`
    then
-      echo "ERROR could not query process from db -> exit"
-      printprocesslog "ERROR could not query process from db (program: $program, function gettodo)"
+      echo "ERROR could not query processes from db -> exit"
+      printprocesslog "ERROR could not query processes from db (program: $program, function gettodo)"
       finish
    fi
@@ -340,8 +295,12 @@
    if [ "$process" = "" ]
    then
-      echo "  => nothing to do -> exit"
+      echo "  => nothing to do"
       finish
-   fi
-}
+   else
+      primaries=( $process )
+      num=`expr ${#primaries[@]} / ${#prims[@]} `
+   fi
+}
+
 
 # function to get the number of processes which still have to be done
@@ -349,5 +308,4 @@
 {
    numproc=
-#   echo "getting status..."
    getdbsetup
    column=${scriptscolname[$i]}
@@ -363,5 +321,5 @@
    fi
    query=$query" isnull($column) "
-   query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) "
+   query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fProgramId) and isnull(fReturnCode) "
    query=$query" group by $column "
 #   echo " QUERY: "$query
@@ -386,6 +344,6 @@
    if [ "$reset" = "no" ]
    then
-      echo "YOU CAN'T RESET $column for $primvar!!!"
-      printprocesslog "ERROR you can't reset $column for $primvar"
+      echo "YOU CAN'T RESET $column for ${primaries[$s+$s]}!!!"
+      printprocesslog "ERROR you can't reset $column for ${primaries[$s+$s]}"
       finish
    fi
@@ -402,6 +360,16 @@
       query=$query", fStartTime=$starttime"
    fi
-   query=$query", fFailedTime=$failedtime, fFailedCode=$failedcode, fFailedCodeAdd=$failedcodeadd, fReturnCode=$returncode "
-   query=$query" where $primary='$primvar'"
+   query=$query", fFailedTime=$failedtime, fProgramId=$programid, fReturnCode=$returncode "
+   query=$query" where "
+#   query=$query" where $primary='$primvar'"
+   for (( i=0 ; i < ${#prims[@]} ; i++ ))
+   do
+      if [ $i -lt `expr ${#prims[@]} - 1` ]
+      then 
+         query=$query" ${prims[$i]}=${primaries[$s+$s+$i]} and "
+      else
+         query=$query" ${prims[$i]}=${primaries[$s+$s+$i]} "
+      fi
+   done
    echo " QUERY: "$query
    if ! mysql -s -u $us --password=$pw --host=vela $db -e " $query "
