std::string getDisplayTime(const TimeStamp timeStamp) { std::ostringstream timeString; if (timeStamp.seconds()) { timeString << getSQLTime(timeStamp.seconds()).getDateTime() << '.' << std::setw(6) << std::setfill('0') << timeStamp.microseconds(); return timeString.str(); } return "Not seen"; }
bool TeSQLite::insertTheme(TeAbstractTheme *theme) { errorMessage_ = ""; string sql = "INSERT INTO te_theme (layer_id, view_id, name, parent_id, priority, node_type, "; sql += "min_scale, max_scale, generate_attribute_where, generate_spatial_where, "; sql += "generate_temporal_where, collection_table, visible_rep, enable_visibility, "; sql += "lower_x, lower_y, upper_x, upper_y, creation_time) VALUES("; if(theme->type()==TeTHEME) sql += Te2String(static_cast<TeTheme*>(theme)->layerId()); else sql += " NULL "; sql += ", "; sql += Te2String(theme->view()); sql += ", '"; sql += theme->name(); sql += "', "; sql += Te2String(theme->parentId()); sql += ", "; sql += Te2String(theme->priority()); sql += ", "; sql += Te2String(theme->type()); sql += ", "; sql += Te2String(theme->minScale(), 15); sql += ", "; sql += Te2String(theme->maxScale(), 15); sql += ", '"; sql += escapeSequence(theme->attributeRest()); sql += "', '"; sql += escapeSequence(theme->spatialRest()); sql += "', '"; sql += escapeSequence(theme->temporalRest()); sql += "', '"; if(theme->type()==TeTHEME) sql += static_cast<TeTheme*>(theme)->collectionTable(); sql += "', "; sql += Te2String(theme->visibleRep()); sql += ", "; sql += Te2String(theme->visibility()); sql += ", "; sql += Te2String(theme->box().x1(), 15); sql += ", "; sql += Te2String(theme->box().y1(), 15); sql += ", "; sql += Te2String(theme->box().x2(), 15); sql += ", "; sql += Te2String(theme->box().y2(), 15); sql += ", "; TeTime creationTime = theme->getCreationTime(); sql += getSQLTime(creationTime); sql += " )"; if(this->execute(sql)) { //int newId = getMaxValue(this, "te_theme", "theme_id"); int newId = getLastInsertedSerial(); if(newId >= 0) { theme->id(newId); } } else return false; if((theme->type()==TeTHEME || theme->type()==TeEXTERNALTHEME) && static_cast<TeTheme*>(theme)->collectionTable().empty()) { sql = "UPDATE te_theme SET"; sql += " collection_table = 'te_collection_" + Te2String(theme->id()) + "'"; sql += " WHERE theme_id = "; sql += Te2String(theme->id()); static_cast<TeTheme*>(theme)->collectionTable(string("te_collection_") + Te2String(theme->id())); if(!this->execute(sql)) return false; } if(theme->parentId() == 0) { std::string sql = "UPDATE te_theme SET"; sql += " parent_id = " + Te2String(theme->id()); sql += " WHERE theme_id = "; sql += Te2String(theme->id()); theme->parentId(theme->id()); if(!this->execute(sql)) return false; } bool status; // insert grouping int numSlices = 0; if(theme->grouping().groupMode_ != TeNoGrouping) { if(!insertGrouping (theme->id(), theme->grouping())) return false; numSlices = theme->grouping().groupNumSlices_; } // insert legend theme->outOfCollectionLegend().group(-1); theme->outOfCollectionLegend().theme(theme->id()); status = insertLegend (&(theme->outOfCollectionLegend())); if (!status) return status; theme->withoutDataConnectionLegend().group(-2); theme->withoutDataConnectionLegend().theme(theme->id()); status = insertLegend (&(theme->withoutDataConnectionLegend())); if (!status) return status; theme->defaultLegend().group(-3); theme->defaultLegend().theme(theme->id()); status = insertLegend (&(theme->defaultLegend())); if (!status) return status; theme->pointingLegend().group(-4); theme->pointingLegend().theme(theme->id()); status = insertLegend (&(theme->pointingLegend())); if (!status) return status; theme->queryLegend().group(-5); theme->queryLegend().theme(theme->id()); status = insertLegend (&(theme->queryLegend())); if (!status) return status; theme->queryAndPointingLegend().group(-6); theme->queryAndPointingLegend().theme(theme->id()); status = insertLegend (&(theme->queryAndPointingLegend())); if (!status) return status; for (int i = 0; i < numSlices; i++) { theme->legend()[i].group(i); theme->legend()[i].theme(theme->id()); status = insertLegend (&(theme->legend()[i])); if (!status) return status; } if (!status) return status; //insert metadata theme if(!theme->saveMetadata(this)) return false; themeMap()[theme->id()] = theme; if(theme->type()==TeTHEME && !updateThemeTable(static_cast<TeTheme*>(theme))) return false; return true; }