2
/***************************************************************************
3
QgsBookmarkItem.h - Spatial Bookmark Item
6
copyright : (C) 2005 Gary Sherman
7
email : sherman at mrcc dot com
8
***************************************************************************/
10
/***************************************************************************
12
* This program is free software; you can redistribute it and/or modify *
13
* it under the terms of the GNU General Public License as published by *
14
* the Free Software Foundation; either version 2 of the License, or *
15
* (at your option) any later version. *
17
***************************************************************************/
18
/* $Id: qgsbookmarkitem.cpp 6827 2007-03-23 19:02:37Z homann $ */
22
#include <qtextstream.h>
27
#include "qgsbookmarkitem.h"
29
QgsBookmarkItem::QgsBookmarkItem(QString name, QString projectTitle,
30
QgsRect viewExtent, int srid, QString dbPath)
31
: mName(name), mProjectTitle(projectTitle), mViewExtent(viewExtent),
32
mSrid(srid), mUserDbPath(dbPath)
35
QgsBookmarkItem::~QgsBookmarkItem()
38
void QgsBookmarkItem::store()
40
// To store the bookmark we have to open the database and insert
41
// the record using the parameters set in the constructor
46
std::cout << "Opening user database: " << mUserDbPath.toLocal8Bit().data() << std::endl;
48
rc = sqlite3_open(mUserDbPath.toUtf8().data(), &db);
51
std::cout << "Can't open database: " << sqlite3_errmsg(db) << std::endl;
53
// XXX This will likely never happen since on open, sqlite creates the
54
// database if it does not exist.
57
// prepare the sql statement
61
QTextOStream sqlStream(&sql);
62
sqlStream << "insert into tbl_bookmarks values(null,'" <<
64
mProjectTitle << "'," <<
65
mViewExtent.xMin() << "," <<
66
mViewExtent.yMin() << "," <<
67
mViewExtent.xMax() << "," <<
68
mViewExtent.yMax() << "," <<
72
std::cout << "Storing bookmark using: " << sql.toLocal8Bit().data() << std::endl;
74
rc = sqlite3_prepare(db, sql.utf8(), sql.length(), &ppStmt, &pzTail);
75
// XXX Need to free memory from the error msg if one is set
78
// get the first row of the result set
79
if(sqlite3_step(ppStmt) != SQLITE_DONE)
82
// XXX query failed -- warn the user some how
83
std::cout << "Failed to store bookmark: " << sqlite3_errmsg(db) << std::endl;
85
// close the statement
86
sqlite3_finalize(ppStmt);