| 162 | }; |
| 163 | |
| 164 | class GDALVectorSQLAlgorithmDatasetMultiLayer final : public GDALDataset |
| 165 | { |
| 166 | // We can't safely have 2 SQL layers active simultaneously on the same |
| 167 | // source dataset. So each time we access one, we must close the last |
| 168 | // active one. |
| 169 | OGRLayerPool m_oPool{1}; |
| 170 | GDALDataset &m_oSrcDS; |
| 171 | std::vector<std::unique_ptr<ProxiedSQLLayer>> m_layers{}; |
| 172 | |
| 173 | struct UserData |
| 174 | { |
| 175 | GDALDataset &oSrcDS; |
| 176 | std::string osSQL{}; |
| 177 | std::string osDialect{}; |
| 178 | std::string osLayerName{}; |
| 179 | |
| 180 | UserData(GDALDataset &oSrcDSIn, const std::string &osSQLIn, |
| 181 | const std::string &osDialectIn, |
| 182 | const std::string &osLayerNameIn) |
| 183 | : oSrcDS(oSrcDSIn), osSQL(osSQLIn), osDialect(osDialectIn), |
| 184 | osLayerName(osLayerNameIn) |
| 185 | { |
| 186 | } |
| 187 | CPL_DISALLOW_COPY_ASSIGN(UserData) |
| 188 | }; |
| 189 | |
| 190 | CPL_DISALLOW_COPY_ASSIGN(GDALVectorSQLAlgorithmDatasetMultiLayer) |
| 191 | |
| 192 | public: |
| 193 | explicit GDALVectorSQLAlgorithmDatasetMultiLayer(GDALDataset &oSrcDS) |
| 194 | : m_oSrcDS(oSrcDS) |
| 195 | { |
| 196 | m_oSrcDS.Reference(); |
| 197 | } |
| 198 | |
| 199 | ~GDALVectorSQLAlgorithmDatasetMultiLayer() override |
| 200 | { |
| 201 | m_layers.clear(); |
| 202 | m_oSrcDS.ReleaseRef(); |
| 203 | } |
| 204 | |
| 205 | void AddLayer(const std::string &osSQL, const std::string &osDialect, |
| 206 | const std::string &osLayerName) |
| 207 | { |
| 208 | const auto OpenLayer = [](void *pUserDataIn) |
| 209 | { |
| 210 | UserData *pUserData = static_cast<UserData *>(pUserDataIn); |
| 211 | return pUserData->oSrcDS.ExecuteSQL( |
| 212 | pUserData->osSQL.c_str(), nullptr, |
| 213 | pUserData->osDialect.empty() ? nullptr |
| 214 | : pUserData->osDialect.c_str()); |
| 215 | }; |
| 216 | |
| 217 | const auto CloseLayer = [](OGRLayer *poLayer, void *pUserDataIn) |
| 218 | { |
| 219 | UserData *pUserData = static_cast<UserData *>(pUserDataIn); |
| 220 | pUserData->oSrcDS.ReleaseResultSet(poLayer); |
| 221 | }; |
nothing calls this directly
no test coverage detected