#include #include /* Include directly the different headers from cppconn/ and mysql_driver.h + mysql_util.h (and mysql_connection.h). This will reduce your build time! */ #include #include #include #include #include using namespace std; int main(void) { cout << endl; try { sql::Driver *driver; sql::Connection *con; sql::Statement *stmt; sql::ResultSet *res; char *locale= NULL; #ifdef _WIN32 locale = setlocale(LC_NUMERIC, "French_Canada"); #else locale = setlocale(LC_NUMERIC, "fr_CA.UTF8"); #endif if(!locale) { cout << endl << "ERROR! Could not set the locale!" << endl; return EXIT_FAILURE; } /* Create a connection */ driver = get_driver_instance(); cout << "Connecting......................."; con = driver->connect("tcp://127.0.0.1:3306", "**********", "********"); /* Connect to the MySQL test database */ con->setSchema("test"); cout << "[DONE]" << endl; stmt = con->createStatement(); cout << "Dropping/creating the table......"; stmt->executeUpdate("DROP TABLE IF EXISTS bug69719"); stmt->executeUpdate("CREATE TABLE bug69719 (id int primary key, doublecol double)"); cout << "[DONE]" << endl; cout << "Inserting VALUES (1, 5.4321)....."; stmt->executeUpdate("INSERT INTO bug69719 (id, doublecol) VALUES (1, 5.4321)"); cout << "[DONE]" << endl; cout << "SELECT the result................"; res = stmt->executeQuery("SELECT * FROM bug69719"); cout << "[DONE]" << endl; while (res->next()) { double doublecol = res->getDouble(2); cout << "\t... double column value: " << doublecol << endl; if(doublecol != 5.4321) cout << "ERROR!!! Wrong result!!! " << endl; } delete res; delete stmt; delete con; } catch (sql::SQLException &e) { cout << "# ERR: SQLException in " << __FILE__; cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl; cout << "# ERR: " << e.what(); cout << " (MySQL error code: " << e.getErrorCode(); cout << ", SQLState: " << e.getSQLState() << " )" << endl; } cout << endl; return EXIT_SUCCESS; }