/* sangRange.c was originally generated by the autoSql program, which also 
 * generated sangRange.h and sangRange.sql.  This module links the database and the RAM 
 * representation of objects. */

#include "common.h"
#include "jksql.h"
#include "sangRange.h"


void sangRangeStaticLoad(char **row, struct sangRange *ret)
/* Load a row from sangRange table into ret.  The contents of ret will
 * be replaced at the next call to this function. */
{
int sizeOne,i;
char *s;

strcpy(ret->name, row[0]);
ret->minSize = sqlUnsigned(row[1]);
ret->maxSize = sqlUnsigned(row[2]);
}

struct sangRange *sangRangeLoad(char **row)
/* Load a sangRange from row fetched with select * from sangRange
 * from database.  Dispose of this with sangRangeFree(). */
{
struct sangRange *ret;
int sizeOne,i;
char *s;

AllocVar(ret);
strcpy(ret->name, row[0]);
ret->minSize = sqlUnsigned(row[1]);
ret->maxSize = sqlUnsigned(row[2]);
return ret;
}

struct sangRange *sangRangeCommaIn(char **pS, struct sangRange *ret)
/* Create a sangRange out of a comma separated string. 
 * This will fill in ret if non-null, otherwise will
 * return a new sangRange */
{
char *s = *pS;
int i;

if (ret == NULL)
    AllocVar(ret);
sqlFixedStringComma(&s, ret->name, sizeof(ret->name));
ret->minSize = sqlUnsignedComma(&s);
ret->maxSize = sqlUnsignedComma(&s);
*pS = s;
return ret;
}

void sangRangeFree(struct sangRange **pEl)
/* Free a single dynamically allocated sangRange such as created
 * with sangRangeLoad(). */
{
struct sangRange *el;

if ((el = *pEl) == NULL) return;
freez(pEl);
}

void sangRangeFreeList(struct sangRange **pList)
/* Free a list of dynamically allocated sangRange's */
{
struct sangRange *el, *next;

for (el = *pList; el != NULL; el = next)
    {
    next = el->next;
    sangRangeFree(&el);
    }
*pList = NULL;
}

void sangRangeOutput(struct sangRange *el, FILE *f, char sep, char lastSep) 
/* Print out sangRange.  Separate fields with sep. Follow last field with lastSep. */
{
int i;
if (sep == ',') fputc('"',f);
fprintf(f, "%s%c", el->name, sep);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%u%c", el->minSize, sep);
fputc(sep,f);
fprintf(f, "%u%c", el->maxSize, lastSep);
fputc(lastSep,f);
}

