bool TeSQLite::insertPolygon(const string& table, TePolygon &p) { errorMessage_ = ""; std::string objectId = p.objectId(); char* wkb = 0; unsigned int wkbSize = 0; TeWKBGeometryDecoder::encodePolygon(p, wkb, wkbSize); std::string command = "INSERT INTO "; command += table; command += " (object_id, lower_x, lower_y, upper_x, upper_y, spatial_data)"; command += " VALUES (?1, ?2, ?3, ?4, ?5, ?6)"; sqlite3_stmt* recordSet = 0; int retValue = sqlite3_prepare_v2(_conn, command.c_str(), -1, &recordSet, 0); if(retValue != SQLITE_OK) { errorMessage_ = errorMessage(); return false; } sqlite3_bind_text(recordSet, 1, objectId.c_str(), objectId.size(), SQLITE_TRANSIENT); sqlite3_bind_double(recordSet, 2, p.box().x1()); sqlite3_bind_double(recordSet, 3, p.box().y1()); sqlite3_bind_double(recordSet, 4, p.box().x2()); sqlite3_bind_double(recordSet, 5, p.box().y2()); sqlite3_bind_blob(recordSet, 6, wkb, wkbSize, SQLITE_TRANSIENT); delete wkb; retValue = sqlite3_step(recordSet); if(retValue != SQLITE_DONE) { return false; } sqlite3_finalize(recordSet); //int newId = getMaxValue(this, table, "geom_id"); int newId = getLastInsertedSerial(); if(newId >= 0) { p.geomId(newId); } return true; }
bool TeSQLite::updatePolygon(const string& table, TePolygon &p) { errorMessage_ = ""; std::string command = "UPDATE " + table + " SET "; command += "object_id=?"; command += ", lower_x=?, lower_y=?, upper_x=?, upper_y=?, "; command += ", spatial_data=? WHERE geom_id = " + Te2String(p.geomId()); std::string objectId = p.objectId(); char* wkb = 0; unsigned int wkbSize = 0; TeWKBGeometryDecoder::encodePolygon(p, wkb, wkbSize); sqlite3_stmt* recordSet = 0; int retValue = sqlite3_prepare_v2(_conn, command.c_str(), -1, &recordSet, 0); if(retValue != SQLITE_OK) { errorMessage_ = errorMessage(); return false; } sqlite3_bind_text(recordSet, 1, objectId.c_str(), objectId.size(), SQLITE_TRANSIENT); sqlite3_bind_double(recordSet, 2, p.box().x1()); sqlite3_bind_double(recordSet, 3, p.box().y1()); sqlite3_bind_double(recordSet, 4, p.box().x2()); sqlite3_bind_double(recordSet, 5, p.box().y2()); sqlite3_bind_blob(recordSet, 6, wkb, wkbSize, SQLITE_TRANSIENT); delete wkb; retValue = sqlite3_step(recordSet); if(retValue != SQLITE_DONE) { return false; } sqlite3_finalize(recordSet); return true; }