Add a WKT column to tbl_srs

proj string definitions of CRSes are lossy, so we need to gradually
transition to WKT definitions instead
This commit is contained in:
Nyall Dawson 2019-12-11 11:45:58 +10:00
parent 3d4b5fb09a
commit 4e4cd313bd
4 changed files with 44 additions and 2 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1886,6 +1886,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,"
@ -1896,7 +1897,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 )
@ -1907,6 +1909,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 )
@ -1936,6 +1975,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,"
@ -1947,7 +1988,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 )