List:MySQL++« Previous MessageNext Message »
From:Michael Hanselmann Date:March 31 2007 9:11pm
Subject:Re: Conceptual issue in mysql++ 2.2.x (use(), store(), execute())
View as plain text  
Hello Warren

On Tue, Mar 27, 2007 at 10:01:03PM -0600, Warren Young wrote:
> I just changed examples/tquery.cpp to make it match the code you posted 
> as closely as possible, and I can't duplicate it.

Yes, it works. However, I use a somewhat different structure as you see
below.

> Your report looks just like what v2.1.1 will do, so I suspect you're
> mixing old and new libraries here. […], they will link to the old
> MySQL++ version you have installed elsewhere on your system, not to
> the one you just built.

No, they don't if I use LD_LIBRARY_PATH. I also checked with ldd.

So, I changed the tquery program to reproduce my problem. While doing
that, I found several other bugs, too. The patch is attached to this
mail.

In order of the code:
- Using con.query() several times causes invalid queries to be built.
- Templates with only one parameter create queries with no result
  because it uses the query itself as a parameter again. This is the
  problem I'm hitting in the other application.
- Setting a parameter to 0 or any other integer value directly causes a
  segfault. Most likely this is because it's implicitly casted to char*.
  I don't know whether this can be fixed. Checking for NULL only isn't
  enough.

Feel free to include the gdb code in exrun.

Greets,
Michael

-- 
Gentoo Linux developer, http://hansmi.ch/, http://forkbomb.ch/

Index: exrun
===================================================================
--- exrun	(revision 1486)
+++ exrun	(working copy)
@@ -28,6 +28,20 @@
 		exit 1
 	fi
 	PROG=$1
+
+elif [ "$PROG" == 'gdb' ]
+then
+	TOOL='gdb --args'
+	shift
+	if [ -z "$1" ]
+	then
+		echo "usage: $0 gdb <example> [args...]"
+		echo
+		echo "   Run $0 without arguments for more detailed usage info."
+		echo
+		exit 1
+	fi
+	PROG=$1
 fi
 shift
 
Index: lib/query.cpp
===================================================================
--- lib/query.cpp	(revision 1486)
+++ lib/query.cpp	(working copy)
@@ -614,6 +614,8 @@
 		}
 	}
 
+    std::cout << "query: " << str << std::endl;
+
 	if (success_ = !mysql_real_query(&conn_->mysql_, str, len)) {
 		MYSQL_RES* res = mysql_use_result(&conn_->mysql_);
 		if (res) {
Index: examples/tquery.cpp
===================================================================
--- examples/tquery.cpp	(revision 1486)
+++ examples/tquery.cpp	(working copy)
@@ -65,6 +65,64 @@
 
 		// Print the new table contents.
 		print_stock_table(query);
+
+        /* If enabled, the second query doesn't work anymore */
+        if (false) {
+            query = con.query();
+        }
+
+        std::cout << std::endl;
+        std::cout << "Doesn't work:" << std::endl;
+        query.reset();
+        query << "select * from stock where item = %0q:item";
+        query.parse();
+        query.def["item"] = "Nuerenberger Bratwurst";
+        mysqlpp::ResUse res3 = query.use();
+
+        try {
+            while (mysqlpp::Row row = res3.fetch_row()) {
+                std::cout << row["item"].get_string() << std::endl;
+            }
+        } catch (const mysqlpp::EndOfResults&) {
+        }
+
+        std::cout << std::endl;
+        std::cout << "Works:" << std::endl;
+        query.reset();
+        query << "select * from stock where item = %0q:item and num = %1:num";
+        query.parse();
+        query.def["item"] = "Hot Mustard";
+        query.def["num"] = 92;
+        mysqlpp::ResUse res4 = query.use();
+
+        try {
+            while (mysqlpp::Row row = res4.fetch_row()) {
+                std::cout << row["item"].get_string() << std::endl;
+            }
+        } catch (const mysqlpp::EndOfResults&) {
+        }
+
+        std::cout << std::endl;
+        std::cout << "Segfault:" << std::endl;
+        query.reset();
+        query << "select * from stock where item = %0q:item and num = %1:num";
+        query.parse();
+        query.def["item"] = "Hot Mustard";
+        /* If enabled, causes a segfault */
+        if (false) {
+            query.def["num"] = 0;
+        } else {
+            int tmp = 0;
+            query.def["num"] = tmp;
+        }
+        mysqlpp::ResUse res5 = query.use();
+
+        try {
+            while (mysqlpp::Row row = res5.fetch_row()) {
+                std::cout << row["item"].get_string() << std::endl;
+            }
+        } catch (const mysqlpp::EndOfResults&) {
+        }
 	}
 	catch (const mysqlpp::BadQuery& er) {
 		// Handle any query errors

Attachment: [application/pgp-signature]
Thread
Conceptual issue in mysql++ 2.2.x (use(), store(), execute())Michael Hanselmann25 Mar
  • Re: Conceptual issue in mysql++ 2.2.x (use(), store(), execute())Warren Young26 Mar
    • Re: Conceptual issue in mysql++ 2.2.x (use(), store(), execute())Michael Hanselmann26 Mar
      • Re: Conceptual issue in mysql++ 2.2.x (use(), store(), execute())Warren Young28 Mar
        • Re: Conceptual issue in mysql++ 2.2.x (use(), store(), execute())Warren Young28 Mar
        • Re: Conceptual issue in mysql++ 2.2.x (use(), store(), execute())Michael Hanselmann31 Mar
          • Re: Conceptual issue in mysql++ 2.2.x (use(), store(), execute())Warren Young2 Apr
            • Re: Conceptual issue in mysql++ 2.2.x (use(), store(), execute())Michael Hanselmann2 Apr
              • Re: Conceptual issue in mysql++ 2.2.x (use(), store(), execute())Warren Young3 Apr
                • Re: Conceptual issue in mysql++ 2.2.x (use(), store(), execute())Michael Hanselmann4 Apr
Re: Conceptual issue in mysql++ 2.2.x (use(), store(), execute())Warren Young29 Mar