You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.9 KiB

26 years ago
26 years ago
26 years ago
26 years ago
  1. /* Copyright (C) 2000 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  13. #if defined(_WIN32) || defined(_WIN64)
  14. #include <windows.h>
  15. #endif
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include "mysql.h"
  19. #define SELECT_QUERY "select name from test where num = %d"
  20. int main(int argc, char **argv)
  21. {
  22. int count, num;
  23. MYSQL mysql,*sock;
  24. MYSQL_RES *res;
  25. char qbuf[160];
  26. if (argc != 3)
  27. {
  28. fprintf(stderr,"usage : select_test <dbname> <num>\n\n");
  29. exit(1);
  30. }
  31. mysql_init(&mysql);
  32. if (!(sock = mysql_real_connect(&mysql,NULL,0,0,argv[1],0,NULL,0)))
  33. {
  34. fprintf(stderr,"Couldn't connect to engine!\n%s\n\n",mysql_error(&mysql));
  35. perror("");
  36. exit(1);
  37. }
  38. mysql.reconnect= 1;
  39. count = 0;
  40. num = atoi(argv[2]);
  41. while (count < num)
  42. {
  43. sprintf(qbuf,SELECT_QUERY,count);
  44. if(mysql_query(sock,qbuf))
  45. {
  46. fprintf(stderr,"Query failed (%s)\n",mysql_error(sock));
  47. exit(1);
  48. }
  49. if (!(res=mysql_store_result(sock)))
  50. {
  51. fprintf(stderr,"Couldn't get result from %s\n",
  52. mysql_error(sock));
  53. exit(1);
  54. }
  55. #ifdef TEST
  56. printf("number of fields: %d\n",mysql_num_fields(res));
  57. #endif
  58. mysql_free_result(res);
  59. count++;
  60. }
  61. mysql_close(sock);
  62. exit(0);
  63. return 0; /* Keep some compilers happy */
  64. }