709fe2b919636225cb13fb2d95cf177702346bd1
angie
  Wed Apr 25 15:50:25 2012 -0700
Feature #6152 (Variant Annotation Tool): Added region type and positioninputs to UI -- and it actually executes some queries now!

diff --git src/lib/asParse.c src/lib/asParse.c
index e90ed66..7e69e1f 100644
--- src/lib/asParse.c
+++ src/lib/asParse.c
@@ -65,30 +65,63 @@
 /* Convert column to a sql type spec in returned dyString */
 {
 struct asTypeInfo *lt = col->lowType;
 struct dyString *type = dyStringNew(32);
 if ((lt->type == t_enum) || (lt->type == t_set))
     sqlSymDef(col, type);
 else if (col->isList || col->isArray)
     dyStringPrintf(type, "longblob");
 else if (lt->type == t_char)
     dyStringPrintf(type, "char(%d)", col->fixedSize ? col->fixedSize : 1);
 else
     dyStringPrintf(type, "%s", lt->sqlName);
 return type;
 }
 
+char *asTypeNameFromSqlType(char *sqlType)
+/* Return the autoSql type name (not enum) for the given SQL type, or NULL.
+ * Don't attempt to free result. */
+{
+if (sqlType == NULL)
+    return NULL;
+// We need to strip '(...)' strings from all types except 'varchar' which must be 'varchar(255)'
+int len = strlen(sqlType) + 8;
+char buf[len];
+if (startsWith("varchar", sqlType))
+    safecpy(buf, len, "varchar(255)");
+else
+    {
+    safecpy(buf, len, sqlType);
+    char *leftParen = strstr(buf, " (");
+    if (leftParen == NULL)
+	leftParen = strchr(buf, '(');
+    if (leftParen != NULL)
+	{
+	char *rightParen = strrchr(leftParen, ')');
+	if (rightParen != NULL)
+	    {
+	    strcpy(leftParen, rightParen+1);
+	    }
+	}
+    }
+int i;
+for (i = 0;  i < ArraySize(asTypes);  i++)
+    if (sameString(buf, asTypes[i].sqlName))
+	return asTypes[i].name;
+return NULL;
+}
+
 static struct asColumn *mustFindColumn(struct asObject *table, char *colName)
 /* Return column or die. */
 {
 struct asColumn *col;
 
 for (col = table->columnList; col != NULL; col = col->next)
     {
     if (sameWord(col->name, colName))
 	return col;
     }
 errAbort("Couldn't find column %s", colName);
 return NULL;
 }
 
 static struct asObject *findObType(struct asObject *objList, char *obName)