@@ -9986,6 +9986,35 @@ bool GDALGeoPackageDataset::AddRelationship(
9986
9986
return false ;
9987
9987
}
9988
9988
9989
+ /*
9990
+ * Strictly speaking we should NOT be inserting the mapping table into gpkg_contents.
9991
+ * The related tables extension explicitly states that the mapping table should only be
9992
+ * in the gpkgext_relations table and not in gpkg_contents. (See also discussion at
9993
+ * https://github.com/opengeospatial/geopackage/issues/679).
9994
+ *
9995
+ * However, if we don't insert the mapping table into gpkg_contents then it is no longer
9996
+ * visible to some clients (eg ESRI software only allows opening tables that are present
9997
+ * in gpkg_contents). So we'll do this anyway, for maximum compatiblity and flexibility.
9998
+ *
9999
+ * More related discussion is at https://github.com/OSGeo/gdal/pull/9258
10000
+ */
10001
+ pszSQL = sqlite3_mprintf (
10002
+ " INSERT INTO gpkg_contents "
10003
+ " (table_name,data_type,identifier,description,last_change,srs_id) "
10004
+ " VALUES "
10005
+ " ('%q','attributes','%q','Mapping table for relationship between "
10006
+ " %q and %q',%s,0)" ,
10007
+ osMappingTableName.c_str (), /* table_name*/
10008
+ osMappingTableName.c_str (), /* identifier*/
10009
+ osLeftTableName.c_str (), /* description left table name*/
10010
+ osRightTableName.c_str (), /* description right table name*/
10011
+ GDALGeoPackageDataset::GetCurrentDateEscapedSQL ().c_str ());
10012
+
10013
+ // Note -- we explicitly ignore failures here, because hey, we aren't really
10014
+ // supposed to be adding this table to gpkg_contents anyway!
10015
+ (void )SQLCommand (hDB, pszSQL);
10016
+ sqlite3_free (pszSQL);
10017
+
9989
10018
pszSQL = sqlite3_mprintf (
9990
10019
" CREATE INDEX \" idx_%w_base_id\" ON \" %w\" (base_id);" ,
9991
10020
osMappingTableName.c_str (), osMappingTableName.c_str ());
0 commit comments