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 cd.scope = 0 AND cd.group_fk = $5)"
33 " SELECT 1 FROM report_info ri WHERE ri.upload_fk = ut.upload_fk AND ri.ri_globaldecision = 1"
34 " ) AND ut.pfile_fk = cd.pfile_fk AND cd.scope = 1)"
36 " WHERE upload_fk=$1 AND (ufile_mode&x'3C000000'::int)=0 AND (lft BETWEEN $2 AND $3) AND ut.pfile_fk != 0"
37 " ORDER BY ut.uploadtree_pk, scopesort, ut.pfile_fk, clearing_decision_pk DESC"
38 ") itemView WHERE decision_type!=$4 OR decision_type IS NULL";
39 char* nonVoidPfile =
"SELECT pfile_fk FROM allPfileData"
40 " WHERE pfile_fk NOT IN (SELECT lf.pfile_fk"
41 " FROM license_file lf"
42 " JOIN ars_master am ON lf.agent_fk = am.agent_fk"
43 " JOIN " LICENSE_REF_TABLE
" lr ON lf.rf_fk = lr.rf_pk"
44 " WHERE am.upload_fk = $1"
45 " AND lr.rf_shortname = ANY(VALUES('No_license_found'), ('Void')))";
47 if (!ignoreIrre && !scanFindings)
49 sql = g_strdup_printf(distinctPfile, tablename);
50 stmt = g_strdup_printf(
"queryFileIdsForUploadAndLimits.%s", tablename);
52 fo_dbManager_PrepareStamement(
60 else if(!ignoreIrre && scanFindings)
62 sql = g_strdup_printf(
63 g_strconcat(
"WITH allPfileData AS (", distinctPfile,
") ", nonVoidPfile,
65 stmt = g_strdup_printf(
"queryFileIdsForUploadAndLimitswithlicensefinding.%s", tablename);
67 fo_dbManager_PrepareStamement(
75 else if(ignoreIrre && scanFindings)
77 sql = g_strdup_printf(
78 g_strconcat(
"WITH allPfileData AS (", distinctPfileNoDec,
") ",
79 nonVoidPfile, NULL), tablename);
80 stmt = g_strdup_printf(
"queryFileIdsForUploadAndLimits.%s.ignoreirreandscanFindings", tablename);
82 fo_dbManager_PrepareStamement(
86 int,
long,
long,
int,
long),
87 uploadId, left, right, DECISION_TYPE_FOR_IRRELEVANT, groupId
92 sql = g_strdup_printf(distinctPfileNoDec, tablename);
93 stmt = g_strdup_printf(
"queryFileIdsForUploadAndLimits.%s.ignoreirre", tablename);
95 fo_dbManager_PrepareStamement(
99 int,
long,
long,
int,
long),
100 uploadId, left, right, DECISION_TYPE_FOR_IRRELEVANT, groupId
109 return fo_dbManager_Exec_printf(
111 "select rf_pk, rf_shortname from " LICENSE_REF_TABLE
" where rf_detector_type = 1 and rf_active = 'true'"
117 fo_dbManager_PrepareStamement(
119 "getLicenseTextForLicenseRefId",
120 "select rf_text from " LICENSE_REF_TABLE
" where rf_pk = $1",
125 if (PQntuples(licenseTextResult) != 1) {
126 printf(
"cannot find license text!\n");
127 PQclear(licenseTextResult);
131 char* result = g_strdup(PQgetvalue(licenseTextResult, 0, 0));
132 PQclear(licenseTextResult);
138 fo_dbManager_PrepareStamement(
140 "hasAlreadyResultsFor",
141 "SELECT 1 WHERE EXISTS (SELECT 1"
142 " FROM license_file WHERE agent_fk = $1 AND pfile_fk = $2"
150 exists = (PQntuples(insertResult) == 1);
151 PQclear(insertResult);
159 fo_dbManager_PrepareStamement(
162 "insert into license_file(agent_fk, pfile_fk) values($1,$2)",
170 PQclear(insertResult);
178 fo_dbManager_PrepareStamement(
181 "insert into license_file(rf_fk, agent_fk, pfile_fk, rf_match_pct) values($1,$2,$3,$4) RETURNING fl_pk",
182 long,
int,
long,
unsigned),
183 refId, agentId, pFileId, percent
186 long licenseFilePk = -1;
188 if (PQntuples(insertResult) == 1) {
189 licenseFilePk = atol(PQgetvalue(insertResult, 0, 0));
191 PQclear(insertResult);
194 return licenseFilePk;
199 fo_dbManager_PrepareStamement(
201 "saveDiffHighlightToDb",
202 "insert into highlight(fl_fk, type, start, len, rf_start, rf_len) values($1,$2,$3,$4,$5,$6)",
203 long,
char*,
size_t,
size_t,
size_t,
size_t),
206 diffInfo->text.start, diffInfo->text.length,
207 diffInfo->search.start, diffInfo->search.length
213 PQclear(insertResult);
219 size_t matchedInfoLen = matchedInfo->len ;
220 for (
size_t i = 0; i < matchedInfoLen; i++) {
222 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.