Skip to content

Commit 812c557

Browse files
author
jef
committed
fix #2588
git-svn-id: http://svn.osgeo.org/qgis/trunk@13155 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e62cf91 commit 812c557

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

resources/qgis.db

2 KB
Binary file not shown.

src/app/qgisapp.cpp

+58-1
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,64 @@ bool QgisApp::createDB()
20562056
return FALSE;
20572057
}
20582058
}
2059-
return TRUE;
2059+
else
2060+
{
2061+
// migrate if necessary
2062+
sqlite3 *db;
2063+
if ( sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8().constData(), &db ) != SQLITE_OK )
2064+
{
2065+
QMessageBox::critical( this, tr( "Private qgis.db" ), tr( "Could not open qgis.db" ) );
2066+
return false;
2067+
}
2068+
2069+
char *errmsg;
2070+
int res = sqlite3_exec( db, "SELECT epsg FROM tbl_srs LIMIT 0", 0, 0, &errmsg );
2071+
if ( res == SQLITE_OK )
2072+
{
2073+
// epsg column exists => need migration
2074+
if ( sqlite3_exec( db,
2075+
"ALTER TABLE tbl_srs RENAME TO tbl_srs_bak;"
2076+
"CREATE TABLE tbl_srs ("
2077+
"srs_id INTEGER PRIMARY KEY,"
2078+
"description text NOT NULL,"
2079+
"projection_acronym text NOT NULL,"
2080+
"ellipsoid_acronym NOT NULL,"
2081+
"parameters text NOT NULL,"
2082+
"srid integer,"
2083+
"auth_name varchar,"
2084+
"auth_id varchar,"
2085+
"is_geo integer NOT NULL,"
2086+
"deprecated boolean);"
2087+
"CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);"
2088+
"DROP VIEW vw_srs;"
2089+
"CREATE VIEW vw_srs as "
2090+
"select a.description as description,"
2091+
"a.srs_id as srs_id,"
2092+
"a.is_geo as is_geo,"
2093+
"b.name as name,"
2094+
"a.parameters as parameters,"
2095+
"a.auth_name as auth_name,"
2096+
"a.auth_id as auth_id,"
2097+
"a.deprecated as deprecated"
2098+
" from "
2099+
"tbl_srs a inner join tbl_projection b on a.projection_acronym=b.acronym"
2100+
" order by "
2101+
"b.name,"
2102+
"a.description;"
2103+
"INSERT INTO tbl_srs(srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,auth_name,auth_id,is_geo,deprecated) SELECT srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,'','',is_geo,0 FROM tbl_srs_bak;"
2104+
"DROP TABLE tbl_srs_bak", 0, 0, &errmsg ) != SQLITE_OK
2105+
)
2106+
{
2107+
QMessageBox::critical( this, tr( "Private qgis.db" ), tr( "Migration of private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) ) );
2108+
sqlite3_free( errmsg );
2109+
sqlite3_close( db );
2110+
return false;
2111+
}
2112+
}
2113+
2114+
sqlite3_close( db );
2115+
}
2116+
return true;
20602117
}
20612118

20622119
void QgisApp::createMapTips()

src/core/qgscoordinatereferencesystem.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ QgsCoordinateReferenceSystem::RecordMap QgsCoordinateReferenceSystem::getRecord(
508508
}
509509
else
510510
{
511-
QgsDebugMsg( "trying system qgis.db" );
511+
QgsDebugMsg( "trying user qgis.db" );
512512
sqlite3_finalize( myPreparedStatement );
513513
sqlite3_close( myDatabase );
514514

@@ -517,7 +517,7 @@ QgsCoordinateReferenceSystem::RecordMap QgsCoordinateReferenceSystem::getRecord(
517517
myFileInfo.setFile( myDatabaseFileName );
518518
if ( !myFileInfo.exists( ) )
519519
{
520-
QgsDebugMsg( "users qgis.db not found" );
520+
QgsDebugMsg( "user qgis.db not found" );
521521
return myMap;
522522
}
523523

0 commit comments

Comments
 (0)