MySQL Forums
Forum List  »  Connector/C (libmysql)

mysql_fetch_lengths and rows
Posted by: Edward Diener
Date: April 01, 2018 06:36PM

Does the 'unsigned long *' returned from a call to mysql_fetch_lengths(MYSQL_RES *result) change for each row read using mysql_fetch_row(MYSQL_RES *result) ? I would have though that it must, since the actual column lengths of data may change for each row read.

Yet when I compiled a program using gcc's -O3 optimization and debugged the program with gdb because of a program hang, I noticed that gdb told me that the unsigned long * variable I was using to hold the result from mysql_fetch_lengths had been optimized away. In other words, in a loop such as:

#include <mysql/mysql.h>
// assume res has been correctly set in the code here
unsigned long * col_lengths;
while ((row = mysql_fetch_row(res)) != 0)
col_lengths = mysql_fetch_lengths(res);
... more code

the gdb debugger tells me, when I try to 'print col_lengths' at the beginner of debugging the ... more code section, that col_lengths has been optimized away. This implies that gcc with the -O3 optimization options has decided that col_lengths is a hardcoded value that can not change in the loop.

Does anybody know that is going on here ? It sounds to me that I can not use gcc's optimization levels when calling mysql client code. Is this somehwere in the MySql docs, or have I missed something here ?

Compiling with -O0 works fine, but -O3 does not as evidenced by this problem. This is a Linux apllication using gcc-7.2 on a Debian ARM system. The program is duly linking with the mysqlclient shared library.

Options: ReplyQuote

Written By
mysql_fetch_lengths and rows
April 01, 2018 06:36PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.