Index: src/hg/lib/makeItemsItem.c
===================================================================
RCS file: src/hg/lib/makeItemsItem.c
diff -N src/hg/lib/makeItemsItem.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/hg/lib/makeItemsItem.c	9 Apr 2010 17:44:20 -0000	1.1
@@ -0,0 +1,233 @@
+/* makeItemsItem.c was originally generated by the autoSql program, which also 
+ * generated makeItemsItem.h and makeItemsItem.sql.  This module links the database and
+ * the RAM representation of objects. */
+
+#include "common.h"
+#include "linefile.h"
+#include "dystring.h"
+#include "jksql.h"
+#include "makeItemsItem.h"
+
+static char const rcsid[] = "$Id$";
+
+void makeItemsStaticLoad(char **row, struct makeItems *ret)
+/* Load a row from makeItems table into ret.  The contents of ret will
+ * be replaced at the next call to this function. */
+{
+
+ret->bin = sqlUnsigned(row[0]);
+ret->chrom = row[1];
+ret->chromStart = sqlUnsigned(row[2]);
+ret->chromEnd = sqlUnsigned(row[3]);
+ret->name = row[4];
+safecpy(ret->strand, sizeof(ret->strand), row[5]);
+ret->score = sqlUnsigned(row[6]);
+ret->color = row[7];
+ret->description = row[8];
+}
+
+struct makeItems *makeItemsLoadByQuery(struct sqlConnection *conn, char *query)
+/* Load all makeItems from table that satisfy the query given.  
+ * Where query is of the form 'select * from example where something=something'
+ * or 'select example.* from example, anotherTable where example.something = 
+ * anotherTable.something'.
+ * Dispose of this with makeItemsFreeList(). */
+{
+struct makeItems *list = NULL, *el;
+struct sqlResult *sr;
+char **row;
+
+sr = sqlGetResult(conn, query);
+while ((row = sqlNextRow(sr)) != NULL)
+    {
+    el = makeItemsLoad(row);
+    slAddHead(&list, el);
+    }
+slReverse(&list);
+sqlFreeResult(&sr);
+return list;
+}
+
+void makeItemsSaveToDb(struct sqlConnection *conn, struct makeItems *el, char *tableName, int updateSize)
+/* Save makeItems as a row to the table specified by tableName. 
+ * As blob fields may be arbitrary size updateSize specifies the approx size
+ * of a string that would contain the entire query. Arrays of native types are
+ * converted to comma separated strings and loaded as such, User defined types are
+ * inserted as NULL. Note that strings must be escaped to allow insertion into the database.
+ * For example "autosql's features include" --> "autosql\'s features include" 
+ * If worried about this use makeItemsSaveToDbEscaped() */
+{
+struct dyString *update = newDyString(updateSize);
+dyStringPrintf(update, "insert into %s values ( %u,'%s',%u,%u,'%s','%s',%u,'%s',%s)", 
+	tableName,  el->bin,  el->chrom,  el->chromStart,  el->chromEnd,  el->name,  el->strand,  el->score,  el->color,  el->description);
+sqlUpdate(conn, update->string);
+freeDyString(&update);
+}
+
+void makeItemsSaveToDbEscaped(struct sqlConnection *conn, struct makeItems *el, char *tableName, int updateSize)
+/* Save makeItems as a row to the table specified by tableName. 
+ * As blob fields may be arbitrary size updateSize specifies the approx size.
+ * of a string that would contain the entire query. Automatically 
+ * escapes all simple strings (not arrays of string) but may be slower than makeItemsSaveToDb().
+ * For example automatically copies and converts: 
+ * "autosql's features include" --> "autosql\'s features include" 
+ * before inserting into database. */ 
+{
+struct dyString *update = newDyString(updateSize);
+char  *chrom, *name, *strand, *color, *description;
+chrom = sqlEscapeString(el->chrom);
+name = sqlEscapeString(el->name);
+strand = sqlEscapeString(el->strand);
+color = sqlEscapeString(el->color);
+description = sqlEscapeString(el->description);
+
+dyStringPrintf(update, "insert into %s values ( %u,'%s',%u,%u,'%s','%s',%u,'%s','%s')", 
+	tableName,  el->bin,  chrom,  el->chromStart,  el->chromEnd,  name,  strand,  el->score,  color,  description);
+sqlUpdate(conn, update->string);
+freeDyString(&update);
+freez(&chrom);
+freez(&name);
+freez(&strand);
+freez(&color);
+freez(&description);
+}
+
+struct makeItems *makeItemsLoad(char **row)
+/* Load a makeItems from row fetched with select * from makeItems
+ * from database.  Dispose of this with makeItemsFree(). */
+{
+struct makeItems *ret;
+
+AllocVar(ret);
+ret->bin = sqlUnsigned(row[0]);
+ret->chrom = cloneString(row[1]);
+ret->chromStart = sqlUnsigned(row[2]);
+ret->chromEnd = sqlUnsigned(row[3]);
+ret->name = cloneString(row[4]);
+safecpy(ret->strand, sizeof(ret->strand), row[5]);
+ret->score = sqlUnsigned(row[6]);
+ret->color = cloneString(row[7]);
+ret->description = cloneString(row[8]);
+return ret;
+}
+
+struct makeItems *makeItemsLoadAll(char *fileName) 
+/* Load all makeItems from a whitespace-separated file.
+ * Dispose of this with makeItemsFreeList(). */
+{
+struct makeItems *list = NULL, *el;
+struct lineFile *lf = lineFileOpen(fileName, TRUE);
+char *row[9];
+
+while (lineFileRow(lf, row))
+    {
+    el = makeItemsLoad(row);
+    slAddHead(&list, el);
+    }
+lineFileClose(&lf);
+slReverse(&list);
+return list;
+}
+
+struct makeItems *makeItemsLoadAllByChar(char *fileName, char chopper) 
+/* Load all makeItems from a chopper separated file.
+ * Dispose of this with makeItemsFreeList(). */
+{
+struct makeItems *list = NULL, *el;
+struct lineFile *lf = lineFileOpen(fileName, TRUE);
+char *row[9];
+
+while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
+    {
+    el = makeItemsLoad(row);
+    slAddHead(&list, el);
+    }
+lineFileClose(&lf);
+slReverse(&list);
+return list;
+}
+
+struct makeItems *makeItemsCommaIn(char **pS, struct makeItems *ret)
+/* Create a makeItems out of a comma separated string. 
+ * This will fill in ret if non-null, otherwise will
+ * return a new makeItems */
+{
+char *s = *pS;
+
+if (ret == NULL)
+    AllocVar(ret);
+ret->bin = sqlUnsignedComma(&s);
+ret->chrom = sqlStringComma(&s);
+ret->chromStart = sqlUnsignedComma(&s);
+ret->chromEnd = sqlUnsignedComma(&s);
+ret->name = sqlStringComma(&s);
+sqlFixedStringComma(&s, ret->strand, sizeof(ret->strand));
+ret->score = sqlUnsignedComma(&s);
+ret->color = sqlStringComma(&s);
+ret->description = sqlStringComma(&s);
+*pS = s;
+return ret;
+}
+
+void makeItemsFree(struct makeItems **pEl)
+/* Free a single dynamically allocated makeItems such as created
+ * with makeItemsLoad(). */
+{
+struct makeItems *el;
+
+if ((el = *pEl) == NULL) return;
+freeMem(el->chrom);
+freeMem(el->name);
+freeMem(el->color);
+freeMem(el->description);
+freez(pEl);
+}
+
+void makeItemsFreeList(struct makeItems **pList)
+/* Free a list of dynamically allocated makeItems's */
+{
+struct makeItems *el, *next;
+
+for (el = *pList; el != NULL; el = next)
+    {
+    next = el->next;
+    makeItemsFree(&el);
+    }
+*pList = NULL;
+}
+
+void makeItemsOutput(struct makeItems *el, FILE *f, char sep, char lastSep) 
+/* Print out makeItems.  Separate fields with sep. Follow last field with lastSep. */
+{
+fprintf(f, "%u", el->bin);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->chrom);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+fprintf(f, "%u", el->chromStart);
+fputc(sep,f);
+fprintf(f, "%u", el->chromEnd);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->name);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->strand);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+fprintf(f, "%u", el->score);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->color);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->description);
+if (sep == ',') fputc('"',f);
+fputc(lastSep,f);
+}
+
+/* -------------------------------- End autoSql Generated Code -------------------------------- */
+

