Skip to content
Permalink
Browse files

Add a WKT column to tbl_srs

proj string definitions of CRSes are lossy, so we need to gradually
transition to WKT definitions instead

(cherry picked from commit 4e4cd31)
  • Loading branch information
nyalldawson committed Dec 11, 2019
1 parent 54df3bb commit 0657c9e4766b234ec0a622c0308c59e6e75abfb2
BIN +0 Bytes (100%) resources/qgis.db
Binary file not shown.
BIN +0 Bytes (100%) resources/srs.db
Binary file not shown.
BIN +0 Bytes (100%) resources/srs6.db
Binary file not shown.
@@ -1843,6 +1843,7 @@ bool QgsApplication::createDatabase( QString *errorMessage )

// qgis.db is missing tbl_srs, create it
if ( sqlite3_exec( database.get(),
"DROP INDEX IF EXISTS idx_srsauthid;"
"CREATE TABLE tbl_srs ("
"srs_id INTEGER PRIMARY KEY,"
"description text NOT NULL,"
@@ -1853,7 +1854,8 @@ bool QgsApplication::createDatabase( QString *errorMessage )
"auth_name varchar,"
"auth_id varchar,"
"is_geo integer NOT NULL,"
"deprecated boolean);"
"deprecated boolean,"
"wkt text);"
"CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);", nullptr, nullptr, &errmsg ) != SQLITE_OK )
{
if ( errorMessage )
@@ -1864,6 +1866,43 @@ bool QgsApplication::createDatabase( QString *errorMessage )
return false;
}
}
else
{
// test if wkt column exists in database
res = sqlite3_exec( database.get(), "SELECT wkt FROM tbl_srs LIMIT 0", nullptr, nullptr, &errmsg );
if ( res != SQLITE_OK )
{
// need to add wkt column
sqlite3_free( errmsg );
if ( sqlite3_exec( database.get(),
"DROP INDEX IF EXISTS idx_srsauthid;"
"DROP TABLE IF EXISTS tbl_srs_bak;"
"ALTER TABLE tbl_srs RENAME TO tbl_srs_bak;"
"CREATE TABLE tbl_srs ("
"srs_id INTEGER PRIMARY KEY,"
"description text NOT NULL,"
"projection_acronym text NOT NULL,"
"ellipsoid_acronym NOT NULL,"
"parameters text NOT NULL,"
"srid integer,"
"auth_name varchar,"
"auth_id varchar,"
"is_geo integer NOT NULL,"
"deprecated boolean,"
"wkt text);"
"CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);"
"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;"
"DROP TABLE tbl_srs_bak", nullptr, nullptr, &errmsg ) != SQLITE_OK )
{
if ( errorMessage )
{
*errorMessage = tr( "Migration of private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
}
sqlite3_free( errmsg );
return false;
}
}
}

res = sqlite3_exec( database.get(), "SELECT acronym FROM tbl_projection LIMIT 0", nullptr, nullptr, &errmsg );
if ( res != SQLITE_OK )
@@ -1893,6 +1932,8 @@ bool QgsApplication::createDatabase( QString *errorMessage )
{
// epsg column exists => need migration
if ( sqlite3_exec( database.get(),
"DROP INDEX IF EXISTS idx_srsauthid;"
"DROP TABLE IF EXISTS tbl_srs_bak;"
"ALTER TABLE tbl_srs RENAME TO tbl_srs_bak;"
"CREATE TABLE tbl_srs ("
"srs_id INTEGER PRIMARY KEY,"
@@ -1904,7 +1945,8 @@ bool QgsApplication::createDatabase( QString *errorMessage )
"auth_name varchar,"
"auth_id varchar,"
"is_geo integer NOT NULL,"
"deprecated boolean);"
"deprecated boolean,"
"wkt text);"
"CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);"
"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;"
"DROP TABLE tbl_srs_bak", nullptr, nullptr, &errmsg ) != SQLITE_OK )

0 comments on commit 0657c9e

Please sign in to comment.
You can’t perform that action at this time.