f5ba6de31304850e1650c1a785f717971cbfa4a8
braney
  Tue Aug 2 12:28:30 2016 -0700
fix problem with bigBed code calling SQL code during parallel load.
This causes a crash because SQL code is not thread safe.

diff --git src/lib/bigBed.c src/lib/bigBed.c
index 9b4059a..7e660ee 100644
--- src/lib/bigBed.c
+++ src/lib/bigBed.c
@@ -520,30 +520,48 @@
 }
 
 struct asObject *bigBedFileAsObjOrDefault(char *fileName)
 // Get asObject associated with bigBed file, or the default.
 {
 struct bbiFile *bbi = bigBedFileOpen(fileName);
 if (bbi)
     {
     struct asObject *as = bigBedAsOrDefault(bbi);
     bbiFileClose(&bbi);
     return as;
     }
 return NULL;
 }
 
+int bbExtraFieldIndex(struct bbiFile *bbi, char* fieldName)
+/* return the index of a given extra field */
+{
+if (fieldName==NULL)
+    return 0;
+struct asObject *as = bigBedAsOrDefault(bbi);
+if (as == NULL)
+    return 0;
+
+// search for field name, return index if found
+struct asColumn *col = as->columnList;
+int ix = 0;
+for (;col != NULL;col=col->next, ix+=1)
+    if (sameString(col->name, fieldName))
+        return max(ix-3, 0); // never return a negative value
+return 0;
+}
+
 bits64 bigBedItemCount(struct bbiFile *bbi)
 /* Return total items in file. */
 {
 udcSeek(bbi->udc, bbi->unzoomedDataOffset);
 return udcReadBits64(bbi->udc, bbi->isSwapped);
 }
 
 struct slName *bigBedListExtraIndexes(struct bbiFile *bbi)
 /* Return list of names of extra indexes beyond primary chrom:start-end one" */
 {
 struct udcFile *udc = bbi->udc;
 boolean isSwapped = bbi->isSwapped;
 
 /* See if we have any extra indexes, and if so seek to there. */
 bits64 offset = bbi->extraIndexListOffset;