mariadb/mytest-old.c
unknown dfacd7c5fa Merge with 3.23.58
BitKeeper/etc/logging_ok:
  auto-union
mytest-old.c:
  Merge rename: VC++Files/libmysqltest/mytest.c -> mytest-old.c
BitKeeper/deleted/.del-mysqlshutdown.c:
  Delete: VC++Files/mysqlshutdown/mysqlshutdown.c
BitKeeper/deleted/.del-mysqlshutdown.rc:
  Delete: VC++Files/mysqlshutdown/mysqlshutdown.rc
BitKeeper/deleted/.del-mysqlwatch.c:
  Delete: VC++Files/mysqlwatch/mysqlwatch.c
BitKeeper/deleted/.del-thr_test.c:
  Delete: VC++Files/thr_test/thr_test.c
BitKeeper/deleted/.del-make_win_src_distribution.sh:
  Delete: scripts/make_win_src_distribution.sh
BitKeeper/deleted/.del-.fgl~cac6624e1ac6ee1d:
  Auto merged
BitKeeper/deleted/.del-Build.tsb~f3be7d512e6d5b74:
  Auto merged
BitKeeper/deleted/.del-Clients and Tools.fgl~826a8e3f651af365:
  Auto merged
BitKeeper/deleted/.del-Default.cdf~1da6505528200d5e:
  Auto merged
BitKeeper/deleted/.del-Default.fdf~466762fdf65e1477:
  Auto merged
BitKeeper/deleted/.del-Default.fgl~45b9e847fa4da131:
  Auto merged
BitKeeper/deleted/.del-Default.fgl~a86ce70180b5aba4:
  Auto merged
BitKeeper/deleted/.del-Default.rge~2218627c2a901409:
  Auto merged
BitKeeper/deleted/.del-Default.shl~a02a9093c2b6b0d9:
  Auto merged
BitKeeper/deleted/.del-Default.shl~e18d3f10bef97a28:
  Auto merged
BitKeeper/deleted/.del-Development.fgl~ca1458874a3fef81:
  Auto merged
BitKeeper/deleted/.del-Grant Tables.fgl~31e527d126c42d90:
  Auto merged
BitKeeper/deleted/.del-MySQL 3.23.com.ipr~eb817edea43c6e6e:
  Auto merged
BitKeeper/deleted/.del-SETUP.BMP~77e20d86bceb4903:
  Auto merged
BitKeeper/deleted/.del-Servers.fgl~36147accb82f759:
  Auto merged
BitKeeper/deleted/.del-Setup.dbg~688e9d3ec362ec34:
  Auto merged
BitKeeper/deleted/.del-Setup.ino~85f07a856a69a722:
  Auto merged
BitKeeper/deleted/.del-Setup.ins~ab68efc133d8411e:
  Auto merged
BitKeeper/deleted/.del-Setup.obs~2f09140119879bc6:
  Auto merged
BitKeeper/deleted/.del-Setup.rul~14510a994d515f19:
  Auto merged
BitKeeper/deleted/.del-Setup.tsb~e74dbc7688d4019a:
  Auto merged
BitKeeper/deleted/.del-infolist.txt~58b203247936d266:
  Auto merged
BitKeeper/deleted/.del-infolist.txt~ee370f4771c83a97:
  Auto merged
BitKeeper/deleted/.del-value.shl~718b5b291d5ff04d:
  Auto merged
BitKeeper/deleted/.del-value.shl~98c2851db96b919e:
  Auto merged
BitKeeper/deleted/.del-Documentation.fgl~cf0ac866737a5c7d:
  Auto merged
configure.in:
  Merge with 3.23.58 (Keep old code)
sql/slave.cc:
  Merge with 3.23.58 (Keep old code)
sql/sql_parse.cc:
  Merge with 3.23.58 (Keep old code)
2003-10-06 21:21:04 +03:00

169 lines
5.1 KiB
C

/*C4*/
/****************************************************************/
/* Author: Jethro Wright, III TS : 3/ 4/1998 9:15 */
/* Date: 02/18/1998 */
/* mytest.c : do some testing of the libmySQL.DLL.... */
/* */
/* History: */
/* 02/18/1998 jw3 also sprach zarathustra.... */
/****************************************************************/
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <mysql.h>
#define DEFALT_SQL_STMT "SELECT * FROM db"
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
/********************************************************
**
** main :-
**
********************************************************/
int
main( int argc, char * argv[] )
{
char szSQL[ 200 ], aszFlds[ 25 ][ 25 ], * pszT, szDB[ 50 ] ;
int i, j, k, l, x ;
MYSQL * myData ;
MYSQL_RES * res ;
MYSQL_FIELD * fd ;
MYSQL_ROW row ;
//....just curious....
printf( "sizeof( MYSQL ) == %d\n", sizeof( MYSQL ) ) ;
if ( argc == 2 )
{
strcpy( szDB, argv[ 1 ] ) ;
strcpy( szSQL, DEFALT_SQL_STMT ) ;
if (!strcmp(szDB,"--debug"))
{
strcpy( szDB, "mysql" ) ;
printf("Some mysql struct information (size and offset):\n");
printf("net:\t%3d %3d\n",sizeof(myData->net),offsetof(MYSQL,net));
printf("host:\t%3d %3d\n",sizeof(myData->host),offsetof(MYSQL,host));
printf("port:\t%3d %3d\n",sizeof(myData->port),offsetof(MYSQL,port));
printf("protocol_version:\t%3d %3d\n",sizeof(myData->protocol_version),
offsetof(MYSQL,protocol_version));
printf("thread_id:\t%3d %3d\n",sizeof(myData->thread_id),
offsetof(MYSQL,thread_id));
printf("affected_rows:\t%3d %3d\n",sizeof(myData->affected_rows),
offsetof(MYSQL,affected_rows));
printf("packet_length:\t%3d %3d\n",sizeof(myData->packet_length),
offsetof(MYSQL,packet_length));
printf("status:\t%3d %3d\n",sizeof(myData->status),
offsetof(MYSQL,status));
printf("fields:\t%3d %3d\n",sizeof(myData->fields),
offsetof(MYSQL,fields));
printf("field_alloc:\t%3d %3d\n",sizeof(myData->field_alloc),
offsetof(MYSQL,field_alloc));
printf("free_me:\t%3d %3d\n",sizeof(myData->free_me),
offsetof(MYSQL,free_me));
printf("options:\t%3d %3d\n",sizeof(myData->options),
offsetof(MYSQL,options));
puts("");
}
}
else if ( argc > 2 ) {
strcpy( szDB, argv[ 1 ] ) ;
strcpy( szSQL, argv[ 2 ] ) ;
}
else {
strcpy( szDB, "mysql" ) ;
strcpy( szSQL, DEFALT_SQL_STMT ) ;
}
//....
if ( (myData = mysql_init((MYSQL*) 0)) &&
mysql_real_connect( myData, NULL, NULL, NULL, NULL, MYSQL_PORT,
NULL, 0 ) )
{
if ( mysql_select_db( myData, szDB ) < 0 ) {
printf( "Can't select the %s database !\n", szDB ) ;
mysql_close( myData ) ;
return 2 ;
}
}
else {
printf( "Can't connect to the mysql server on port %d !\n",
MYSQL_PORT ) ;
mysql_close( myData ) ;
return 1 ;
}
//....
if ( ! mysql_query( myData, szSQL ) ) {
res = mysql_store_result( myData ) ;
i = (int) mysql_num_rows( res ) ; l = 1 ;
printf( "Query: %s\nNumber of records found: %ld\n", szSQL, i ) ;
//....we can get the field-specific characteristics here....
for ( x = 0 ; fd = mysql_fetch_field( res ) ; x++ )
strcpy( aszFlds[ x ], fd->name ) ;
//....
while ( row = mysql_fetch_row( res ) ) {
j = mysql_num_fields( res ) ;
printf( "Record #%ld:-\n", l++ ) ;
for ( k = 0 ; k < j ; k++ )
printf( " Fld #%d (%s): %s\n", k + 1, aszFlds[ k ],
(((row[k]==NULL)||(!strlen(row[k])))?"NULL":row[k])) ;
puts( "==============================\n" ) ;
}
mysql_free_result( res ) ;
}
else printf( "Couldn't execute %s on the server !\n", szSQL ) ;
//....
puts( "==== Diagnostic info ====" ) ;
pszT = mysql_get_client_info() ;
printf( "Client info: %s\n", pszT ) ;
//....
pszT = mysql_get_host_info( myData ) ;
printf( "Host info: %s\n", pszT ) ;
//....
pszT = mysql_get_server_info( myData ) ;
printf( "Server info: %s\n", pszT ) ;
//....
res = mysql_list_processes( myData ) ; l = 1 ;
if (res)
{
for ( x = 0 ; fd = mysql_fetch_field( res ) ; x++ )
strcpy( aszFlds[ x ], fd->name ) ;
while ( row = mysql_fetch_row( res ) ) {
j = mysql_num_fields( res ) ;
printf( "Process #%ld:-\n", l++ ) ;
for ( k = 0 ; k < j ; k++ )
printf( " Fld #%d (%s): %s\n", k + 1, aszFlds[ k ],
(((row[k]==NULL)||(!strlen(row[k])))?"NULL":row[k])) ;
puts( "==============================\n" ) ;
}
}
else
{
printf("Got error %s when retreiving processlist\n",mysql_error(myData));
}
//....
res = mysql_list_tables( myData, "%" ) ; l = 1 ;
for ( x = 0 ; fd = mysql_fetch_field( res ) ; x++ )
strcpy( aszFlds[ x ], fd->name ) ;
while ( row = mysql_fetch_row( res ) ) {
j = mysql_num_fields( res ) ;
printf( "Table #%ld:-\n", l++ ) ;
for ( k = 0 ; k < j ; k++ )
printf( " Fld #%d (%s): %s\n", k + 1, aszFlds[ k ],
(((row[k]==NULL)||(!strlen(row[k])))?"NULL":row[k])) ;
puts( "==============================\n" ) ;
}
//....
pszT = mysql_stat( myData ) ;
puts( pszT ) ;
//....
mysql_close( myData ) ;
return 0 ;
}