------------------------------------------------------------------------------
| 85 | |
| 86 | //------------------------------------------------------------------------------ |
| 87 | bool vtkSQLiteQuery::SetQuery(const char* newQuery) |
| 88 | { |
| 89 | vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting Query to " |
| 90 | << (newQuery ? newQuery : "(null)")); |
| 91 | |
| 92 | if (this->Query == nullptr && newQuery == nullptr) |
| 93 | { |
| 94 | return true; |
| 95 | } |
| 96 | |
| 97 | if (this->Query && newQuery && (!strcmp(this->Query, newQuery))) |
| 98 | { |
| 99 | return true; // we've already got that query |
| 100 | } |
| 101 | |
| 102 | delete[] this->Query; |
| 103 | |
| 104 | if (newQuery) |
| 105 | { |
| 106 | // Keep a local copy of the query - this is from vtkSetGet.h |
| 107 | size_t n = strlen(newQuery) + 1; |
| 108 | char* cp1 = new char[n]; |
| 109 | const char* cp2 = (newQuery); |
| 110 | this->Query = cp1; |
| 111 | do |
| 112 | { |
| 113 | *cp1++ = *cp2++; |
| 114 | } while (--n); |
| 115 | } |
| 116 | else |
| 117 | { |
| 118 | this->Query = nullptr; |
| 119 | } |
| 120 | |
| 121 | // If we get to this point the query has changed. We need to |
| 122 | // finalize the already-prepared statement if one exists and then |
| 123 | // prepare a new statement. |
| 124 | if (this->Private->Statement) |
| 125 | { |
| 126 | vtkDebugMacro(<< "Finalizing old statement"); |
| 127 | int finalizeStatus = sqlite3_finalize(this->Private->Statement); |
| 128 | if (finalizeStatus != SQLITE_OK) |
| 129 | { |
| 130 | vtkWarningMacro(<< "SetQuery(): Finalize returned unexpected code " << finalizeStatus); |
| 131 | } |
| 132 | this->Private->Statement = nullptr; |
| 133 | } |
| 134 | |
| 135 | if (this->Query) |
| 136 | { |
| 137 | vtkSQLiteDatabase* dbContainer = vtkSQLiteDatabase::SafeDownCast(this->Database); |
| 138 | |
| 139 | if (dbContainer == nullptr) |
| 140 | { |
| 141 | vtkErrorMacro(<< "This should never happen: SetQuery() called when there is no underlying " |
| 142 | "database. You probably instantiated vtkSQLiteQuery directly instead of " |
| 143 | "calling vtkSQLDatabase::GetInstance(). This also happens during " |
| 144 | "TestSetGet in the CDash testing."); |
nothing calls this directly
no test coverage detected