70 "INSERT INTO license_file" 71 "(rf_fk, agent_fk, pfile_fk)" 72 " VALUES($1,$2,$3) RETURNING fl_pk",
94 const unsigned long fl_fk)
const 102 "ojoInsertHighlight",
103 "INSERT INTO highlight" 104 "(fl_fk, start, len, type)" 105 " VALUES($1,$2,$3,'L')",
122 "ojoInsertNoLicense",
123 "INSERT INTO license_file" 124 "(agent_fk, pfile_fk)" 137 bool hasEnding(
string const &firstString,
string const &ending)
139 if (firstString.length() >= ending.length())
142 == firstString.compare(firstString.length() - ending.length(),
143 ending.length(), ending));
166 bool success =
false;
167 unsigned long result = 0;
173 unicodeCleanShortname.toUTF8String(rfShortName);
177 "selectLicenseIdWithOrOJO",
178 "SELECT rf_pk FROM ONLY license_ref" 179 " WHERE LOWER(rf_shortname) = LOWER($1)" 180 " OR LOWER(rf_shortname) = LOWER($2)" 181 " ORDER BY rf_pk ASC;",
188 string tempShortName(rfShortName);
190 std::transform(tempShortName.begin(), tempShortName.end(), tempShortName.begin(),
193 string orLater(
"-or-later");
195 unsigned long int plusLast = tempShortName.rfind(plus);
196 unsigned long int orLaterLast = tempShortName.rfind(orLater);
199 if (plusLast != string::npos)
201 tempShortName.erase(plusLast, string::npos);
203 if (orLaterLast != string::npos)
205 tempShortName.erase(orLaterLast, string::npos);
209 (tempShortName + plus).c_str(), (tempShortName + orLater).c_str());
211 success = queryResult && queryResult.
getRowCount() > 0;
219 string tempShortName(rfShortName);
221 std::transform(tempShortName.begin(), tempShortName.end(), tempShortName.begin(),
223 string only(
"-only");
225 unsigned long int onlyLast = tempShortName.rfind(only);
228 if (onlyLast != string::npos)
230 tempShortName.erase(onlyLast, string::npos);
234 tempShortName.c_str(), (tempShortName + only).c_str());
236 success = queryResult && queryResult.
getRowCount() > 0;
249 while ((!success) && count++ < 3)
259 "selectOrInsertLicenseIdForNameOjo",
261 "selectExisting AS (" 262 "SELECT rf_pk FROM ONLY license_ref" 263 " WHERE LOWER(rf_shortname) = LOWER($1)" 266 "INSERT INTO license_ref(rf_shortname, rf_text, rf_detector_type)" 268 " WHERE NOT EXISTS(SELECT * FROM selectExisting)" 272 "SELECT rf_pk FROM insertNew " 274 "SELECT rf_pk FROM selectExisting",
277 rfShortName.c_str(),
"License by OJO.", 3);
279 success = queryResult && queryResult.
getRowCount() > 0;
309 string const &rfShortName)
326 string const &rfShortName)
const 328 std::unordered_map<string, long>::const_iterator findIterator =
332 return findIterator->second;
unsigned long getLicenseIdForName(std::string const &rfShortName)
Get the license id for a given short name.
std::vector< unsigned long > queryFileIdsVectorForUpload(int uploadId, bool ignoreFilesWithMimeType) const
Get pfile ids for a given upload id.
unsigned long saveLicenseToDatabase(OjoDatabaseEntry &entry) const
Save findings to the database if agent was called by scheduler.
Store the results of a regex match.
QueryResult execPrepared(fo_dbManager_PreparedStatement *stmt,...) const
Execute a prepared statement with new parameters.
bool hasEnding(string const &firstString, string const &ending)
OjosDatabaseHandler(fo::DbManager dbManager)
fo_dbManager * getStruct_dbManager() const
unsigned long stringToUnsignedLong(const char *string)
Database handler for OJO.
unsigned long selectOrInsertLicenseIdForName(std::string rfShortname)
Database handler for agents.
bool saveHighlightToDatabase(const ojomatch &match, const unsigned long fl_fk) const
OjosDatabaseHandler spawn() const
std::unordered_map< std::string, long > licenseRefCache
QueryResult queryPrintf(const char *queryFormat,...) const
Execute a query in printf format.
fo_dbManager * dbManager
fo_dbManager object
fo namespace holds the FOSSology library functions.
unsigned long getCachedLicenseIdForName(std::string const &rfShortName) const
const unsigned long int agent_fk
bool insertNoResultInDatabase(OjoDatabaseEntry &entry) const
Save no result to the database.
icu::UnicodeString recodeToUnicode(const std::string &input)
std::vector< T > getSimpleResults(int columnN, T(functionP)(const char *)) const
Get vector of a single column from query result.
DbManager dbManager
DbManager to use.
const unsigned long int license_fk
const unsigned long int pfile_fk
std::vector< unsigned long > queryFileIdsForUpload(int uploadId, bool ignoreFilesWithMimeType)
Store the results of a regex match.