pgsql: Use booleans instead of varchar to return creation status
This commit is contained in:
parent
cd23262e41
commit
ec0aad9b7a
@ -129,11 +129,11 @@ func (pgSQL *pgSQL) insertFeatureVersion(featureVersion database.FeatureVersion)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find or create FeatureVersion.
|
// Find or create FeatureVersion.
|
||||||
var newOrExisting string
|
var created bool
|
||||||
|
|
||||||
t = time.Now()
|
t = time.Now()
|
||||||
err = tx.QueryRow(soiFeatureVersion, featureID, &featureVersion.Version).
|
err = tx.QueryRow(soiFeatureVersion, featureID, &featureVersion.Version).
|
||||||
Scan(&newOrExisting, &featureVersion.ID)
|
Scan(&created, &featureVersion.ID)
|
||||||
observeQueryTime("insertFeatureVersion", "soiFeatureVersion", t)
|
observeQueryTime("insertFeatureVersion", "soiFeatureVersion", t)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -141,8 +141,9 @@ func (pgSQL *pgSQL) insertFeatureVersion(featureVersion database.FeatureVersion)
|
|||||||
return 0, handleError("soiFeatureVersion", err)
|
return 0, handleError("soiFeatureVersion", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if newOrExisting == "exi" {
|
if !created {
|
||||||
// That featureVersion already exists, return its id.
|
// The featureVersion already existed, no need to link it to
|
||||||
|
// vulnerabilities.
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
|
|
||||||
if pgSQL.cache != nil {
|
if pgSQL.cache != nil {
|
||||||
|
@ -63,9 +63,9 @@ const (
|
|||||||
WHERE NOT EXISTS (SELECT id FROM FeatureVersion WHERE feature_id = $1 AND version = $2)
|
WHERE NOT EXISTS (SELECT id FROM FeatureVersion WHERE feature_id = $1 AND version = $2)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
)
|
)
|
||||||
SELECT 'exi', id FROM FeatureVersion WHERE feature_id = $1 AND version = $2
|
SELECT false, id FROM FeatureVersion WHERE feature_id = $1 AND version = $2
|
||||||
UNION
|
UNION
|
||||||
SELECT 'new', id FROM new_featureversion`
|
SELECT true, id FROM new_featureversion`
|
||||||
|
|
||||||
searchVulnerabilityFixedInFeature = `
|
searchVulnerabilityFixedInFeature = `
|
||||||
SELECT id, vulnerability_id, version FROM Vulnerability_FixedIn_Feature
|
SELECT id, vulnerability_id, version FROM Vulnerability_FixedIn_Feature
|
||||||
@ -167,9 +167,9 @@ const (
|
|||||||
WHERE NOT EXISTS (SELECT id FROM Vulnerability_FixedIn_Feature WHERE vulnerability_id = $1 AND feature_id = $2)
|
WHERE NOT EXISTS (SELECT id FROM Vulnerability_FixedIn_Feature WHERE vulnerability_id = $1 AND feature_id = $2)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
)
|
)
|
||||||
SELECT 'exi', id FROM Vulnerability_FixedIn_Feature WHERE vulnerability_id = $1 AND feature_id = $2
|
SELECT false, id FROM Vulnerability_FixedIn_Feature WHERE vulnerability_id = $1 AND feature_id = $2
|
||||||
UNION
|
UNION
|
||||||
SELECT 'new', id FROM new_fixedinfeature`
|
SELECT true, id FROM new_fixedinfeature`
|
||||||
|
|
||||||
searchFeatureVersionByFeature = `SELECT id, version FROM FeatureVersion WHERE feature_id = $1`
|
searchFeatureVersionByFeature = `SELECT id, version FROM FeatureVersion WHERE feature_id = $1`
|
||||||
|
|
||||||
|
@ -433,22 +433,22 @@ func (pgSQL *pgSQL) insertVulnerabilityFixedInFeatureVersions(tx *sql.Tx, vulner
|
|||||||
|
|
||||||
for _, fv := range fixedIn {
|
for _, fv := range fixedIn {
|
||||||
var fixedInID int
|
var fixedInID int
|
||||||
var newOrExisting string
|
var created bool
|
||||||
|
|
||||||
// Find or create entry in Vulnerability_FixedIn_Feature.
|
// Find or create entry in Vulnerability_FixedIn_Feature.
|
||||||
err = tx.QueryRow(
|
err = tx.QueryRow(
|
||||||
soiVulnerabilityFixedInFeature,
|
soiVulnerabilityFixedInFeature,
|
||||||
vulnerabilityID, fv.Feature.ID,
|
vulnerabilityID, fv.Feature.ID,
|
||||||
&fv.Version,
|
&fv.Version,
|
||||||
).Scan(&newOrExisting, &fixedInID)
|
).Scan(&created, &fixedInID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return handleError("insertVulnerabilityFixedInFeature", err)
|
return handleError("insertVulnerabilityFixedInFeature", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if newOrExisting == "exi" {
|
if !created {
|
||||||
// The relationship between the feature and the vulnerability already
|
// The relationship between the feature and the vulnerability already
|
||||||
// exists, there's no need to update Vulnerability_Affects_FeatureVersion.
|
// existed, no need to update Vulnerability_Affects_FeatureVersion.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user