MySQL Forums
Forum List  »  Connector/C++

Re: Mysql c++ application help
Posted by: Peter Brawley
Date: April 10, 2016 10:37PM

Your mysql_query() calls can fail in many ways, so they need error handling.

To debug query calls, stub out the query that your program has built, copy & paste it into the mysql program to see what query building errors you need to fix in your code.

Re formatting, absent html tables or an equivalent library, you need to format the data yourself, as in this very basic c code ...

  for( lrow = 0; lrow < rows; lrow++ ) {
    if(( row = mysql_fetch_row( rset )) != NULL ) {
      for( icol = 0; icol < cols; icol++ ) {
        column = columns[icol];
          if( column != NULL ) {
            if( strlen( row[icol] ) > column->max_length ) {
              column->max_length = strlen( row[icol] );
            }
          }
        }
     }
  }   
  for( icol = 0; icol < cols; icol++ ) {
    printf( "%-*s ", columns[icol]->max_length, strupr( columns[icol]->name ));
  }
  printf( "\n" );
  mysql_data_seek( rset, 0 );
  for( lrow = 0; lrow < rows; lrow++ ) {
    if(( row = mysql_fetch_row( rset )) != NULL ) {
      for( icol = 0; icol < cols; icol++ ) {
        printf( "%-*s ", columns[icol]->max_length, row[icol] );
      }
      printf( "\n" );
    }
  }
  printf( "%d %s\n", rows, "rows returned." );
  mysql_free_result( rset );
  mysql_close( conn );
  return 0;

Options: ReplyQuote


Subject
Views
Written By
Posted
1962
April 10, 2016 10:18PM
Re: Mysql c++ application help
946
April 10, 2016 10:37PM
823
April 14, 2016 04:00AM


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.