~mysql/mysql-connector-cpp/trunk

« back to all changes in this revision

Viewing changes to examples/connect.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
36
36
#include <sstream>
37
37
#include <stdexcept>
38
38
 
 
39
#include <boost/scoped_ptr.hpp>
 
40
 
39
41
/*
40
42
  Public interface of the MySQL Connector/C++.
41
43
  You might not use it but directly include directly the different
72
74
        try {
73
75
                sql::Driver * driver = sql::mysql::get_driver_instance();
74
76
                /* Using the Driver to create a connection */
75
 
                std::auto_ptr< sql::Connection > con(driver->connect(url, user, pass));
 
77
                boost::scoped_ptr< sql::Connection > con(driver->connect(url, user, pass));
76
78
 
77
79
                /* Creating a "simple" statement - "simple" = not a prepared statement */
78
 
                std::auto_ptr< sql::Statement > stmt(con->createStatement());
 
80
                boost::scoped_ptr< sql::Statement > stmt(con->createStatement());
79
81
 
80
82
                /* Create a test table demonstrating the use of sql::Statement.execute() */
81
83
                stmt->execute("USE " + database);
101
103
                        Run a query which returns exactly one result set like SELECT
102
104
                        Stored procedures (CALL) may return more than one result set
103
105
                        */
104
 
                        std::auto_ptr< sql::ResultSet > res(stmt->executeQuery("SELECT id, label FROM test ORDER BY id ASC"));
 
106
                        boost::scoped_ptr< sql::ResultSet > res(stmt->executeQuery("SELECT id, label FROM test ORDER BY id ASC"));
105
107
                        cout << "#\t Running 'SELECT id, label FROM test ORDER BY id ASC'" << endl;
106
108
 
107
109
                        /* Number of rows in the result set */
127
129
 
128
130
                {
129
131
                        /* Fetching again but using type convertion methods */
130
 
                        std::auto_ptr< sql::ResultSet > res(stmt->executeQuery("SELECT id FROM test ORDER BY id DESC"));
 
132
                        boost::scoped_ptr< sql::ResultSet > res(stmt->executeQuery("SELECT id FROM test ORDER BY id DESC"));
131
133
                        cout << "#\t Fetching 'SELECT id FROM test ORDER BY id DESC' using type conversion" << endl;
132
134
                        row = 0;
133
135
                        while (res->next()) {
150
152
                }
151
153
 
152
154
                {
153
 
                        std::auto_ptr< sql::ResultSet > res(stmt->executeQuery("SELECT id, label FROM test WHERE id = 100"));
 
155
                        boost::scoped_ptr< sql::ResultSet > res(stmt->executeQuery("SELECT id, label FROM test WHERE id = 100"));
154
156
 
155
157
                        res->next();
156
158
                        if ((res->getInt("id") != 100) || (res->getString("label") != "y")) {