Index: /trunk/DataCheck/Sourcefile.sh
===================================================================
--- /trunk/DataCheck/Sourcefile.sh	(revision 18773)
+++ /trunk/DataCheck/Sourcefile.sh	(revision 18774)
@@ -36,4 +36,12 @@
 datetime=`date +%F-%H-%M-%S`
 
+if [ "$transferdelay" = "" ]
+then 
+   # setup where immediate report of problem is needed, i.e. mainly LP
+   checknight=`date +%Y%m%d --date="-19HOUR"`
+else
+   # any setup where transfer might cause a delay in arrival of files
+   checknight=`date +%Y%m%d  --date="-${transferdelay}day"`
+fi
 
 # function to make sure that a directory is made
@@ -197,4 +205,26 @@
       error=`echo $val | grep -E -o 'ERROR [1-9]{1,4}' | grep -E -o '[1-9]{1,4}'`
       # here possible reaction to mysql error
+      if [ $error -eq 1213 ]
+      then 
+         printprocesslog "WARN Deadlock found. Should resend query."
+         printprocesslog "DEBUG sendquery QUERY: [2nd try] "$query
+         val=`mysql $sqlpwfile -s -u $us $pw --host=$ho $db -e " $query " 2>&1`
+         checkmysql2=`echo $?`
+         if [ $checkmysql2 -gt 0 ]
+         then
+            printprocesslog "ERROR could not query DB "$db" on host "$ho" with user "$us" (program: $program, function sendquery) [2nd try]"
+            printprocesslog "MYSQLERROR [returncode: "$checkmysql"] "$val" [2nd try]"
+            error2=`echo $val | grep -E -o 'ERROR [1-9]{1,4}' | grep -E -o '[1-9]{1,4}'`
+            val=
+            finish
+         else
+            if [ "$val" = "NULL" ]
+            then
+               val=
+            fi
+            echo $val
+            return 0
+         fi
+      fi
       val=
       finish
@@ -577,12 +607,4 @@
       finish
    fi
-   if [ "$transferdelay" = "" ]
-   then 
-      # setup where immediate report of problem is needed, i.e. mainly LP
-      checknight=`date +%Y%m%d --date="-19HOUR"`
-   else
-      # any setup where transfer might cause a delay in arrival of files
-      checknight=`date +%Y%m%d  --date="-${transferdelay}day"`
-   fi
    
    printprocesslog "INFO checking availability of "$1
