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

/* Copyright (C) 2014 The Regents of the University of California 
 * See README in this or parent directory for licensing information. */

#include "common.h"
#include "linefile.h"
#include "dystring.h"
#include "jksql.h"
#include "bacEndAlias.h"


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

ret->alias = row[0];
ret->identNo = sqlUnsigned(row[1]);
ret->acc = row[2];
}

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

AllocVar(ret);
ret->alias = cloneString(row[0]);
ret->identNo = sqlUnsigned(row[1]);
ret->acc = cloneString(row[2]);
return ret;
}

struct bacEndAlias *bacEndAliasLoadAll(char *fileName) 
/* Load all bacEndAlias from a whitespace-separated file.
 * Dispose of this with bacEndAliasFreeList(). */
{
struct bacEndAlias *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[3];

while (lineFileRow(lf, row))
    {
    el = bacEndAliasLoad(row);
    slAddHead(&list, el);
    }
lineFileClose(&lf);
slReverse(&list);
return list;
}

struct bacEndAlias *bacEndAliasLoadAllByChar(char *fileName, char chopper) 
/* Load all bacEndAlias from a chopper separated file.
 * Dispose of this with bacEndAliasFreeList(). */
{
struct bacEndAlias *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[3];

while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
    {
    el = bacEndAliasLoad(row);
    slAddHead(&list, el);
    }
lineFileClose(&lf);
slReverse(&list);
return list;
}

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

if (ret == NULL)
    AllocVar(ret);
ret->alias = sqlStringComma(&s);
ret->identNo = sqlUnsignedComma(&s);
ret->acc = sqlStringComma(&s);
*pS = s;
return ret;
}

void bacEndAliasFree(struct bacEndAlias **pEl)
/* Free a single dynamically allocated bacEndAlias such as created
 * with bacEndAliasLoad(). */
{
struct bacEndAlias *el;

if ((el = *pEl) == NULL) return;
freeMem(el->alias);
freeMem(el->acc);
freez(pEl);
}

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

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

void bacEndAliasOutput(struct bacEndAlias *el, FILE *f, char sep, char lastSep) 
/* Print out bacEndAlias.  Separate fields with sep. Follow last field with lastSep. */
{
int i;
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->alias);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%u", el->identNo);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->acc);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}

/* -------------------------------- End autoSql Generated Code -------------------------------- */

