0

I got a problem regarding simple MySQL function which is mysql_fetch_row when ever I use it, my application will crash with it will go to the point when its executing. No matter what query I would run it will crash. The core dump says following:

(gdb) bt full
#0  0x2866397f in mysql_store_result () from /usr/home/ld/application
#1  0x28637905 in main () from /usr/home/ld/application
#2  0x08441d3a in CRC_GetCodeSize20 ()

The code looks simple:

int main()
{
  MYSQL *conn;      // the connection
  MYSQL_RES *res;   // the results
  MYSQL_ROW row;    // the results row (line by line)
 
  struct connection_details mysqlD;
  mysqlD.server = "localhost";  // where the mysql database is
  mysqlD.user = "mysqlusername";        // the root user of mysql   
  mysqlD.password = "mysqlpassword"; // the password of the root user in mysql
  mysqlD.database = "mysql";    // the databse to pick
 
  conn = mysql_connection_setup(mysqlD);
 
  res = mysql_perform_query(conn, "select 1, 2");
 
  printf("Result:\n");
  while ((row = mysql_fetch_row(res)) !=NULL)
      printf("%s\n", row[0]);
 
  mysql_free_result(res);
  mysql_close(conn);
 
  return 0;
}

What is the problem?

edit

mysql_perform_query:

MYSQL_RES* mysql_perform_query(MYSQL *connection, char *sql_query)
{
   if (mysql_query(connection, sql_query))
   {
      printf("MySQL query error : %s\n", mysql_error(connection));
      exit(1);
   }
 
   return mysql_use_result(connection);
}
7
  • 1
    Add some error checking. Both the connection and the query could fail but there's is no check for either. Commented Nov 16, 2013 at 22:04
  • @RetiredNinja I have been trying performing some error checking, when I remove the mysql_fetch_row then application is working. I have tried to set a error check for almost all variables : res, conn and the mysql_fetch_row itself. Commented Nov 16, 2013 at 22:11
  • I have also turned mysql logging on the query executes, which means the connection is fine: 131116 22:05:42 47 Query SELECT 1, 2. Commented Nov 16, 2013 at 23:43
  • What does your mysql_perform_query look like? You might want to include that part of your code in the question since that's what seems to be setting up "res." Commented Nov 16, 2013 at 23:47
  • Are you sure that row[0] is valid? Commented Nov 17, 2013 at 2:51

2 Answers 2

4
+300

Ok. So I have spent quite some time to reproduce this problem. I assume you took the example from this tutorial: http://www.codingfriends.com/index.php/2010/02/17/mysql-connection-example/ since it's exactly the same.

Steps taken:

  1. cd /usr/ports/databases/mysql56-client && make install

  2. Copy pasted the exact code from the above tutorial to test.cpp

  3. g++ -I/usr/local/include/mysql -L/usr/local/lib/mysql -lmysqlclient test.cpp

  4. ./a.out

  5. Output:

    Mysql tables in database: entry old

I used my remote mysql server and a test account. First I made sure I can connect to it via console mysql -h mydomain.com -u test -p

The program seems to work normally. The only thing I noticed is that sometimes it takes 1 second to execute while other times it takes up to 10 seconds for whatever reason.

Built on PC-BSD Isotope Edition (9.1 RELEASE) with up to date port tree.

So now there are 2 people with successful build (me and your friend). Code being the same the only thing I can think of going wrong is the libmysqlclient.so library. Try to update your port tree and do a fresh build. Or maybe try a different version.

Sign up to request clarification or add additional context in comments.

6 Comments

I have took exactly the same steps, with the only difference I'm running the compiled application on the FreeBSD 9.0 (my friend is using it as well) while the application itself was compiled on the FreeBSD 9.1. Its still crashing.
You can't compile it on the native machine? Also, is the mysql lib the same on both systems? What if you run it on 9.1?
No, the MySQL lib is quite different. Mysql version on the 9.1: mysql_config --version 5.6.14, and on the 9.0: mysql_config --version 5.5.28.
Well.. maybe this is the problem? I mean.. you are linking against 5.6.14 and you are running it with 5.5.28. As I said above, first try to run it on 9.1 and if it works there the problem seems obvious.
So it might be the mysql fault. Is there a way to upgrade the mysql in FreeBSD?
|
0

You could try viewing the registered *port* using the netstat command ,
because the reason it might be crashing is, you are using an already registered port for your dbase. Check for that.
Also if you find out working on an already registered port, try changing the port number in the S/w along with that you have to remove the value from the registry as well(regedit) .(Sometimes it uses the shadow port , so need to do that).

Also check for null in your "conn", Somehow maybe you arn't able to initiate a connection. (connection pool exhaustion?? Very doubtful ).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.