~ubuntu-branches/ubuntu/hardy/qgis/hardy

« back to all changes in this revision

Viewing changes to src/qgsbookmarkitem.cpp

  • Committer: Bazaar Package Importer
  • Author(s): William Grant
  • Date: 2007-05-06 13:42:32 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070506134232-pyli6t388w5asd8x
Tags: 0.8.0-3ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules, debian/qgis.install, debian/qgis.dirs debian/qgis.desktop:
    Add and install .desktop.
* debian/qgis.desktop: Remove Applications category; it's not real.
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/***************************************************************************
3
 
               QgsBookmarkItem.h  - Spatial Bookmark Item
4
 
                             -------------------
5
 
    begin                : 2005-04-23
6
 
    copyright            : (C) 2005 Gary Sherman
7
 
    email                : sherman at mrcc dot com
8
 
 ***************************************************************************/
9
 
 
10
 
/***************************************************************************
11
 
 *                                                                         *
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.                                   *
16
 
 *                                                                         *
17
 
 ***************************************************************************/
18
 
 /* $Id: qgsbookmarkitem.cpp,v 1.2.2.1 2005/07/09 23:51:17 timlinux Exp $ */
19
 
#include <iostream>
20
 
#include <sqlite3.h>
21
 
#include <qstring.h>
22
 
#include <qtextstream.h>
23
 
 
24
 
#include <cassert>
25
 
 
26
 
#include "qgsrect.h"
27
 
#include "qgsbookmarkitem.h"
28
 
 
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)
33
 
{
34
 
}
35
 
QgsBookmarkItem::~QgsBookmarkItem()
36
 
{
37
 
}
38
 
  void QgsBookmarkItem::store()
39
 
{
40
 
  // To store the bookmark we have to open the database and insert
41
 
  // the record using the parameters set in the constructor
42
 
 
43
 
  sqlite3 *db;
44
 
  char *zErrMsg = 0;
45
 
  int rc;
46
 
#ifdef QGISDEBUG 
47
 
  std::cout << "Opening user database: " << mUserDbPath.local8Bit() << std::endl; 
48
 
#endif 
49
 
  rc = sqlite3_open(mUserDbPath.local8Bit(), &db);
50
 
  if(rc)
51
 
  {
52
 
    std::cout <<  "Can't open database: " <<  sqlite3_errmsg(db) << std::endl;
53
 
 
54
 
    // XXX This will likely never happen since on open, sqlite creates the
55
 
    //     database if it does not exist.
56
 
    assert(rc == 0);
57
 
  }
58
 
  // prepare the sql statement
59
 
  const char *pzTail;
60
 
  sqlite3_stmt *ppStmt;
61
 
  char *pzErrmsg;
62
 
  QString sql;
63
 
  QTextOStream sqlStream(&sql);
64
 
  sqlStream << "insert into tbl_bookmarks values(null,'" <<
65
 
    mName << "','" <<
66
 
    mProjectTitle << "'," <<
67
 
    mViewExtent.xMin() << "," <<
68
 
    mViewExtent.yMin() << "," <<
69
 
    mViewExtent.xMax() << "," <<
70
 
    mViewExtent.yMax() << "," <<
71
 
    mSrid << ")";
72
 
 
73
 
#ifdef QGISDEBUG 
74
 
  std::cout << "Storing bookmark using: " << sql.local8Bit() << std::endl; 
75
 
#endif 
76
 
  rc = sqlite3_prepare(db, sql.utf8(), sql.length(), &ppStmt, &pzTail);
77
 
  // XXX Need to free memory from the error msg if one is set
78
 
  if(rc == SQLITE_OK)
79
 
  {
80
 
    // get the first row of the result set
81
 
    if(sqlite3_step(ppStmt) != SQLITE_DONE)
82
 
    {
83
 
 
84
 
      // XXX query failed -- warn the user some how
85
 
      std::cout << "Failed to store bookmark: " << sqlite3_errmsg(db) << std::endl; 
86
 
    }
87
 
    // close the statement
88
 
    sqlite3_finalize(ppStmt);
89
 
    // close the database
90
 
    sqlite3_close(db);
91
 
  }
92
 
 
93
 
 
94
 
}