MCPcopy Create free account
hub / github.com/Kitware/VTK / GetIndexSpecification

Method GetIndexSpecification

IO/MySQL/vtkMySQLDatabase.cxx:501–560  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

499
500//------------------------------------------------------------------------------
501vtkStdString vtkMySQLDatabase::GetIndexSpecification(
502 vtkSQLDatabaseSchema* schema, int tblHandle, int idxHandle, bool& skipped)
503{
504 skipped = false;
505 vtkStdString queryStr = ", ";
506 bool mustUseName = true;
507
508 int idxType = schema->GetIndexTypeFromHandle(tblHandle, idxHandle);
509 switch (idxType)
510 {
511 case vtkSQLDatabaseSchema::PRIMARY_KEY:
512 queryStr += "PRIMARY KEY ";
513 mustUseName = false;
514 break;
515 case vtkSQLDatabaseSchema::UNIQUE:
516 queryStr += "UNIQUE ";
517 break;
518 case vtkSQLDatabaseSchema::INDEX:
519 queryStr += "INDEX ";
520 break;
521 default:
522 return vtkStdString();
523 }
524
525 // No index_name for PRIMARY KEYs
526 if (mustUseName)
527 {
528 queryStr += schema->GetIndexNameFromHandle(tblHandle, idxHandle);
529 }
530 queryStr += " (";
531
532 // Loop over all column names of the index
533 int numCnm = schema->GetNumberOfColumnNamesInIndex(tblHandle, idxHandle);
534 if (numCnm < 0)
535 {
536 vtkGenericWarningMacro(
537 "Unable to get index specification: index has incorrect number of columns " << numCnm);
538 return {};
539 }
540
541 bool firstCnm = true;
542 for (int cnmHandle = 0; cnmHandle < numCnm; ++cnmHandle)
543 {
544 if (firstCnm)
545 {
546 firstCnm = false;
547 }
548 else
549 {
550 queryStr += ",";
551 }
552 // With MySQL, the column name must be enclosed between backquotes
553 queryStr += "`";
554 queryStr += schema->GetIndexColumnNameFromHandle(tblHandle, idxHandle, cnmHandle);
555 queryStr += "` ";
556 }
557 queryStr += ")";
558

Callers

nothing calls this directly

Calls 5

vtkStdStringClass · 0.50

Tested by

no test coverage detected