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

Function TestSQLiteDatabase

IO/SQL/Testing/Cxx/TestSQLiteDatabase.cxx:23–399  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21#include <iostream>
22
23int TestSQLiteDatabase(int /*argc*/, char* /*argv*/[])
24{
25 bool status;
26
27 std::cerr << ">>>>> Testing bad input." << std::endl;
28
29 vtkSQLDatabase* db0 = vtkSQLDatabase::CreateFromURL(nullptr);
30 if (db0)
31 {
32 std::cerr << "ERROR: Created a database from a nullptr URL! How?" << std::endl;
33 db0->Delete();
34 return 1;
35 }
36
37 std::cerr << ">>>>> Testing creation modes." << std::endl;
38
39 vtkSmartPointer<vtkTest::ErrorObserver> errorObserver =
40 vtkSmartPointer<vtkTest::ErrorObserver>::New();
41 vtkSmartPointer<vtkTest::ErrorObserver> queryObserver =
42 vtkSmartPointer<vtkTest::ErrorObserver>::New();
43
44 vtkSQLiteDatabase* db1 =
45 vtkSQLiteDatabase::SafeDownCast(vtkSQLDatabase::CreateFromURL("sqlite://local.db"));
46
47 status = db1->Open("", vtkSQLiteDatabase::CREATE_OR_CLEAR);
48 vtkSQLQuery* query1 = db1->GetQueryInstance();
49 query1->SetQuery("CREATE TABLE test (id INTEGER)");
50 if (!query1->Execute())
51 {
52 std::cerr << "Create query failed" << std::endl;
53 return 1;
54 }
55 if (!status)
56 {
57 std::cerr << "Couldn't open database using CREATE_OR_CLEAR.\n";
58 return 1;
59 }
60 db1->Delete();
61 query1->Delete();
62
63 vtkSQLiteDatabase* db2 =
64 vtkSQLiteDatabase::SafeDownCast(vtkSQLDatabase::CreateFromURL("sqlite://local.db"));
65 db2->AddObserver(vtkCommand::ErrorEvent, errorObserver);
66 status = db2->Open("", vtkSQLiteDatabase::CREATE);
67 if (status)
68 {
69 std::cerr << "Using CREATE on an existing file should have failed but did not.\n";
70 return 1;
71 }
72 int status1 =
73 errorObserver->CheckErrorMessage("You specified creating a database but the file exists");
74 if (status1 != 0)
75 {
76 std::cerr << "Expected error message not found.\n";
77 return 1;
78 }
79 db2->Delete();
80

Callers

nothing calls this directly

Calls 15

EffectSchemaMethod · 0.80
DeleteMethod · 0.65
NewFunction · 0.50
formatFunction · 0.50
vtkStdStringClass · 0.50
OpenMethod · 0.45
GetQueryInstanceMethod · 0.45
SetQueryMethod · 0.45
ExecuteMethod · 0.45
AddObserverMethod · 0.45

Tested by

no test coverage detected