--- a/examples/standalone_example_docs2.cpp 2012-08-16 12:15:30.000000000 -0700
+++ b/examples/standalone_example_docs2.cpp 2012-08-23 10:05:54.000000000 -0700
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
-51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "mysql_connection.h"
+/* Public interface of the MySQL Connector/C++ */
+#include <driver/mysql_public_iface.h>
+/* Connection parameter and sample data */
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
+int main(int argc, const char **argv)
-cout << "Let's have MySQL count from 10 to 1..." << endl;
- sql::PreparedStatement *pstmt;
- /* Create a connection */
- driver = sql::mysql::get_driver_instance();
- con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
- /* Connect to the MySQL test database */
- con->setSchema("test");
- stmt = con->createStatement();
- stmt->execute("DROP TABLE IF EXISTS test");
- stmt->execute("CREATE TABLE test(id INT)");
- /* '?' is the supported placeholder syntax */
- pstmt = con->prepareStatement("INSERT INTO test(id) VALUES (?)");
- for (int i = 1; i <= 10; i++) {
- pstmt->executeUpdate();
- /* Select in ascending order */
- pstmt = con->prepareStatement("SELECT id FROM test ORDER BY id ASC");
- res = pstmt->executeQuery();
- /* Fetch in reverse = descending order! */
- while (res->previous())
- cout << "\t... MySQL counts: " << res->getInt("id") << endl;
-} catch (sql::SQLException &e) {
- cout << "# ERR: SQLException in " << __FILE__;
- cout << "(" << EXAMPLE_FUNCTION << ") on line " << __LINE__ << endl;
- cout << "# ERR: " << e.what();
- cout << " (MySQL error code: " << e.getErrorCode();
- cout << ", SQLState: " << e.getSQLState() << " )" << endl;
+ static const string url(argc >= 2 ? argv[1] : EXAMPLE_HOST);
+ static const string user(argc >= 3 ? argv[2] : EXAMPLE_USER);
+ static const string pass(argc >= 4 ? argv[3] : EXAMPLE_PASS);
+ static const string database(argc >= 5 ? argv[4] : EXAMPLE_DB);
+ cout << "Let's have MySQL count from 10 to 1..." << endl;