#include <errno.h>
 #include <sys/types.h>
 #include <time.h>
+#include <limits.h>
 
 #include "glite/jp/types.h"
 #include "glite/jp/context.h"
        struct tm       *tm = gmtime(&t);
        char    tbuf[256];
 
+       /* XXX: the very end of our days */
+       if (!tm && t == (time_t) LONG_MAX) return strdup("9999-12-31 23:59:59");
+
        sprintf(tbuf,"'%4d-%02d-%02d %02d:%02d:%02d'",tm->tm_year+1900,tm->tm_mon+1,
                tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
        
 
        }
 
        peername = glite_jp_peer_name(ctx);
-       if (peername = NULL) {
+       if (peername == NULL) {
                err.code = EINVAL;
                err.desc = "Cannot obtain client certificate info";
                goto error_out;
        }
 
        trio_asprintf(&stmt, "select owner, reg_time from jobs"
-               "where jobid='%|Ss'", ju);
+               " where jobid='%|Ss'", ju);
 
        if (!stmt) {
                err.code = ENOMEM;
 
        free(stmt); stmt = NULL;
        trio_asprintf(&stmt,"insert into files"
-               "(jobid,filename,int_path,ext_path,state,deadline,ul_userid) "
+               "(jobid,filename,int_path,ext_url,state,deadline,ul_userid) "
                "values ('%|Ss','%|Ss','%|Ss','%|Ss','%|Ss', '%|Ss', '%|Ss')",
                ju, data_basename, data_fname, destination_out, "uploading", 
                glite_jp_db_timetodb(*commit_before_inout), peerhash);