summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkarsh Simha <akarsh@kde.org>2016-08-16 23:04:32 (GMT)
committerAkarsh Simha <akarsh@kde.org>2016-08-16 23:07:08 (GMT)
commitac46a17dcf2173e152938b1885d9474cbf7340e8 (patch)
treebf5b3dc3ea570ffddef15c082e095313c8647cf3
parent594738bbb811028468a2b4f81599a84e8083bb21 (diff)
Changes to CatalogDB::AddEntry()
1. Make CatalogDB::AddEntry() a public proxy method for a private method CatalogDB::_AddEntry(). 2. The public method opens a DB connection, and closes the DB after use. This is a time-consuming operation, so it is unwise to do so when calling AddEntry multiple times. 3. When loading entire catalogs into the DB, the methods should call the private method _AddEntry(), which does not open/close a DB connection. -- This has not yet been implemented completely in this commit. 4. FindCatalog opens/closes a DB connection, so after calling FindCatalog, we must re-open the DB connection. 5. Allow ID to be specified even when using the Misc catalog.
-rw-r--r--datahandlers/catalogdb.cpp34
-rw-r--r--datahandlers/catalogdb.h31
2 files changed, 48 insertions, 17 deletions
diff --git a/datahandlers/catalogdb.cpp b/datahandlers/catalogdb.cpp
index 6d9618f..0d9ea03 100644
--- a/datahandlers/catalogdb.cpp
+++ b/datahandlers/catalogdb.cpp
@@ -261,8 +261,18 @@ int CatalogDB::FindFuzzyEntry(const double ra, const double dec,
return returnval;
}
+bool CatalogDB::AddEntry(const CatalogEntryData& catalog_entry, int catid) {
+ if( ! skydb_.open() ) {
+ qWarning() << "Failed to open database to add catalog entry!";
+ qWarning() << LastError();
+ return false;
+ }
+ bool retVal = _AddEntry( catalog_entry, catid );
+ skydb_.close();
+ return retVal;
+}
-void CatalogDB::AddEntry(const CatalogEntryData& catalog_entry, int catid)
+bool CatalogDB::_AddEntry(const CatalogEntryData& catalog_entry, int catid)
{
// Verification step
// If RA, Dec are Null, it denotes an invalid object and should not be written
@@ -274,7 +284,7 @@ void CatalogDB::AddEntry(const CatalogEntryData& catalog_entry, int catid)
qDebug() << "Attempt to add incorrect ra & dec with ID:"
<< catalog_entry.ID << " Long Name: "
<< catalog_entry.long_name;
- return;
+ return false;
}
// Part 1: Adding in DSO table
// I will not use QSQLTableModel as I need to execute a query to find
@@ -282,7 +292,6 @@ void CatalogDB::AddEntry(const CatalogEntryData& catalog_entry, int catid)
// Part 2: Fuzzy Match or Create New Entry
int rowuid = FindFuzzyEntry(catalog_entry.ra, catalog_entry.dec, catalog_entry.magnitude);
-
//skydb_.open();
if ( rowuid == -1) { //i.e. No fuzzy match found. Proceed to add new entry
@@ -317,8 +326,10 @@ void CatalogDB::AddEntry(const CatalogEntryData& catalog_entry, int catid)
// correct catalogs and adding things appropriately, but that
// would entail a long project. This should work for the most
// part, though -- asimha
- ID = -1;
+ // ID = -1;
+ skydb_.close();
catid = FindCatalog( "Misc" );
+ Q_ASSERT( skydb_.open() );
if( catid < 0 ) {
CatalogData new_catalog;
@@ -331,12 +342,14 @@ void CatalogDB::AddEntry(const CatalogEntryData& catalog_entry, int catid)
new_catalog.author = "KStars";
new_catalog.license = "Unknown";
+ skydb_.close();
AddCatalog(new_catalog);
catid = FindCatalog( "Misc" );
+ Q_ASSERT( skydb_.open() );
}
if( catid < 0 ) {
qWarning() << "Failed to create Misc catalog for miscellaneous objects! AddEntry operation failed!";
- return;
+ return false;
}
}
@@ -361,6 +374,7 @@ void CatalogDB::AddEntry(const CatalogEntryData& catalog_entry, int catid)
add_od.bindValue(":id", ID);
}
else{
+ qWarning() << "FIXME: This query has not been tested!!!!";
add_od.prepare("INSERT INTO ObjectDesignation (id_Catalog, UID_DSO, LongName"
", IDNumber) VALUES (:catid, :rowuid, :longname,"
"(SELECT MAX(ISNULL(IDNumber,1))+1 FROM ObjectDesignation WHERE id_Catalog = :catid) )"
@@ -369,13 +383,17 @@ void CatalogDB::AddEntry(const CatalogEntryData& catalog_entry, int catid)
add_od.bindValue(":catid", catid);
add_od.bindValue(":rowuid", rowuid);
add_od.bindValue(":longname", catalog_entry.long_name);
+ bool retVal = true;
if (!add_od.exec()) {
- qWarning() << add_od.lastQuery();
- qWarning() << skydb_.lastError();
+ qWarning() << "Query exec failed:";
+ qWarning() << add_od.lastQuery();
+ qWarning() << skydb_.lastError();
+ retVal = false;
}
add_od.clear();
-
//skydb_.close();
+
+ return retVal;
}
QString CatalogDB::GetCatalogName(const QString &fname)
diff --git a/datahandlers/catalogdb.h b/datahandlers/catalogdb.h
index aa10a44..2a4d7f0 100644
--- a/datahandlers/catalogdb.h
+++ b/datahandlers/catalogdb.h
@@ -109,15 +109,6 @@ class CatalogDB {
const double magnitude);
/**
- * @brief Used to add a cross referenced entry into the database
- *
- * @param catalog_entry Data structure with entry details
- * @param catid Category ID in the database
- * @return void
- **/
- void AddEntry(const CatalogEntryData &catalog_entry, int catid);
-
- /**
* @brief Removes the catalog from the database and refreshes the listing.
*
* @param catalog_name Name of the catalog
@@ -150,8 +141,30 @@ class CatalogDB {
void GetCatalogData(const QString& catalog_name,
CatalogData& catalog_data);
+ /**
+ * @brief Used to add a cross referenced entry into the database
+ *
+ * @note This public method opens and closes the database.
+ *
+ * @param catalog_entry Data structure with entry details
+ * @param catid Category ID in the database
+ * @return false if adding was unsuccessful
+ **/
+ bool AddEntry(const CatalogEntryData &catalog_entry, int catid);
private:
/**
+ * @brief Used to add a cross referenced entry into the database
+ *
+ * @note This private method is useful when calling the method
+ * repeatedly on an already-opened DB.
+ *
+ * @param catalog_entry Data structure with entry details
+ * @param catid Category ID in the database
+ * @return false if adding was unsuccessful
+ **/
+ bool _AddEntry(const CatalogEntryData &catalog_entry, int catid);
+
+ /**
* @brief Database object for the sky object. Assigned and Initialized by
* Initialize()
**/