List:MySQL++« Previous MessageNext Message »
From:Adrian Cornish Date:August 9 2011 6:58pm
Subject:Re: Problem with exec()
View as plain text  
On Tue, Aug 9, 2011 at 10:39 AM, Joseph Hesse <joe_hesse@stripped> wrote:

> I am executing a MySQL query that has an error.
> The query does not return anything, it creates a temporary table.
> I know it has an error because I tried to execute it separately from a
> command prompt.
> I am using Fedora 14 Linux.
>
> I'm just showing pseudocode.
> I can create a small working example if that would help.
>
> /////////////////////
> query << "My Query";
>
> if(!query.exec())
> {
> // error code
> }
> /////////////////////
>
> My problem is that the error code never gets executed.
> When the query is correct the query always gets executed.
>
> Any help would be appreciated.
>
> Hi Joe

Always best to provide a full working example of your issue - this can be
done by modifying the sample applications.

Try modifying simple1.cpp to see if you can reproduce your error - below is
a patch of what I think you are trying to do - which works just fine

Index: simple1.cpp
===================================================================
--- simple1.cpp (revision 2692)
+++ simple1.cpp (working copy)
@@ -50,21 +50,17 @@
                        cmdline.user(), cmdline.pass())) {
                // Retrieve a subset of the sample stock table set up by
resetdb
                // and display it.
-               mysqlpp::Query query = conn.query("select item from stock");
-               if (mysqlpp::StoreQueryResult res = query.store()) {
-                       cout << "We have:" << endl;
-                       mysqlpp::StoreQueryResult::const_iterator it;
-                       for (it = res.begin(); it != res.end(); ++it) {
-                               mysqlpp::Row row = *it;
-                               cout << '\t' << row[0] << endl;
-                       }
-               }
-               else {
-                       cerr << "Failed to get item list: " << query.error()
<< endl;
-                       return 1;
-               }
-
-               return 0;
+               mysqlpp::Query query = conn.query();
+      query << "select a list of things from stock";
+      //query << "select * from stock";
+      if(!query.exec())
+      {
+         std::cout << "Failed\n";
+      }
+      else
+      {
+         std::cout << "Worked\n";
+      }
        }
        else {
                cerr << "DB connection failed: " << conn.error() <<
endl;

Thread
Problem with exec()Joseph Hesse9 Aug
  • Re: Problem with exec()Adrian Cornish9 Aug
  • Re: Problem with exec()Warren Young10 Aug