1 /* Copyright (c) 2000, 2003, 2004 MySQL AB
2    Use is subject to license terms
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; version 2 of the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1335  USA */
16 
17 #ifdef __WIN__
18 #include <windows.h>
19 #endif
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include "mysql.h"
23 
24 #define SELECT_QUERY "select name from test where num = %d"
25 
26 
27 int main(int argc, char **argv)
28 {
29   int	count, num;
30   MYSQL mysql,*sock;
31   MYSQL_RES *res;
32   char	qbuf[160];
33 
34   if (argc != 2)
35   {
36     fprintf(stderr,"usage : select_test <dbname>\n\n");
37     exit(1);
38   }
39 
40   if (!(sock = mysql_connect(&mysql,NULL,0,0)))
41   {
42     fprintf(stderr,"Couldn't connect to engine!\n%s\n\n",mysql_error(&mysql));
43     perror("");
44     exit(1);
45   }
46   mysql.reconnect= 1;
47 
48   if (mysql_select_db(sock,argv[1]) < 0)
49   {
50     fprintf(stderr,"Couldn't select database %s!\n%s\n",argv[1],
51 	    mysql_error(sock));
52     exit(1);
53   }
54 
55   if (!(res=mysql_list_dbs(sock,NULL)))
56   {
57     fprintf(stderr,"Couldn't list dbs!\n%s\n",mysql_error(sock));
58     exit(1);
59   }
60   mysql_free_result(res);
61   if (!(res=mysql_list_tables(sock,NULL)))
62   {
63     fprintf(stderr,"Couldn't list tables!\n%s\n",mysql_error(sock));
64     exit(1);
65   }
66   mysql_free_result(res);
67 
68   mysql_close(sock);
69   exit(0);
70   return 0;
71 }
72