#include <windows.h>#include <stdio.h>#include <string.h>#include <mysql.h>Include dependency graph for mytest.c:

Go to the source code of this file.
Defines | |
| #define | DEFALT_SQL_STMT "SELECT * FROM db" |
| #define | offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) |
Functions | |
| int | main (int argc, char *argv[]) |
| #define offsetof | ( | TYPE, | |||
| MEMBER | ) | ((size_t) &((TYPE *)0)->MEMBER) |
| int main | ( | int | argc, | |
| char * | argv[] | |||
| ) |
Definition at line 61 of file mytest.c.
References st_mysql::affected_rows, DEFALT_SQL_STMT, st_mysql::field_alloc, st_mysql::fields, st_mysql::free_me, host, st_mysql::host, int(), mysql_close(), mysql_error(), mysql_fetch_field(), mysql_fetch_row(), mysql_free_result(), mysql_get_client_info(), mysql_get_host_info(), mysql_get_server_info(), mysql_init(), mysql_list_processes(), mysql_list_tables(), mysql_num_fields(), mysql_num_rows(), MYSQL_PORT, mysql_query(), mysql_real_connect(), mysql_select_db(), mysql_stat(), mysql_store_result(), st_mysql_field::name, st_mysql::net, NULL, offsetof, options(), st_mysql::options, st_mysql::packet_length, port, st_mysql::port, protocol_version, st_mysql::protocol_version, st_mysql::reconnect, status, st_mysql::status, strcmp(), strlen(), thread_id, st_mysql::thread_id, and x.
00063 { 00064 00065 00066 00067 char szSQL[ 200 ], aszFlds[ 25 ][ 25 ], szDB[ 50 ] ; 00068 00069 const char *pszT; 00070 int i, j, k, l, x ; 00071 00072 MYSQL * myData ; 00073 00074 MYSQL_RES * res ; 00075 00076 MYSQL_FIELD * fd ; 00077 00078 MYSQL_ROW row ; 00079 00080 00081 00082 //....just curious.... 00083 00084 printf( "sizeof( MYSQL ) == %d\n", (int) sizeof( MYSQL ) ) ; 00085 if ( argc == 2 ) 00086 00087 { 00088 00089 strcpy( szDB, argv[ 1 ] ) ; 00090 00091 strcpy( szSQL, DEFALT_SQL_STMT ) ; 00092 00093 if (!strcmp(szDB,"--debug")) 00094 00095 { 00096 00097 strcpy( szDB, "mysql" ) ; 00098 00099 printf("Some mysql struct information (size and offset):\n"); 00100 00101 printf("net:\t%3d %3d\n",(int) sizeof(myData->net), 00102 (int) offsetof(MYSQL,net)); 00103 printf("host:\t%3d %3d\n",(int) sizeof(myData->host), 00104 (int) offsetof(MYSQL,host)); 00105 printf("port:\t%3d %3d\n", (int) sizeof(myData->port), 00106 (int) offsetof(MYSQL,port)); 00107 printf("protocol_version:\t%3d %3d\n", 00108 (int) sizeof(myData->protocol_version), 00109 (int) offsetof(MYSQL,protocol_version)); 00110 printf("thread_id:\t%3d %3d\n",(int) sizeof(myData->thread_id), 00111 (int) offsetof(MYSQL,thread_id)); 00112 printf("affected_rows:\t%3d %3d\n",(int) sizeof(myData->affected_rows), 00113 (int) offsetof(MYSQL,affected_rows)); 00114 printf("packet_length:\t%3d %3d\n",(int) sizeof(myData->packet_length), 00115 (int) offsetof(MYSQL,packet_length)); 00116 printf("status:\t%3d %3d\n",(int) sizeof(myData->status), 00117 (int) offsetof(MYSQL,status)); 00118 printf("fields:\t%3d %3d\n",(int) sizeof(myData->fields), 00119 (int) offsetof(MYSQL,fields)); 00120 printf("field_alloc:\t%3d %3d\n",(int) sizeof(myData->field_alloc), 00121 (int) offsetof(MYSQL,field_alloc)); 00122 printf("free_me:\t%3d %3d\n",(int) sizeof(myData->free_me), 00123 (int) offsetof(MYSQL,free_me)); 00124 printf("options:\t%3d %3d\n",(int) sizeof(myData->options), 00125 (int) offsetof(MYSQL,options)); 00126 puts(""); 00127 00128 } 00129 00130 } 00131 00132 else if ( argc > 2 ) { 00133 00134 strcpy( szDB, argv[ 1 ] ) ; 00135 00136 strcpy( szSQL, argv[ 2 ] ) ; 00137 00138 } 00139 00140 else { 00141 00142 strcpy( szDB, "mysql" ) ; 00143 00144 strcpy( szSQL, DEFALT_SQL_STMT ) ; 00145 00146 } 00147 00148 //.... 00149 00150 00151 00152 if ( (myData = mysql_init((MYSQL*) 0)) && 00153 00154 mysql_real_connect( myData, NULL, NULL, NULL, NULL, MYSQL_PORT, 00155 00156 NULL, 0 ) ) 00157 00158 { 00159 00160 myData->reconnect= 1; 00161 if ( mysql_select_db( myData, szDB ) < 0 ) { 00162 00163 printf( "Can't select the %s database !\n", szDB ) ; 00164 00165 mysql_close( myData ) ; 00166 00167 return 2 ; 00168 00169 } 00170 00171 } 00172 00173 else { 00174 00175 printf( "Can't connect to the mysql server on port %d !\n", 00176 00177 MYSQL_PORT ) ; 00178 00179 mysql_close( myData ) ; 00180 00181 return 1 ; 00182 00183 } 00184 00185 //.... 00186 00187 if ( ! mysql_query( myData, szSQL ) ) { 00188 00189 res = mysql_store_result( myData ) ; 00190 00191 i = (int) mysql_num_rows( res ) ; l = 1 ; 00192 00193 printf( "Query: %s\nNumber of records found: %ld\n", szSQL, i ) ; 00194 00195 //....we can get the field-specific characteristics here.... 00196 00197 for ( x = 0 ; fd = mysql_fetch_field( res ) ; x++ ) 00198 00199 strcpy( aszFlds[ x ], fd->name ) ; 00200 00201 //.... 00202 00203 while ( row = mysql_fetch_row( res ) ) { 00204 00205 j = mysql_num_fields( res ) ; 00206 00207 printf( "Record #%ld:-\n", l++ ) ; 00208 00209 for ( k = 0 ; k < j ; k++ ) 00210 00211 printf( " Fld #%d (%s): %s\n", k + 1, aszFlds[ k ], 00212 00213 (((row[k]==NULL)||(!strlen(row[k])))?"NULL":row[k])) ; 00214 00215 puts( "==============================\n" ) ; 00216 00217 } 00218 00219 mysql_free_result( res ) ; 00220 00221 } 00222 00223 else printf( "Couldn't execute %s on the server !\n", szSQL ) ; 00224 00225 //.... 00226 00227 puts( "==== Diagnostic info ====" ) ; 00228 00229 pszT = mysql_get_client_info() ; 00230 00231 printf( "Client info: %s\n", pszT ) ; 00232 00233 //.... 00234 00235 pszT = mysql_get_host_info( myData ) ; 00236 00237 printf( "Host info: %s\n", pszT ) ; 00238 00239 //.... 00240 00241 pszT = mysql_get_server_info( myData ) ; 00242 00243 printf( "Server info: %s\n", pszT ) ; 00244 00245 //.... 00246 00247 res = mysql_list_processes( myData ) ; l = 1 ; 00248 00249 if (res) 00250 00251 { 00252 00253 for ( x = 0 ; fd = mysql_fetch_field( res ) ; x++ ) 00254 00255 strcpy( aszFlds[ x ], fd->name ) ; 00256 00257 while ( row = mysql_fetch_row( res ) ) { 00258 00259 j = mysql_num_fields( res ) ; 00260 00261 printf( "Process #%ld:-\n", l++ ) ; 00262 00263 for ( k = 0 ; k < j ; k++ ) 00264 00265 printf( " Fld #%d (%s): %s\n", k + 1, aszFlds[ k ], 00266 00267 (((row[k]==NULL)||(!strlen(row[k])))?"NULL":row[k])) ; 00268 00269 puts( "==============================\n" ) ; 00270 00271 } 00272 00273 } 00274 00275 else 00276 00277 { 00278 00279 printf("Got error %s when retreiving processlist\n",mysql_error(myData)); 00280 00281 } 00282 00283 //.... 00284 00285 res = mysql_list_tables( myData, "%" ) ; l = 1 ; 00286 00287 for ( x = 0 ; fd = mysql_fetch_field( res ) ; x++ ) 00288 00289 strcpy( aszFlds[ x ], fd->name ) ; 00290 00291 while ( row = mysql_fetch_row( res ) ) { 00292 00293 j = mysql_num_fields( res ) ; 00294 00295 printf( "Table #%ld:-\n", l++ ) ; 00296 00297 for ( k = 0 ; k < j ; k++ ) 00298 00299 printf( " Fld #%d (%s): %s\n", k + 1, aszFlds[ k ], 00300 00301 (((row[k]==NULL)||(!strlen(row[k])))?"NULL":row[k])) ; 00302 00303 puts( "==============================\n" ) ; 00304 00305 } 00306 00307 //.... 00308 00309 pszT = mysql_stat( myData ) ; 00310 00311 puts( pszT ) ; 00312 00313 //.... 00314 00315 mysql_close( myData ) ; 00316 00317 return 0 ; 00318 00319 00320 00321 }
Here is the call graph for this function:

1.4.7

