Beispiel #1
0
static struct hash *makeChromHashForTable(struct sqlConnection *conn, char *table)
/* Get a hash of all the chroms that are actually being used for the table.
 * This is helpful for assemblies with huge numbers of chroms. */
{
char query[1024];
// Make sure that the table has a chrom field.
// a bbi table will NOT have a chrom field
int cIdx = sqlFieldIndex(conn, table, "chrom");
if (cIdx < 0)
    return NULL;
sqlSafef(query, sizeof query, "select distinct chrom, 'dummyvalue' from %s", table);
struct hash *hash = sqlQuickHash(conn, query);
return hash;
}
void cdwReallyRemoveFiles(char *email, char *submitUrl, int fileCount, char *fileIds[])
/* cdwReallyRemoveFiles - Remove files from data warehouse.  Generally you want to depricate them 
 * instead. */
{
/* First convert all fileIds to binary. Do this first so bad command lines get caught. */
long long ids[fileCount];
int i;
for (i = 0; i<fileCount; ++i)
    ids[i] = sqlLongLong(fileIds[i]);

/* Get hash of all submissions by user from that URL.  Hash is keyed by ascii version of
 * submitId. */
struct sqlConnection *conn = cdwConnectReadWrite();
struct cdwUser *user = cdwMustGetUserFromEmail(conn, email);
char query[256];
sqlSafef(query, sizeof(query), 
    " select cdwSubmit.id,cdwSubmitDir.id from cdwSubmit,cdwSubmitDir "
    " where cdwSubmit.submitDirId=cdwSubmitDir.id and userId=%d "
    " and cdwSubmitDir.url='%s' ",
    user->id, submitUrl);
struct hash *submitHash = sqlQuickHash(conn, query);

/* Make sure that files and submission really go together. */
for (i=0; i<fileCount; ++i)
    {
    long long fileId = ids[i];
    char buf[64];
    sqlSafef(query, sizeof(query), "select submitId from cdwFile where id=%lld", fileId);
    char *result = sqlQuickQuery(conn, query, buf, sizeof(buf));
    if (result == NULL)
        errAbort("%lld is not a fileId in the warehouse", fileId);
    if (hashLookup(submitHash, result) == NULL)
        errAbort("File ID %lld does not belong to submission set based on %s", fileId, submitUrl);
    }

/* OK - paranoid checking is done, now let's remove each file from the tables it is in. */
for (i=0; i<fileCount; ++i)
    {
    cdwReallyRemoveFile(conn, ids[i], really);
    }
}
Beispiel #3
0
static struct hash* pubsLookupSequences(struct track *tg, struct sqlConnection* conn, char *articleId, bool getSnippet)
/* create a hash with a mapping annotId -> snippet or annotId -> shortSeq for an articleId*/
{
    struct dyString *dy = dyStringNew(LARGEBUF);
    char *sequenceTable = trackDbRequiredSetting(tg->tdb, "pubsSequenceTable");

    // work around sql injection fix problem, suggested by galt
    sqlDyStringPrintf(dy, "SELECT annotId, ");

     if (getSnippet)
        dyStringAppend(dy, "replace(replace(snippet, \"<B>\", \"\\n>>> \"), \"</B>\", \" <<<\\n\")" );
    else
        dyStringAppend(dy, "concat(substr(sequence,1,4),\"...\",substr(sequence,-4))" );
    sqlDyStringPrintf(dy, " FROM %s WHERE articleId='%s' ", sequenceTable, articleId);
    // end sql injection fix

    struct hash *seqIdHash = sqlQuickHash(conn, dy->string);

    //freeMem(sequenceTable); // trackDbRequiredSetting returns a value in a hash, so do not free
    freeDyString(&dy);
    return seqIdHash;
}