13 #define LICENSE_REF_TABLE "ONLY license_ref"
16 long left,
long right,
long groupId,
17 bool ignoreIrre,
bool scanFindings) {
23 char* distinctPfile =
"SELECT DISTINCT pfile_fk FROM %s"
24 " WHERE upload_fk = $1 AND (ufile_mode&x'3C000000'::int) = 0 "
25 " AND (lft BETWEEN $2 AND $3) AND pfile_fk != 0";
26 char* distinctPfileNoDec =
"SELECT DISTINCT pfile_fk FROM ("
27 "SELECT distinct ON(ut.uploadtree_pk, ut.pfile_fk, scopesort) ut.pfile_fk pfile_fk, ut.uploadtree_pk, decision_type,"
28 " CASE cd.scope WHEN 1 THEN 1 ELSE 0 END AS scopesort"
30 " LEFT JOIN clearing_decision cd ON "
31 " ((ut.uploadtree_pk = cd.uploadtree_fk AND scope = 0 AND cd.group_fk = $5) "
32 " OR (ut.pfile_fk = cd.pfile_fk AND scope = 1)) "
33 " WHERE upload_fk=$1 AND (ufile_mode&x'3C000000'::int)=0 AND (lft BETWEEN $2 AND $3) AND ut.pfile_fk != 0"
34 " ORDER BY ut.uploadtree_pk, scopesort, ut.pfile_fk, clearing_decision_pk DESC"
35 ") itemView WHERE decision_type!=$4 OR decision_type IS NULL";
36 char* nonVoidPfile =
"SELECT pfile_fk FROM allPfileData"
37 " WHERE pfile_fk NOT IN (SELECT lf.pfile_fk"
38 " FROM license_file lf"
39 " JOIN ars_master am ON lf.agent_fk = am.agent_fk"
40 " JOIN " LICENSE_REF_TABLE
" lr ON lf.rf_fk = lr.rf_pk"
41 " WHERE am.upload_fk = $1"
42 " AND lr.rf_shortname = ANY(VALUES('No_license_found'), ('Void')))";
44 if (!ignoreIrre && !scanFindings)
46 sql = g_strdup_printf(distinctPfile, tablename);
47 stmt = g_strdup_printf(
"queryFileIdsForUploadAndLimits.%s", tablename);
49 fo_dbManager_PrepareStamement(
57 else if(!ignoreIrre && scanFindings)
59 sql = g_strdup_printf(
60 g_strconcat(
"WITH allPfileData AS (", distinctPfile,
") ", nonVoidPfile,
62 stmt = g_strdup_printf(
"queryFileIdsForUploadAndLimitswithlicensefinding.%s", tablename);
64 fo_dbManager_PrepareStamement(
72 else if(ignoreIrre && scanFindings)
74 sql = g_strdup_printf(
75 g_strconcat(
"WITH allPfileData AS (", distinctPfileNoDec,
") ",
76 nonVoidPfile, NULL), tablename);
77 stmt = g_strdup_printf(
"queryFileIdsForUploadAndLimits.%s.ignoreirreandscanFindings", tablename);
79 fo_dbManager_PrepareStamement(
83 int,
long,
long,
int,
long),
84 uploadId, left, right, DECISION_TYPE_FOR_IRRELEVANT, groupId
89 sql = g_strdup_printf(distinctPfileNoDec, tablename);
90 stmt = g_strdup_printf(
"queryFileIdsForUploadAndLimits.%s.ignoreirre", tablename);
92 fo_dbManager_PrepareStamement(
96 int,
long,
long,
int,
long),
97 uploadId, left, right, DECISION_TYPE_FOR_IRRELEVANT, groupId
106 return fo_dbManager_Exec_printf(
108 "select rf_pk, rf_shortname from " LICENSE_REF_TABLE
" where rf_detector_type = 1 and rf_active = 'true'"
114 fo_dbManager_PrepareStamement(
116 "getLicenseTextForLicenseRefId",
117 "select rf_text from " LICENSE_REF_TABLE
" where rf_pk = $1",
122 if (PQntuples(licenseTextResult) != 1) {
123 printf(
"cannot find license text!\n");
124 PQclear(licenseTextResult);
128 char* result = g_strdup(PQgetvalue(licenseTextResult, 0, 0));
129 PQclear(licenseTextResult);
135 fo_dbManager_PrepareStamement(
137 "hasAlreadyResultsFor",
138 "SELECT 1 WHERE EXISTS (SELECT 1"
139 " FROM license_file WHERE agent_fk = $1 AND pfile_fk = $2"
147 exists = (PQntuples(insertResult) == 1);
148 PQclear(insertResult);
156 fo_dbManager_PrepareStamement(
159 "insert into license_file(agent_fk, pfile_fk) values($1,$2)",
167 PQclear(insertResult);
175 fo_dbManager_PrepareStamement(
178 "insert into license_file(rf_fk, agent_fk, pfile_fk, rf_match_pct) values($1,$2,$3,$4) RETURNING fl_pk",
179 long,
int,
long,
unsigned),
180 refId, agentId, pFileId, percent
183 long licenseFilePk = -1;
185 if (PQntuples(insertResult) == 1) {
186 licenseFilePk = atol(PQgetvalue(insertResult, 0, 0));
188 PQclear(insertResult);
191 return licenseFilePk;
196 fo_dbManager_PrepareStamement(
198 "saveDiffHighlightToDb",
199 "insert into highlight(fl_fk, type, start, len, rf_start, rf_len) values($1,$2,$3,$4,$5,$6)",
200 long,
char*,
size_t,
size_t,
size_t,
size_t),
203 diffInfo->text.start, diffInfo->text.length,
204 diffInfo->search.start, diffInfo->search.length
210 PQclear(insertResult);
216 size_t matchedInfoLen = matchedInfo->len ;
217 for (
size_t i = 0; i < matchedInfoLen; i++) {
219 if (!saveDiffHighlightToDb(
dbManager, diffMatchInfo, licenseFileId))
char * getUploadTreeTableName(fo_dbManager *dbManager, int uploadId)
Get the upload tree table name for a given upload.
fo_dbManager * dbManager
fo_dbManager object
PGresult * fo_dbManager_ExecPrepared(fo_dbManager_PreparedStatement *preparedStatement,...)
Execute a prepared statement.
int exists
Default not exists.