void cutterSaveToDbEscaped(struct sqlConnection *conn, struct cutter *el, char *tableName, int updateSize)
/* Save cutter 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 cutterSaveToDb().
 * For example automatically copies and converts: 
 * "autosql's features include" --> "autosql\'s features include" 
 * before inserting into database. */ 
{
struct dyString *update = newDyString(updateSize);
char  *name, *seq, *scizsArray, *companiesArray, *refsArray;
name = sqlEscapeString(el->name);
seq = sqlEscapeString(el->seq);

scizsArray = sqlStringArrayToString(el->scizs, el->numSciz);
companiesArray = sqlCharArrayToString(el->companies, el->numCompanies);
refsArray = sqlUnsignedArrayToString(el->refs, el->numRefs);
dyStringPrintf(update, "insert into %s values ( '%s',%u,%u,'%s',%u,%d,%u,%u,%u,'%s',%u,'%s',%u,'%s')", 
	tableName,  name, el->size , el->matchSize ,  seq, el->cut , el->overhang , el->palindromic , el->semicolon , el->numSciz ,  scizsArray , el->numCompanies ,  companiesArray , el->numRefs ,  refsArray );
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&name);
freez(&seq);
freez(&scizsArray);
freez(&companiesArray);
freez(&refsArray);
}
示例#2
0
void encodeErgeSaveToDb(struct sqlConnection *conn, struct encodeErge *el, char *tableName, int updateSize)
/* Save encodeErge 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. Strings are automatically escaped to allow insertion into the database. */
{
struct dyString *update = newDyString(updateSize);
char  *blockSizesArray, *chromStartsArray;
blockSizesArray = sqlUnsignedArrayToString(el->blockSizes, el->blockCount);
chromStartsArray = sqlUnsignedArrayToString(el->chromStarts, el->blockCount);
sqlDyStringPrintf(update, "insert into %s values ( '%s',%u,%u,'%s',%u,'%s',%u,%u,%u,%u,'%s','%s','%s','%s')", 
	tableName,  el->chrom,  el->chromStart,  el->chromEnd,  el->name,  el->score,  el->strand,  el->thickStart,  el->thickEnd,  el->reserved,  el->blockCount,  blockSizesArray ,  chromStartsArray ,  el->Id,  el->color);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&blockSizesArray);
freez(&chromStartsArray);
}
void cutterSaveToDb(struct sqlConnection *conn, struct cutter *el, char *tableName, int updateSize)
/* Save cutter 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 cutterSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
char  *scizsArray, *companiesArray, *refsArray;
scizsArray = sqlStringArrayToString(el->scizs, el->numSciz);
companiesArray = sqlCharArrayToString(el->companies, el->numCompanies);
refsArray = sqlUnsignedArrayToString(el->refs, el->numRefs);
dyStringPrintf(update, "insert into %s values ( '%s',%u,%u,'%s',%u,%d,%u,%u,%u,'%s',%u,'%s',%u,'%s')", 
	tableName,  el->name,  el->size,  el->matchSize,  el->seq,  el->cut,  el->overhang,  el->palindromic,  el->semicolon,  el->numSciz,  scizsArray ,  el->numCompanies,  companiesArray ,  el->numRefs,  refsArray );
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&scizsArray);
freez(&companiesArray);
freez(&refsArray);
}
示例#4
0
void addElementInt(unsigned el, unsigned **array, unsigned *count)
/* Add a new element to a array of elements */
{
  char *arrayCurr, arrayNew[MAX_ID_LIST];
  int sizeOne, size;
  unsigned *uArray, **dArray;

  if (!inArrayInt(el, *array, *count))
    {
      size = *count;
      arrayCurr = sqlUnsignedArrayToString(*array, *count);
      safef(arrayNew, ArraySize(arrayNew), "%s%d,", arrayCurr, el);
      size++;
      dArray = array;
      /* if (*count > 0)
	 freeMem(dArray); */
      sqlUnsignedDynamicArray(arrayNew, &uArray, &sizeOne);
      assert(sizeOne == size);
      *count = size;
      *array = uArray;
    }
}