18 #include "databasehandler.hpp" 31 vector<unsigned long> NinkaDatabaseHandler::queryFileIdsForUpload(
int uploadId)
33 return queryFileIdsVectorForUpload(uploadId);
37 bool NinkaDatabaseHandler::saveLicenseMatch(
int agentId,
long pFileId,
long licenseId,
unsigned percentMatch)
40 fo_dbManager_PrepareStamement(
43 "INSERT INTO license_file (agent_fk, pfile_fk, rf_fk, rf_match_pct) VALUES ($1, $2, $3, $4)",
44 int, long, long, unsigned
53 unsigned long NinkaDatabaseHandler::selectOrInsertLicenseIdForName(
string rfShortName)
56 unsigned long result = 0;
59 while ((!success) && count++<3)
64 dbManager.queryPrintf(
"LOCK TABLE license_ref");
67 fo_dbManager_PrepareStamement(
69 "selectOrInsertLicenseIdForName",
72 "SELECT rf_pk FROM ONLY license_ref" 73 " WHERE rf_shortname = $1" 76 "INSERT INTO license_ref(rf_shortname, rf_text, rf_detector_type)" 78 " WHERE NOT EXISTS(SELECT * FROM selectExisting)" 82 "SELECT rf_pk FROM insertNew " 84 "SELECT rf_pk FROM selectExisting",
92 success = queryResult && queryResult.
getRowCount() > 0;
114 void NinkaDatabaseHandler::insertOrCacheLicenseIdForName(
string const& rfShortName)
116 if (getCachedLicenseIdForName(rfShortName)==0)
118 unsigned long licenseId = selectOrInsertLicenseIdForName(rfShortName);
122 licenseRefCache.insert(std::make_pair(rfShortName, licenseId));
127 unsigned long NinkaDatabaseHandler::getCachedLicenseIdForName(
string const& rfShortName)
const 129 std::unordered_map<string,long>::const_iterator findIterator = licenseRefCache.find(rfShortName);
130 if (findIterator != licenseRefCache.end())
132 return findIterator->second;
unsigned long stringToUnsignedLong(const char *string)
Database handler for agents.
fo_dbManager * dbManager
fo_dbManager object
General utility functions for CPP.
fo namespace holds the FOSSology library functions.
std::vector< T > getSimpleResults(int columnN, T(functionP)(const char *)) const
Get vector of a single column from query result.