2
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; version 2 of the
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
#include "tut_stdafx.h"
22
#include "connection_helpers.h"
24
#define VERBOSE_TESTING 0
28
BEGIN_TEST_DATA_CLASS(module_dbc_general_test)
33
TEST_MODULE(module_dbc_general_test, "DBC: general tests");
38
grt.scan_metaclasses_in("../../res/grt/");
39
grt.end_loading_metaclasses();
41
ensure_equals("load structs", grt.get_metaclasses().size(), INT_METACLASS_COUNT);
46
db_mgmt_ConnectionRef connectionProperties(&grt);
48
setup_env(&grt, connectionProperties);
50
sql::DriverManager *dm= sql::DriverManager::getDriverManager();
51
sql::ConnectionWrapper wrapper= dm->getConnection(connectionProperties);
52
sql::Connection* connection= wrapper.get();
53
sql::DatabaseMetaData *meta(connection->getMetaData());
54
std::auto_ptr<sql::ResultSet> rset(meta->getSchemata());
59
std::cout << rset->getString("schema_name") << std::endl;
60
std::cout << " Schema Objects:" << std::endl;
64
std::auto_ptr<sql::ResultSet> rset2(meta->getSchemaObjects("", rset->getString("database")));
68
std::cout << rset2->getString("object_type") << ": " << rset2->getString("name") << "," <<
69
rset2->getString("ddl") << std::endl;
77
db_mgmt_ConnectionRef connectionProperties(&grt);
79
setup_env(&grt, connectionProperties);
81
sql::DriverManager *dm= sql::DriverManager::getDriverManager();
82
sql::ConnectionWrapper wrapper= dm->getConnection(connectionProperties);
83
sql::Connection* connection= wrapper.get();
85
std::auto_ptr<sql::Statement> stmt(connection->createStatement());
87
stmt->execute("DROP TABLE IF EXISTS test.product");
88
stmt->execute("CREATE TABLE test.product(idproduct INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(80))");
90
connection->setAutoCommit(0);
93
std::cout << "Insert Data." << std:endl;
96
std::auto_ptr<sql::PreparedStatement> prepStmt(connection->prepareStatement("INSERT INTO test.product(idproduct, name) VALUES(?, ?)"));
97
prepStmt->setInt(1, 1);
98
prepStmt->setString(2, "Harry Potter");
99
prepStmt->executeUpdate();
102
std::cout << "Display Data." << std::endl;
105
std::auto_ptr<sql::ResultSet> rset1(stmt->executeQuery("SELECT * FROM test.product"));
108
while (rset1->next())
111
std::cout << rset1->getString(2) << ", " << rset1->getString("name") << std::endl;
116
printf("%d row(s)", i);
121
connection->rollback();
124
printf("Display Data Again.\n");
126
std::auto_ptr<sql::ResultSet> rset2(stmt->executeQuery("SELECT * FROM test.product"));
129
while (rset2->next())
132
std::cout << rset2->getString(2) << ", " << rset2->getString("name") << std::endl;
137
std::cout << i << " row(s)" << std::endl;