Skip to content
Permalink
Browse files
added openDb
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4936 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Mar 2, 2006
1 parent a91787b commit f2899357b0782ae97046a1a355a4c2a90dbf7a4f
Showing with 44 additions and 40 deletions.
  1. +38 −40 src/gui/qgsspatialrefsys.cpp
  2. +6 −0 src/gui/qgsspatialrefsys.h
@@ -10,6 +10,7 @@
#include <qdir.h>
#include <projects.h>
#include <qdom.h>
#include <QMessageBox>

#include <qgsapplication.h>
#include <qgslayerprojectionselector.h>
@@ -200,13 +201,10 @@ bool QgsSpatialRefSys::createFromSrid(long theSrid)
sqlite3_stmt *myPreparedStatement;
int myResult;
//check the db is available
myResult = sqlite3_open(myDatabaseFileName.toLocal8Bit().data(), &myDatabase);
myResult = openDb(myDatabaseFileName, &myDatabase);
if(myResult)
{
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
assert(myResult == 0);
return false;
}

/*
@@ -319,13 +317,10 @@ bool QgsSpatialRefSys::createFromEpsg(long theEpsg)
sqlite3_stmt *myPreparedStatement;
int myResult;
//check the db is available
myResult = sqlite3_open(myDatabaseFileName.toLocal8Bit().data(), &myDatabase);
myResult = openDb(myDatabaseFileName, &myDatabase);
if(myResult)
{
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
assert(myResult == 0);
return false;
}

/*
@@ -404,13 +399,10 @@ bool QgsSpatialRefSys::createFromSrsId (long theSrsId)
sqlite3_stmt *myPreparedStatement;
int myResult;
//check the db is available
myResult = sqlite3_open(myDatabaseFileName.toLocal8Bit().data(), &myDatabase);
myResult = openDb(myDatabaseFileName, &myDatabase);
if(myResult)
{
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
assert(myResult == 0);
return false;
}

/*
@@ -601,18 +593,13 @@ QgsSpatialRefSys::RecordMap QgsSpatialRefSys::getRecord(QString theSql)
// Get the full path name to the sqlite3 spatial reference database.
myDatabaseFileName = QgsApplication::srsDbFilePath();


//check the db is available
myResult = sqlite3_open(myDatabaseFileName.toLocal8Bit().data(), &myDatabase);
myResult = openDb(myDatabaseFileName, &myDatabase);
if(myResult)
{
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
assert(myResult == 0);
return myMap;
}


myResult = sqlite3_prepare(myDatabase, theSql.utf8(), theSql.length(), &myPreparedStatement, &myTail);
// XXX Need to free memory from the error msg if one is set
if(myResult == SQLITE_OK && sqlite3_step(myPreparedStatement) == SQLITE_ROW)
@@ -644,16 +631,12 @@ QgsSpatialRefSys::RecordMap QgsSpatialRefSys::getRecord(QString theSql)
}

//check the db is available
myResult = sqlite3_open(myDatabaseFileName.toLocal8Bit().data(), &myDatabase);
myResult = openDb(myDatabaseFileName, &myDatabase);
if(myResult)
{
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
assert(myResult == 0);
return myMap;
}


myResult = sqlite3_prepare(myDatabase, theSql.utf8(), theSql.length(), &myPreparedStatement, &myTail);
// XXX Need to free memory from the error msg if one is set
if(myResult == SQLITE_OK && sqlite3_step(myPreparedStatement) == SQLITE_ROW)
@@ -937,13 +920,10 @@ long QgsSpatialRefSys::findMatchingProj()


//check the db is available
myResult = sqlite3_open(myDatabaseFileName.toLocal8Bit().data(), &myDatabase);
myResult = openDb(myDatabaseFileName, &myDatabase);
if(myResult)
{
std::cout << "QgsSpatialRefSys::findMatchingProj Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
assert(myResult == 0);
return 0;
}

myResult = sqlite3_prepare(myDatabase, mySql.utf8(), mySql.length(), &myPreparedStatement, &myTail);
@@ -979,10 +959,9 @@ long QgsSpatialRefSys::findMatchingProj()

myDatabaseFileName = QDir::homeDirPath () + "/.qgis/qgis.db";
//check the db is available
myResult = sqlite3_open(myDatabaseFileName.toLocal8Bit().data(), &myDatabase);
myResult = openDb(myDatabaseFileName, &myDatabase);
if(myResult)
{
std::cout << "QgsSpatialRefSys::findMatchingProj Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
std::cout << "This is a non critical error" << std::endl;
return 0;
}
@@ -1258,13 +1237,10 @@ QString QgsSpatialRefSys::getProj4FromSrsId(const int theSrsId)

sqlite3 *db;
int rc;
rc = sqlite3_open(myDatabaseFileName.toLocal8Bit().data(), &db);
rc = openDb(myDatabaseFileName, &db);
if(rc)
{
std::cout << "Can't open database: " << sqlite3_errmsg(db) << std::endl;
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
assert(rc == 0);
return QString();
}
// prepare the sql statement
const char *pzTail;
@@ -1288,3 +1264,25 @@ QString QgsSpatialRefSys::getProj4FromSrsId(const int theSrsId)
//assert(myProjString.length() > 0);
return myProjString;
}

int QgsSpatialRefSys::openDb(QString path, sqlite3 **db)
{
#ifdef QGISDEBUG
std::cout << "QgsSpatialRefSys::openDb path = " << path.toLocal8Bit().data() << std::endl;
#endif
int myResult = sqlite3_open(path.toLocal8Bit().data(), db);

if(myResult)
{
std::cout << "Can't open database: " << sqlite3_errmsg(*db) << std::endl;

// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
// ... unfortunately it happens on Windows
QMessageBox::warning(0,"Error","Could not open SRS database "
+ path + "<br>Error(" + QString::number(myResult)
+ "): " + QString(sqlite3_errmsg(*db)) );

}
return myResult;
}
@@ -13,6 +13,8 @@
class QDomNode;
class QDomDocument;

#include <sqlite3.h>

//qgis includes
#include <qgis.h>

@@ -305,6 +307,10 @@ class QgsSpatialRefSys
*/
void setEllipsoidAcronym(QString theEllipsoidAcronym);
private:
// Open SQLite db and show message if ccannot be opened
// returns the same code as sqlite3_open
static int openDb ( QString path, sqlite3 **db );

//!The internal sqlite3 srs.db primary key for this srs
long mSrsId;
//!A textual description of the srs.

0 comments on commit f289935

Please sign in to comment.