24 #define LICENSE_REF_TABLE "ONLY license_ref"    25 #define DECISION_TYPE_FOR_IRRELEVANT 4    27 PGresult* queryFileIdsForUploadAndLimits(
fo_dbManager* 
dbManager, 
int uploadId, 
long left, 
long right, 
long groupId) {
    29     fo_dbManager_PrepareStamement(
    31       "queryFileIdsForUploadAndLimits"    33       "SELECT distinct (pfile_fk) FROM ("      34         "SELECT distinct ON(ut.uploadtree_pk, ut.pfile_fk, scopesort) ut.pfile_fk pfile_fk, ut.uploadtree_pk, decision_type,"    35           " CASE cd.scope WHEN 1 THEN 1 ELSE 0 END AS scopesort"    36         " FROM uploadtree ut "    37         " LEFT JOIN clearing_decision cd ON cd.group_fk=$5 AND (ut.uploadtree_pk=cd.uploadtree_fk AND scope=0 OR ut.pfile_fk=cd.pfile_fk AND scope=1) "    38         " WHERE upload_fk=$1 and (ufile_mode&x'3C000000'::int)=0 AND (lft between $2 and $3) AND ut.pfile_fk != 0"    39         " ORDER BY ut.uploadtree_pk, scopesort, ut.pfile_fk, clearing_decision_pk DESC"    40       ") itemView WHERE decision_type!=$4 OR decision_type IS NULL"    42       int, 
long, 
long, 
int, 
long),
    43     uploadId, left, right, DECISION_TYPE_FOR_IRRELEVANT, groupId
    48   return fo_dbManager_Exec_printf(
    50     "select rf_pk, rf_shortname from " LICENSE_REF_TABLE 
" where rf_detector_type = 1 and rf_active = 'true'"    54 char* getLicenseTextForLicenseRefId(
fo_dbManager* dbManager, 
long refId) {
    56     fo_dbManager_PrepareStamement(
    58       "getLicenseTextForLicenseRefId",
    59       "select rf_text from " LICENSE_REF_TABLE 
" where rf_pk = $1",
    64   if (PQntuples(licenseTextResult) != 1) {
    65     printf(
"cannot find license text!\n");
    66     PQclear(licenseTextResult);
    70   char* result = g_strdup(PQgetvalue(licenseTextResult, 0, 0));
    71   PQclear(licenseTextResult);
    75 int hasAlreadyResultsFor(
fo_dbManager* dbManager, 
int agentId, 
long pFileId) {
    77     fo_dbManager_PrepareStamement(
    79       "hasAlreadyResultsFor",
    80       "SELECT 1 WHERE EXISTS (SELECT 1"    81       " FROM license_file WHERE agent_fk = $1 AND pfile_fk = $2"    89     exists = (PQntuples(insertResult) == 1);
    90     PQclear(insertResult);
    96 int saveNoResultToDb(
fo_dbManager* dbManager, 
int agentId, 
long pFileId) {
    98     fo_dbManager_PrepareStamement(
   101       "insert into license_file(agent_fk, pfile_fk) values($1,$2)",
   109     PQclear(insertResult);
   115 long saveToDb(
fo_dbManager* dbManager, 
int agentId, 
long refId, 
long pFileId, 
unsigned percent) {
   117     fo_dbManager_PrepareStamement(
   120       "insert into license_file(rf_fk, agent_fk, pfile_fk, rf_match_pct) values($1,$2,$3,$4) RETURNING fl_pk",
   121       long, 
int, 
long, 
unsigned),
   122     refId, agentId, pFileId, percent
   125   long licenseFilePk = -1;
   127     if (PQntuples(insertResult) == 1) {
   128       licenseFilePk = atol(PQgetvalue(insertResult, 0, 0));
   130     PQclear(insertResult);
   133   return licenseFilePk;
   138     fo_dbManager_PrepareStamement(
   140       "saveDiffHighlightToDb",
   141       "insert into highlight(fl_fk, type, start, len, rf_start, rf_len) values($1,$2,$3,$4,$5,$6)",
   142       long, 
char*, 
size_t, 
size_t, 
size_t, 
size_t),
   145     diffInfo->text.start, diffInfo->text.length,
   146     diffInfo->search.start, diffInfo->search.length
   152   PQclear(insertResult);
   157 int saveDiffHighlightsToDb(
fo_dbManager* dbManager, 
const GArray* matchedInfo, 
long licenseFileId) {
   158   size_t matchedInfoLen = matchedInfo->len ;
   159   for (
size_t i = 0; i < matchedInfoLen; i++) {
   161     if (!saveDiffHighlightToDb(dbManager, diffMatchInfo, licenseFileId))
 PGresult * fo_dbManager_ExecPrepared(fo_dbManager_PreparedStatement *preparedStatement,...)
Execute a prepared statement. 
fo_dbManager * dbManager
fo_dbManager object 
int exists
Default not exists.