------------------------------------------------------------------------------
| 231 | |
| 232 | //------------------------------------------------------------------------------ |
| 233 | vtkStdString vtkSQLDatabase::GetIndexSpecification( |
| 234 | vtkSQLDatabaseSchema* schema, int tblHandle, int idxHandle, bool& skipped) |
| 235 | { |
| 236 | vtkStdString queryStr; |
| 237 | |
| 238 | int idxType = schema->GetIndexTypeFromHandle(tblHandle, idxHandle); |
| 239 | switch (idxType) |
| 240 | { |
| 241 | case vtkSQLDatabaseSchema::PRIMARY_KEY: |
| 242 | queryStr = ", PRIMARY KEY "; |
| 243 | skipped = false; |
| 244 | break; |
| 245 | case vtkSQLDatabaseSchema::UNIQUE: |
| 246 | queryStr = ", UNIQUE "; |
| 247 | skipped = false; |
| 248 | break; |
| 249 | case vtkSQLDatabaseSchema::INDEX: |
| 250 | // Not supported within a CREATE TABLE statement by all SQL backends: |
| 251 | // must be created later with a CREATE INDEX statement |
| 252 | queryStr = "CREATE INDEX "; |
| 253 | skipped = true; |
| 254 | break; |
| 255 | default: |
| 256 | return {}; |
| 257 | } |
| 258 | |
| 259 | // No index_name for PRIMARY KEYs nor UNIQUEs |
| 260 | if (skipped) |
| 261 | { |
| 262 | queryStr += schema->GetIndexNameFromHandle(tblHandle, idxHandle); |
| 263 | } |
| 264 | |
| 265 | // CREATE INDEX <index name> ON <table name> syntax |
| 266 | if (skipped) |
| 267 | { |
| 268 | queryStr += " ON "; |
| 269 | queryStr += schema->GetTableNameFromHandle(tblHandle); |
| 270 | } |
| 271 | |
| 272 | queryStr += " ("; |
| 273 | |
| 274 | // Loop over all column names of the index |
| 275 | int numCnm = schema->GetNumberOfColumnNamesInIndex(tblHandle, idxHandle); |
| 276 | if (numCnm < 0) |
| 277 | { |
| 278 | vtkGenericWarningMacro( |
| 279 | "Unable to get index specification: index has incorrect number of columns " << numCnm); |
| 280 | return {}; |
| 281 | } |
| 282 | |
| 283 | bool firstCnm = true; |
| 284 | for (int cnmHandle = 0; cnmHandle < numCnm; ++cnmHandle) |
| 285 | { |
| 286 | if (firstCnm) |
| 287 | { |
| 288 | firstCnm = false; |
| 289 | } |
| 290 | else |
no test coverage detected