Author: tbedford
Date: 2009-09-03 18:58:07 +0200 (Thu, 03 Sep 2009)
New Revision: 16423
Log:
Framework to support Connector/C++ tutorials
Added:
trunk/sample-programs/connector-cpp-tutorials/connector-cpp-frmwk.cpp
Added: trunk/sample-programs/connector-cpp-tutorials/connector-cpp-frmwk.cpp
===================================================================
--- trunk/sample-programs/connector-cpp-tutorials/connector-cpp-frmwk.cpp (rev 0)
+++ trunk/sample-programs/connector-cpp-tutorials/connector-cpp-frmwk.cpp 2009-09-03 16:58:07 UTC (rev 16423)
Changed blocks: 1, Lines Added: 52, Lines Deleted: 0; 1847 bytes
@@ -0,0 +1,52 @@
+#include <stdlib.h>
+#include <iostream>
+#include <sstream>
+#include <stdexcept>
+
+#include "mysql_connection.h"
+
+#include <cppconn/driver.h>
+#include <cppconn/exception.h>
+#include <cppconn/resultset.h>
+#include <cppconn/statement.h>
+#include <cppconn/prepared_statement.h>
+
+#define EXAMPLE_HOST "localhost"
+#define EXAMPLE_USER "root"
+#define EXAMPLE_PASS ""
+#define EXAMPLE_DB "world"
+
+using namespace std;
+
+int main(int argc, const char **argv)
+{
+ cout << "Connector/C++ tutorial framework..." << endl;
+ cout << endl;
+
+ try {
+
+ /* INSERT TUTORIAL CODE HERE! */
+
+ } catch (sql::SQLException &e) {
+ /*
+ The MySQL Connector/C++ throws three different exceptions:
+
+ - sql::MethodNotImplementedException (derived from sql::SQLException)
+ - sql::InvalidArgumentException (derived from sql::SQLException)
+ - sql::SQLException (derived from std::runtime_error)
+ */
+ cout << "# ERR: SQLException in " << __FILE__;
+ cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
+ /* Use what() (derived from std::runtime_error) to fetch the error message */
+ cout << "# ERR: " << e.what();
+ cout << " (MySQL error code: " << e.getErrorCode();
+ cout << ", SQLState: " << e.getSQLState() << " )" << endl;
+
+ return EXIT_FAILURE;
+ }
+
+ cout << endl;
+ cout << "... find more at http://www.mysql.com" << endl;
+ cout << endl;
+ return EXIT_SUCCESS;
+}
| Thread |
|---|
| • svn commit - mysqldoc@docsrva: r16423 - in trunk/sample-programs: . connector-cpp-tutorials | anthony.bedford | 3 Sep |