~mysql/mysql-connector-cpp/trunk

« back to all changes in this revision

Viewing changes to examples/connection_meta_schemaobj.cpp

  • Committer: Hemant Dangi
  • Date: 2014-12-17 16:28:39 UTC
  • Revision ID: hemant.dangi@oracle.com-20141217162839-sdbpj3fcwn5gxjxh
Bug #75251: Add C++11 support and replace (deprecated in C++11) auto_ptr

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
 
2
Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
3
3
 
4
4
The MySQL Connector/C++ is licensed under the terms of the GPLv2
5
5
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
38
38
#include <stdexcept>
39
39
#include <list>
40
40
 
 
41
#include <boost/scoped_ptr.hpp>
 
42
 
41
43
/* Public interface of the MySQL Connector/C++ */
42
44
#include <driver/mysql_public_iface.h>
43
45
/* Connection parameter and sample data */
75
77
                cout << driver->getMajorVersion() << "." << driver->getMinorVersion();
76
78
                cout << "." << driver->getPatchVersion() << endl;
77
79
 
78
 
                std::auto_ptr< sql::Connection > con(driver->connect(url, user, pass));
 
80
                boost::scoped_ptr< sql::Connection > con(driver->connect(url, user, pass));
79
81
                sql::DatabaseMetaData * con_meta = con->getMetaData();
80
82
 
81
83
                cout << "# CDBC (API) major version = " << con_meta->getCDBCMajorVersion() << endl;
90
92
                        NOTE Connector C++ defines catalog = n/a, schema = MySQL database
91
93
                        */
92
94
                        cout << "# List of available schemata/databases: ";
93
 
                        std::auto_ptr< sql::ResultSet > res(con_meta->getSchemas());
 
95
                        boost::scoped_ptr< sql::ResultSet > res(con_meta->getSchemas());
94
96
 
95
97
                        /* just for fun... of course you can scroll and fetch in whatever order you want */
96
98
                        res->afterLast();
108
110
                {
109
111
                        /* What object types does getSchemaObjects support? */
110
112
                        cout << "# Supported Object types: ";
111
 
                        std::auto_ptr< sql::ResultSet > res(con_meta->getSchemaObjectTypes());
 
113
                        boost::scoped_ptr< sql::ResultSet > res(con_meta->getSchemaObjectTypes());
112
114
                        while (res->next()) {
113
115
                                cout << res->getString(1);
114
116
                                if (!res->isLast()) {
121
123
                }
122
124
 
123
125
 
124
 
                std::auto_ptr< sql::Statement > stmt(con->createStatement());
 
126
                boost::scoped_ptr< sql::Statement > stmt(con->createStatement());
125
127
                stmt->execute("USE " + database);
126
128
                stmt->execute("DROP TABLE IF EXISTS test1");
127
129
                stmt->execute("CREATE TABLE test1(id INT, label CHAR(1))");
129
131
                stmt->execute("CREATE TABLE test2(id INT, label CHAR(1))");
130
132
 
131
133
                /* "" = empty string requests all types of objects */
132
 
                std::auto_ptr< sql::ResultSet > res(con_meta->getSchemaObjects(con->getCatalog(), con->getSchema(), ""));
 
134
                boost::scoped_ptr< sql::ResultSet > res(con_meta->getSchemaObjects(con->getCatalog(), con->getSchema(), ""));
133
135
                row = 1;
134
136
                sql::ResultSetMetaData * res_meta = res->getMetaData();
135
137
                while (res->next()) {
217
219
                cout << "#\t\t isSigned() = " << res_meta->isSigned(5) << endl;
218
220
                cout << "#\t\t isWritable() = " << res_meta->isWritable(5) << endl;
219
221
 
220
 
                std::auto_ptr< sql::ResultSet > res_tables(con_meta->getTables(con->getCatalog(), database, "t%", table_types));
 
222
                boost::scoped_ptr< sql::ResultSet > res_tables(con_meta->getTables(con->getCatalog(), database, "t%", table_types));
221
223
                sql::ResultSetMetaData * res_meta_tables = res_tables->getMetaData();
222
224
 
223
225
                cout << "#" << endl;
235
237
                cout << "#" << endl;
236
238
 
237
239
                res_tables->first();
238
 
                std::auto_ptr< sql::ResultSet > res_columns(con_meta->getColumns(con->getCatalog(), database, "test1", "%"));
 
240
                boost::scoped_ptr< sql::ResultSet > res_columns(con_meta->getColumns(con->getCatalog(), database, "test1", "%"));
239
241
 
240
242
                cout << "#" << "Columns in the table 'test1'..." << endl;
241
243
                cout << "#\t rowsCount() = " << res_columns->rowsCount() << endl;