MySQL++

Error: Failed to find MySQL C API type ID for y
Login

Error: Failed to find MySQL C API type ID for y

(1) By nhall on 2019-02-15 15:52:29 [link] [source]

Hello,

I'm in the process of updating some old code from MySQL++ 2.1.1 to 3.2.4. Using MySQL++ 2.1.1 I had some code that looked something like:

  query << "INSERT INTO mytable SET ";
  query << "order_number='" << escape << order_number << "', ";
  query << "line_number='" << escape << results.insert_id << "', ";

which worked fine for many years. In MySQL++ 3.2.4 the insert_id changed to a function so I changed the code to:

   query << "INSERT INTO mytable SET ";
   query << "order_number='" << escape << order_number << "', ";
   query << "line_number='" << escape << results.insert_id() << "', ";

but upon running my program, when the query goes to execute this error occurs:

   Error: Failed to find MySQL C API type ID for y

So then I tried casting to an unsigned long like:

   query << "INSERT INTO mytable SET ";
   query << "order_number='" << escape << order_number << "', ";
   query << "line_number='" << escape << (unsigned long)results.insert_id() << "', ";

and the code ran fine!


Digging into the code further, I see that insert_id() is returning a ulonglong so I tried to explicitly cast to that in case something weird was going on:

   query << "line_number='" << escape << (ulonglong)results.insert_id() << "', ";

and that caused the same error as before:

   Error: Failed to find MySQL C API type ID for y

I also tried:

   query << "line_number='" << escape << (unsigned long long)results.insert_id() << "', ";

and that gives the same error.

I'm not familiar with the actual MySQL C API but it seems to me like perhaps it is not liking this unsigned long long data type.

I see in MySQL++ 2.1.1 insert_id was defined as "my_ulonglong" which is an actual datatype found in mysql.h, but this was changed. Could the issue be a mismatch between ulonglong and my_ulonglong since these are typedef'ed differently with the #ifdef logic in the corresponding h files? Like maybe my_ulonglong is defined as an unsigned long on my system but ulonglong is being defined as an unsigned long long?

For further information, this is a 64-bit system running Debian 8, g++ 4.9.2. Thanks and let me know if you need me to look up any more info.

(2) By Warren Young (tangent) on 2019-02-16 00:17:13 in reply to 1 [link] [source]

Try the current trunk. It has an accommodation for this case.

As a rule, you want to be using mysqlpp::sql_* types in such cases, not others, such as ulonglong, but we can't go changing insert_id() to return that, as that'd break the ABI.

(3) By Warren Young (tangent) on 2019-02-17 00:09:58 in reply to 2 [source]

If you're wondering how to get the current trunk version, just search for "trunk" on the project home page. You have tarball and Fossil clone options there.

(4) By nhall on 2019-02-20 12:44:41 in reply to 3 [link] [source]

The updated code in the trunk fixes the problem, thanks.