33 int uploadId,
int agentId,
bool ignoreFilesWithMimeType)
61 "INSERT INTO license_file"
62 "(rf_fk, agent_fk, pfile_fk)"
63 " VALUES($1,$2,$3) RETURNING fl_pk",
85 const unsigned long fl_fk)
const
94 "INSERT INTO highlight"
95 "(fl_fk, start, len, type)"
96 " VALUES($1,$2,$3,'L')",
113 "ojoInsertNoLicense",
114 "INSERT INTO license_file"
115 "(agent_fk, pfile_fk)"
128 bool hasEnding(
string const &firstString,
string const &ending)
130 if (firstString.length() >= ending.length())
133 == firstString.compare(firstString.length() - ending.length(),
134 ending.length(), ending));
161 string rfShortName,
const int groupId,
const int userId)
163 bool success =
false;
164 unsigned long result = 0;
170 unicodeCleanShortname.toUTF8String(rfShortName);
174 "selectLicenseIdWithOrOJO",
175 "WITH mainLicense AS ("
176 " SELECT rf_pk, 1 AS prior FROM ONLY license_ref"
177 " WHERE LOWER(rf_shortname) = LOWER($1)"
178 " OR LOWER(rf_shortname) = LOWER($2)"
179 "), candidateLicense AS ("
180 " SELECT rf_pk, 2 AS prior FROM license_candidate"
181 " WHERE (LOWER(rf_shortname) = LOWER($1)"
182 " OR LOWER(rf_shortname) = LOWER($2))"
185 "SELECT rf_pk, prior FROM mainLicense "
187 "SELECT rf_pk, prior FROM candidateLicense "
195 string tempShortName(rfShortName);
197 std::transform(tempShortName.begin(), tempShortName.end(), tempShortName.begin(),
200 string orLater(
"-or-later");
202 unsigned long int plusLast = tempShortName.rfind(plus);
203 unsigned long int orLaterLast = tempShortName.rfind(orLater);
206 if (plusLast != string::npos)
208 tempShortName.erase(plusLast, string::npos);
210 if (orLaterLast != string::npos)
212 tempShortName.erase(orLaterLast, string::npos);
216 (tempShortName + plus).c_str(), (tempShortName + orLater).c_str(),
219 success = queryResult && queryResult.
getRowCount() > 0;
227 string tempShortName(rfShortName);
229 std::transform(tempShortName.begin(), tempShortName.end(), tempShortName.begin(),
231 string only(
"-only");
233 unsigned long int onlyLast = tempShortName.rfind(only);
236 if (onlyLast != string::npos)
238 tempShortName.erase(onlyLast, string::npos);
242 tempShortName.c_str(), (tempShortName + only).c_str(), groupId);
244 success = queryResult && queryResult.
getRowCount() > 0;
267 while ((!success) && count++ < 3)
277 "selectOrInsertLicenseIdForNameOjo",
279 "selectExisting AS ("
280 "SELECT rf_pk FROM ONLY license_ref"
281 " WHERE LOWER(rf_shortname) = LOWER($1)"
284 "INSERT INTO license_candidate"
285 "(rf_shortname, rf_text, rf_detector_type, group_fk, "
286 "rf_user_fk_created, rf_user_fk_modified)"
287 " SELECT $1, $2, $3, $4, $5, $5"
288 " WHERE NOT EXISTS(SELECT * FROM selectExisting)"
292 "SELECT rf_pk FROM insertNew "
294 "SELECT rf_pk FROM selectExisting",
295 char*,
char*,
int,
int,
int
297 rfShortName.c_str(),
"License by OJO.", 3, groupId, userId);
299 success = queryResult && queryResult.
getRowCount() > 0;
331 string const &rfShortName,
const int groupId,
const int userId)
348 string const &rfShortName)
const
350 std::unordered_map<string, long>::const_iterator findIterator =
354 return findIterator->second;
bool hasEnding(string const &firstString, string const &ending)
Database handler for OJO.
unsigned long getCachedLicenseIdForName(std::string const &rfShortName) const
OjosDatabaseHandler spawn() const
std::vector< unsigned long > queryFileIdsForUpload(int uploadId, int agentId, bool ignoreFilesWithMimeType)
bool insertNoResultInDatabase(OjoDatabaseEntry &entry) const
Save no result to the database.
bool saveHighlightToDatabase(const ojomatch &match, const unsigned long fl_fk) const
unsigned long saveLicenseToDatabase(OjoDatabaseEntry &entry) const
Save findings to the database if agent was called by scheduler.
std::unordered_map< std::string, long > licenseRefCache
OjosDatabaseHandler(fo::DbManager dbManager)
unsigned long selectOrInsertLicenseIdForName(std::string rfShortname, const int groupId, const int userId)
unsigned long getLicenseIdForName(std::string const &rfShortName, const int groupId, const int userId)
Get the license id for a given short name.
Database handler for agents.
std::vector< unsigned long > queryFileIdsVectorForUpload(int uploadId, bool ignoreFilesWithMimeType) const
Get pfile ids for a given upload id.
DbManager dbManager
DbManager to use.
QueryResult execPrepared(fo_dbManager_PreparedStatement *stmt,...) const
Execute a prepared statement with new parameters.
QueryResult queryPrintf(const char *queryFormat,...) const
Execute a query in printf format.
fo_dbManager * getStruct_dbManager() const
std::vector< T > getSimpleResults(int columnN, T(functionP)(const char *)) const
Get vector of a single column from query result.
fo_dbManager * dbManager
fo_dbManager object
fo namespace holds the FOSSology library functions.
unsigned long stringToUnsignedLong(const char *string)
icu::UnicodeString recodeToUnicode(const std::string &input)
const unsigned long int license_fk
const unsigned long int agent_fk
const unsigned long int pfile_fk
Store the results of a regex match.
Store the results of a regex match.