Index: trunk/MagicSoft/Mars/datacenter/scripts/sourcefile
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 9590)
+++ trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 9591)
@@ -253,9 +253,27 @@
 }
 
-# function to get the join of a step from the dependencies-file steps.rc
+# function to get the join of a step 
+#  (normal join but using different primaries)
+#  from the dependencies-file steps.rc
 function getjoin()
 {
    getdbsetup
    grep $@"[.]Join:" $steps | sed -e "s/$@[.]Join://"
+}
+
+# function to get the special join of a step 
+#  (i.e. join with a different table) 
+#  from the dependencies-file steps.rc
+function getspecialjoin()
+{
+   getdbsetup
+   grep $@"[.]SpecialJoin:" $steps | sed -e "s/$@[.]SpecialJoin://"
+}
+
+# function to get the needs of a step from the dependencies-file steps.rc
+function getneeds()
+{
+   getdbsetup
+   grep $@"[.]Needs:" $steps | sed -e "s/$@[.]Needs://"
 }
 
@@ -270,7 +288,20 @@
    do
       needprims=( `getprimary $need` )
+      # make sure that the correct joins are used
+      # in case the primaries of the step and the need are 
+      #   the same, the tables are join with these primaries
+      # otherwise it is checked whether there has to be a 
+      #   join with different primaries (indicated as 'Join'
+      #   in the steps.rc
+      # 'SpecialJoins' do not have to be taken into account here
       if [ "`echo ${needprims[@]}`" == "`echo ${prims[@]}`" ]
       then 
          query=$query" LEFT JOIN "$need"Status USING (${prims[@]}) "
+      else 
+         stdjoin=`getjoin $need`
+         if ! [ "$stdjoin" = "" ]
+         then
+            query=$query" "$stdjoin" "
+         fi
       fi
    done
@@ -287,8 +318,10 @@
       needprims=( `getprimary $need` )
       # in case the primaries of the tables agree
-      #   only the condition is given
-      # for tables with differing primaries a special query 
-      #   is needed
-      if [ "`echo ${needprims[@]}`" == "`echo ${prims[@]}`" ]
+      #   or there is just a normal 'Join' needed
+      #   only the condition is added to the query
+      # for tables which need a join with a different
+      #   table, a special query is added using the
+      #   'SpecialJoin' from the steps.rc
+      if [ "`echo ${needprims[@]}`" == "`echo ${prims[@]}`" ] || ! [ "$stdjoin" = "" ]
       then 
          query=$query" NOT ISNULL("$need"Status.fStartTime) AND "
@@ -297,5 +330,5 @@
       else 
          query=$query" (SELECT COUNT(*) FROM "$need"Status "
-         query=$query" "`getjoin $need`" "
+         query=$query" "`getspecialjoin $need`" "
          query=$query" WHERE "$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`
          for (( j=1 ; j < ${#prims[@]} ; j++ ))
@@ -304,5 +337,5 @@
          done
          query=$query") = (SELECT COUNT(*) FROM "$need"Status "
-         query=$query" "`getjoin $need`" "
+         query=$query" "`getspecialjoin $need`" "
          query=$query" WHERE "$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`
          for (( j=1 ; j < ${#prims[@]} ; j++ ))
@@ -356,5 +389,5 @@
    fi
    # print query 
-   echo " gettodo QUERY: "$query
+   #echo " gettodo QUERY: "$query
    printprocesslog "INFO gettodo QUERY: "$query
    # execute query 
@@ -393,5 +426,5 @@
    query=$query" GROUP BY 2 "
    # printing query
-   echo " getstatus QUERY: "$query
+   #echo " getstatus QUERY: "$query
    printprocesslog "INFO getstatus QUERY: "$query
    # execute query
@@ -462,5 +495,5 @@
    
    # get the influences from the steps.rc by evaluating the needs of all steps
-   influences=`grep $step $rc | grep "Needs" | grep -v "$step[.]Needs" | cut -d'.' -f1`
+   influences=`grep $step $steps | grep "Needs" | grep -v "$step[.]Needs" | cut -d'.' -f1`
    
    # get query
@@ -469,9 +502,23 @@
    for influence in $influences
    do
-      query=$query" LEFT JOIN $influence USING("`getprimary $influence`") "
-      specialjoin=`getjoin $influence`
-      if ! [ "$specialjoin" = "" ]
+      # make sure that the right join is done 
+      #   in case the is a 'Join' given for the 
+      #   influenced step, this is added
+      # otherwise it is checked whether the executed step
+      #   itself needs a 'Join' (i.e. has different primaries)
+      #   if yes, the tables are joined with the primaries of the influenced step
+      #   else with the primaries of the executed step itself
+      stdjoin=`getjoin $influence`
+      if ! [ "$stdjoin" = "" ]
       then 
-         query=$query$specialjoin
+         query=$query" "$stdjoin" "
+      else
+         stdjoin2=`getjoin $step`
+         if [ "$stdjoin2" == "" ]
+         then
+            query=$query" LEFT JOIN "$influence"Status USING("`getprimary $influence`") "
+         else
+            query=$query" LEFT JOIN "$influence"Status USING("`getprimary $step`") "
+         fi
       fi
    done
@@ -502,5 +549,5 @@
    done   
    # print query
-   echo " setstatus QUERY: "$query
+   #echo " setstatus QUERY: "$query
    printprocesslog "INFO setstatus QUERY: "$query
    # execute query
