@@ -275,45 +275,6 @@ int OGRSQLiteBaseDataSource::GetSpatialiteVersionNumber()
275
275
return v;
276
276
}
277
277
278
- /* ***********************************************************************/
279
- /* GetRelationshipNames() */
280
- /* ***********************************************************************/
281
-
282
- std::vector<std::string> OGRSQLiteDataSource::GetRelationshipNames (
283
- CPL_UNUSED CSLConstList papszOptions) const
284
-
285
- {
286
- if (!m_bHasPopulatedRelationships)
287
- LoadRelationshipsFromForeignKeys ();
288
-
289
- std::vector<std::string> oasNames;
290
- oasNames.reserve (m_osMapRelationships.size ());
291
- for (auto it = m_osMapRelationships.begin ();
292
- it != m_osMapRelationships.end (); ++it)
293
- {
294
- oasNames.emplace_back (it->first );
295
- }
296
- return oasNames;
297
- }
298
-
299
- /* ***********************************************************************/
300
- /* GetRelationship() */
301
- /* ***********************************************************************/
302
-
303
- const GDALRelationship *
304
- OGRSQLiteDataSource::GetRelationship (const std::string &name) const
305
-
306
- {
307
- if (!m_bHasPopulatedRelationships)
308
- LoadRelationshipsFromForeignKeys ();
309
-
310
- auto it = m_osMapRelationships.find (name);
311
- if (it == m_osMapRelationships.end ())
312
- return nullptr ;
313
-
314
- return it->second .get ();
315
- }
316
-
317
278
/* ***********************************************************************/
318
279
/* AddRelationship() */
319
280
/* ***********************************************************************/
@@ -704,18 +665,28 @@ OGRErr OGRSQLiteBaseDataSource::PragmaCheck(const char *pszPragma,
704
665
}
705
666
706
667
/* ***********************************************************************/
707
- /* LoadRelationshipsFromForeignKeys() */
668
+ /* LoadRelationships() */
708
669
/* ***********************************************************************/
709
670
710
- void OGRSQLiteBaseDataSource::LoadRelationshipsFromForeignKeys () const
671
+ void OGRSQLiteBaseDataSource::LoadRelationships () const
711
672
712
673
{
713
674
m_osMapRelationships.clear ();
675
+ LoadRelationshipsFromForeignKeys ({});
676
+ m_bHasPopulatedRelationships = true ;
677
+ }
714
678
679
+ /* ***********************************************************************/
680
+ /* LoadRelationshipsFromForeignKeys() */
681
+ /* ***********************************************************************/
682
+
683
+ void OGRSQLiteBaseDataSource::LoadRelationshipsFromForeignKeys (
684
+ const std::vector<std::string> &excludedTables) const
685
+
686
+ {
715
687
if (hDB)
716
688
{
717
- auto oResult = SQLQuery (
718
- hDB,
689
+ std::string osSQL =
719
690
" SELECT m.name, p.id, p.seq, p.\" table\" AS base_table_name, "
720
691
" p.\" from\" , p.\" to\" , "
721
692
" p.on_delete FROM sqlite_master m "
@@ -728,8 +699,27 @@ void OGRSQLiteBaseDataSource::LoadRelationshipsFromForeignKeys() const
728
699
// Same with Spatialite system tables
729
700
" AND base_table_name NOT IN ('geometry_columns', "
730
701
" 'spatial_ref_sys', 'views_geometry_columns', "
731
- " 'virts_geometry_columns') "
732
- " ORDER BY m.name" );
702
+ " 'virts_geometry_columns') " ;
703
+ if (!excludedTables.empty ())
704
+ {
705
+ std::string oExcludedTablesList;
706
+ for (const auto &osExcludedTable : excludedTables)
707
+ {
708
+ oExcludedTablesList += !oExcludedTablesList.empty () ? " ," : " " ;
709
+ char *pszEscapedName =
710
+ sqlite3_mprintf (" '%q'" , osExcludedTable.c_str ());
711
+ oExcludedTablesList += pszEscapedName;
712
+ sqlite3_free (pszEscapedName);
713
+ }
714
+
715
+ osSQL += " AND base_table_name NOT IN (" + oExcludedTablesList +
716
+ " )"
717
+ " AND m.name NOT IN (" +
718
+ oExcludedTablesList + " ) " ;
719
+ }
720
+ osSQL += " ORDER BY m.name" ;
721
+
722
+ auto oResult = SQLQuery (hDB, osSQL.c_str ());
733
723
734
724
if (!oResult)
735
725
{
@@ -806,9 +796,50 @@ void OGRSQLiteBaseDataSource::LoadRelationshipsFromForeignKeys() const
806
796
std::move (poRelationship);
807
797
}
808
798
}
799
+ }
800
+ }
801
+
802
+ /* ***********************************************************************/
803
+ /* GetRelationshipNames() */
804
+ /* ***********************************************************************/
805
+
806
+ std::vector<std::string> OGRSQLiteBaseDataSource::GetRelationshipNames (
807
+ CPL_UNUSED CSLConstList papszOptions) const
808
+
809
+ {
810
+ if (!m_bHasPopulatedRelationships)
811
+ {
812
+ LoadRelationships ();
813
+ }
814
+
815
+ std::vector<std::string> oasNames;
816
+ oasNames.reserve (m_osMapRelationships.size ());
817
+ for (auto it = m_osMapRelationships.begin ();
818
+ it != m_osMapRelationships.end (); ++it)
819
+ {
820
+ oasNames.emplace_back (it->first );
821
+ }
822
+ return oasNames;
823
+ }
824
+
825
+ /* ***********************************************************************/
826
+ /* GetRelationship() */
827
+ /* ***********************************************************************/
809
828
810
- m_bHasPopulatedRelationships = true ;
829
+ const GDALRelationship *
830
+ OGRSQLiteBaseDataSource::GetRelationship (const std::string &name) const
831
+
832
+ {
833
+ if (!m_bHasPopulatedRelationships)
834
+ {
835
+ LoadRelationships ();
811
836
}
837
+
838
+ auto it = m_osMapRelationships.find (name);
839
+ if (it == m_osMapRelationships.end ())
840
+ return nullptr ;
841
+
842
+ return it->second .get ();
812
843
}
813
844
814
845
/* **********************************************************************/
0 commit comments