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

Function TestMySQLDatabase

IO/MySQL/Testing/Cxx/TestMySQLDatabase.cxx:37–546  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35#include <iostream>
36
37int TestMySQLDatabase(int, char** const)
38{
39 vtkMySQLDatabase* db =
40 vtkMySQLDatabase::SafeDownCast(vtkSQLDatabase::CreateFromURL(VTK_MYSQL_TEST_URL));
41
42 // Temp code to for linkage ...
43 vtkMySQLDatabase* tmp = vtkMySQLDatabase::New();
44
45 bool status = db->Open("vtktest");
46
47 if (!status)
48 {
49 std::cerr << "Couldn't open database.\n";
50 return 1;
51 }
52
53 vtkSQLQuery* query = db->GetQueryInstance();
54 std::string createQuery(
55 "CREATE TABLE IF NOT EXISTS people (name TEXT, age INTEGER, weight FLOAT)");
56 std::cout << createQuery << std::endl;
57 query->SetQuery(createQuery.c_str());
58 if (!query->Execute())
59 {
60 std::cerr << "Create query failed" << std::endl;
61 return 1;
62 }
63
64 for (int i = 0; i < 40; ++i)
65 {
66 auto insertQuery =
67 vtk::format("INSERT INTO people VALUES('John Doe {:d}', {:d}, {:d})", i, i, 10 * i);
68 std::cout << insertQuery << std::endl;
69 query->SetQuery(insertQuery);
70 if (!query->Execute())
71 {
72 std::cerr << "Insert query " << i << " failed" << std::endl;
73 return 1;
74 }
75 }
76
77 const char* queryText = "SELECT name, age, weight FROM people WHERE age <= 20";
78 query->SetQuery(queryText);
79 std::cerr << std::endl << "Running query: " << query->GetQuery() << std::endl;
80
81 std::cerr << std::endl << "Using vtkSQLQuery directly to execute query:" << std::endl;
82 if (!query->Execute())
83 {
84 std::cerr << "Query failed" << std::endl;
85 return 1;
86 }
87
88 for (int col = 0; col < query->GetNumberOfFields(); ++col)
89 {
90 if (col > 0)
91 {
92 std::cerr << ", ";
93 }
94 std::cerr << query->GetFieldName(col);

Callers

nothing calls this directly

Calls 15

GetDateFunction · 0.85
GetTimeFunction · 0.85
EffectSchemaMethod · 0.80
DeleteMethod · 0.65
NewFunction · 0.50
formatFunction · 0.50

Tested by

no test coverage detected