List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:September 27 2010 4:39pm
Subject:Re: How to pass null as SQLQueryParams
View as plain text  
On Sep 26, 2010, at 1:45 PM, Michal wrote:

> The invoking in C++ looks like:
>                std::string strQuery = "CALL MyFunction(%0q, %1q, %2q, %3q)";
>                mysqlpp::Query  query = connection->query(strQuery);
>                mysqlpp::SQLQueryParms params;
>                query.parse();
>                // the type of strings are std::string
>                params << String1;
>                params << String2;
>                params << String3; // This string has value " ". I would like
> to
> store it as null
>                params << String4;
>                query.execute(params);

Have you tried "params << mysqlpp::null"?

By the way, I don't see anything in this code that requires the explicit creation of
SQLQueryParms or query string objects.  This code is shorter, and, I think, clearer:

    mysqlpp::Query query = connection->query(
        "CALL MyFunction(%0q, %1q, %2q, %3q)");
    query.execute(String1, String2, mysqlpp::null, String4);

> I can not predict which String will have value " ", this situation that this is
> String3 is only example.

In that case, you'd do something like this:

     mysqlpp::String s;
     if (it_is_supposed_to_be_null()) {
         s.assign(0, 0, mysql_type_info::string_type, true);
     else {
         s = "foo";

We should probably add assignment-from-null instead of making you jump through hoops like
this.  I've added it to the Wishlist.  You may want to create the patch to ensure it gets
added to the library sooner rather than later.
How to pass null as SQLQueryParamsMichal26 Sep
  • Re: How to pass null as SQLQueryParamsWarren Young27 Sep