1 /* Copyright (c) 2000, 2003, 2004, 2007 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, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
23 
24 
25 #ifdef __WIN__
26 #include <windows.h>
27 #endif
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include "mysql.h"
31 #include "config.h"
32 #define SELECT_QUERY "select name from test where num = %d"
33 
34 
main(int argc,char ** argv)35 int main(int argc, char **argv)
36 {
37 #ifdef HAVE_OPENSSL
38   int	count, num;
39   MYSQL mysql,*sock;
40   MYSQL_RES *res;
41   char	qbuf[160];
42 
43   if (argc != 3)
44   {
45     fprintf(stderr,"usage : ssl_test <dbname> <num>\n\n");
46     exit(1);
47   }
48 
49   mysql_init(&mysql);
50 #ifdef HAVE_OPENSSL
51   mysql_ssl_set(&mysql,"../SSL/MySQL-client-key.pem",
52     "../SSL/MySQL-client-cert.pem",
53     "../SSL/MySQL-ca-cert.pem", 0, 0);
54 #endif
55   if (!(sock = mysql_real_connect(&mysql,"127.0.0.1",0,0,argv[1],MYSQL_PORT,NULL,0)))
56   {
57     fprintf(stderr,"Couldn't connect to engine!\n%s\n\n",mysql_error(&mysql));
58     perror("");
59     exit(1);
60   }
61   mysql.reconnect= 1;
62   count = 0;
63   num = atoi(argv[2]);
64   while (count < num)
65   {
66     sprintf(qbuf,SELECT_QUERY,count);
67     if(mysql_query(sock,qbuf))
68     {
69       fprintf(stderr,"Query failed (%s)\n",mysql_error(sock));
70       exit(1);
71     }
72     if (!(res=mysql_store_result(sock)))
73     {
74       fprintf(stderr,"Couldn't get result from query failed (%s)\n",
75 	      mysql_error(sock));
76       exit(1);
77     }
78 #ifdef TEST
79     printf("number of fields: %d\n",mysql_num_fields(res));
80 #endif
81     mysql_free_result(res);
82     count++;
83   }
84   mysql_close(sock);
85 #else /* HAVE_OPENSSL */
86   printf("ssl_test: SSL not configured.\n");
87 #endif /* HAVE_OPENSSL */
88   exit(0);
89   return 0;					/* Keep some compilers happy */
90 }
91