fa93a0b39b44232aea5067812b3660f186b9e7a2
tdreszer
  Thu May 12 11:49:21 2011 -0700
Fixed a couple of bug in mdbUpte: encodeExp was updating accession without it being requested and using -var and delete was segfaulting.
diff --git src/hg/lib/mdb.c src/hg/lib/mdb.c
index 15cae04..08e6004 100644
--- src/hg/lib/mdb.c
+++ src/hg/lib/mdb.c
@@ -1139,31 +1139,31 @@
 
 count = mdbObjPrintToTabFile(mdbObjs,MDB_TEMPORARY_TAB_FILE);
 
 // Disable keys in hopes of speeding things up.  No danger since it only disables non-unique keys
 char query[8192];
 safef(query, sizeof(query),"alter table %s disable keys",tableName);
 sqlUpdate(conn, query);
 
 // Quick? load
 sqlLoadTabFile(conn, MDB_TEMPORARY_TAB_FILE, tableName, SQL_TAB_FILE_WARN_ON_ERROR|SQL_TAB_FILE_WARN_ON_WARN);
 
 // Enabling the keys again
 safef(query, sizeof(query),"alter table %s enable keys",tableName);
 sqlUpdate(conn, query);
 
-unlink(MDB_TEMPORARY_TAB_FILE);
+//unlink(MDB_TEMPORARY_TAB_FILE);
 
 verbose(0,"%04ldms - Done loading mdb with 'LOAD DATA INFILE' mysql command.\n",(clock1000() - lastTime));
 
 return count;
 }
 
 // ------------------ Querys -------------------
 struct mdbObj *mdbObjQuery(struct sqlConnection *conn,char *table,struct mdbObj *mdbObj)
 // Query the metadata table by obj and optional vars and vals in metaObj struct.  If mdbObj is NULL query all.
 // Returns new mdbObj struct fully populated and sorted in obj,var order.
 {
 //  select obj,var,val where (var= [and val=]) or ([var= and] val=) order by obj,var
     boolean buildHash = TRUE;
 
     if(table == NULL)
@@ -2894,39 +2894,41 @@
             boolean updateObj = FALSE;
             char *val = mdbObjFindValue(obj,MDB_VAR_ENCODE_EXP_ID);
             if (val != NULL)
                 {
                 foundId = TRUE; // warn==1 will give only 1 exp wide error if no individual errors.  NOTE: would be nice if those with expId sorted to beginning, but can't have everything.
                 int thisId = atoi(val);
                 if (expId == ENCODE_EXP_IX_UNDEFINED || thisId != expId)
                     {
                     updateObj = TRUE;  // Always an error!
                     expMissing++;
 
                     printf("    ERROR  %s %-60s has bad %s=%s.\n",experimentId,obj->obj,MDB_VAR_ENCODE_EXP_ID,val);
                     }
                 else
                     {
-                    char *acc = mdbObjFindValue(obj,MDB_VAR_DCC_ACCESSION); // FIXME: Add code to update accession to encodeExp
-                    if (updateAccession && !createExpIfNecessary && exp->accession == NULL)
+                    char *acc = mdbObjFindValue(obj,MDB_VAR_DCC_ACCESSION);
+                    if (updateAccession && !createExpIfNecessary && exp->accession == NULL) // -test so one wasn't created
                         {
                         exp->accession = needMem(16);
                         safef(exp->accession, 16, "TEMP%06d", exp->ix); // Temporary since this is not an update but we want -test to work.
                         }
                     if (exp->accession != NULL && (acc == NULL || differentString(acc,exp->accession)))
                         {
+                        if (updateAccession)
                         updateObj = TRUE;
+
                         accMissing++;
 
                         if (acc != NULL) // Always an error
                             printf("    ERROR  %s %-60s %s set, has wrong %s: %s.\n",experimentId,obj->obj,
                                     MDB_VAR_ENCODE_EXP_ID,MDB_VAR_DCC_ACCESSION,acc);
                         else if (warn > 1)           // NOTE: Could give more info for each obj as per wrangler's desires
                             printf("           %s %-60s %s set, needs %s.\n",experimentId,obj->obj,MDB_VAR_ENCODE_EXP_ID,MDB_VAR_DCC_ACCESSION);
                         }
                     else
                         {
                         errors--;       // One less error
                         if (warn > 1)           // NOTE: Could give more info for each obj as per wrangler's desires
                             printf("           %s %-60s %s\n",experimentId,obj->obj,(exp->accession != NULL ? exp->accession : ""));
                         }
                     }
@@ -2942,31 +2944,31 @@
                 if ((foundId && warn > 0) || warn > 1)
                     {
                     if (updateObj)
                         printf("           %s %-60s needs updating to mdb.\n",experimentId,obj->obj);
                     else
                         printf("           %s %s\n",experimentId,obj->obj); // missing
                     }
                 }
 
             // This object needs to be updated.
             if (updateObj)
                 {
                 mdbObjSetVarInt(obj,MDB_VAR_ENCODE_EXP_ID,expId);
                 struct mdbObj *newObj = mdbObjCreate(obj->obj,MDB_VAR_ENCODE_EXP_ID, experimentId);
                 assert(exp != NULL);
-                if (exp->accession != NULL)
+                if (exp->accession != NULL && updateAccession)
                     mdbObjSetVar(newObj,MDB_VAR_DCC_ACCESSION,exp->accession);
                 slAddHead(&mdbUpdateObjs,newObj);
                 }
             slAddHead(&mdbProcessedObs,obj);
             }
         // Done with one experiment
         encodeExpFree(&exp);
 
         if (!foundId && errors > 0 && warn > 0)
             printf("           %s all %d objects are missing an %s.\n",experimentId,objsInExp,MDB_VAR_ENCODE_EXP_ID);
         }
     // Done with one composite
 
     if (expCount > 0)
         {