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