summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkarsh Simha <akarsh@kde.org>2016-05-19 11:21:17 (GMT)
committerAkarsh Simha <akarsh@kde.org>2016-05-20 04:08:42 (GMT)
commit65c7ce93ff1afbf386fb8249e857ee7c59f651cd (patch)
treeb9e049bdcef660f4ee15ba266a2e033b7656e713
parent1d1680a68afa0260c99725175ed06253efd851e6 (diff)
[NOT TESTED] This commit creates a special Misc catalog in the DB
Might remove this too, and do it all properly, depending on how feasible it is to do it before Windows release.
-rw-r--r--datahandlers/catalogdb.cpp44
1 files changed, 41 insertions, 3 deletions
diff --git a/datahandlers/catalogdb.cpp b/datahandlers/catalogdb.cpp
index 38bb6fe..5907715 100644
--- a/datahandlers/catalogdb.cpp
+++ b/datahandlers/catalogdb.cpp
@@ -308,6 +308,36 @@ void CatalogDB::AddEntry(const CatalogEntryData& catalog_entry, int catid)
rowuid = add_query.lastInsertId().toInt();
add_query.clear();
}
+ int ID = catalog_entry.ID;
+ if( catalog_entry.catalog_name == "Misc" || catid < 0 ) {
+ // Add into the Miscellaneous catalog
+
+ // FIXME: This is a hackjob. We should really be identifying the
+ // correct catalogs and adding things appropriately, but that
+ // would entail a long project. This should work for the most
+ // part, though -- asimha
+ ID = -1;
+ catid = FindCatalog( "Misc" );
+ if( catid < 0 ) {
+ CatalogData new_catalog;
+
+ new_catalog.catalog_name = "Misc";
+ new_catalog.prefix = "Misc";
+ new_catalog.color = "#ff0000";
+ new_catalog.epoch = 2000.0;
+ new_catalog.fluxfreq = "400 nm";
+ new_catalog.fluxunit = "mag";
+ new_catalog.author = "KStars";
+ new_catalog.license = "Unknown";
+
+ AddCatalog(new_catalog);
+ catid = FindCatalog( "Misc" );
+ }
+ if( catid < 0 ) {
+ qWarning() << "Failed to create Misc catalog for miscellaneous objects! AddEntry operation failed!";
+ return;
+ }
+ }
/* TODO(spacetime)
* Possible Bugs in QSQL Db with SQLite
@@ -324,12 +354,20 @@ void CatalogDB::AddEntry(const CatalogEntryData& catalog_entry, int catid)
// Part 3: Add in Object Designation
//skydb_.open();
QSqlQuery add_od(skydb_);
- add_od.prepare("INSERT INTO ObjectDesignation (id_Catalog, UID_DSO, LongName"
- ", IDNumber) VALUES (:catid, :rowuid, :longname, :id)");
+ if( ID >= 0 ) {
+ add_od.prepare("INSERT INTO ObjectDesignation (id_Catalog, UID_DSO, LongName"
+ ", IDNumber) VALUES (:catid, :rowuid, :longname, :id)");
+ add_od.bindValue(":id", ID);
+ }
+ else{
+ 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) )"
+ );
+ }
add_od.bindValue(":catid", catid);
add_od.bindValue(":rowuid", rowuid);
add_od.bindValue(":longname", catalog_entry.long_name);
- add_od.bindValue(":id", catalog_entry.ID);
if (!add_od.exec()) {
qWarning() << add_od.lastQuery();
qWarning() << skydb_.lastError();