LCOV - code coverage report
Current view: top level - clients/examples/C - smack01.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 20 30 66.7 %
Date: 2021-09-14 19:48:19 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : #ifdef _MSC_VER
      10             : /* suppress deprecation warning for snprintf */
      11             : #define _CRT_SECURE_NO_WARNINGS
      12             : #endif
      13             : 
      14             : #include <stdlib.h>
      15             : #include <stdio.h>
      16             : #include <string.h>
      17             : #include <mapi.h>
      18             : 
      19             : #define die(dbh,hdl)    do {                                            \
      20             :                                 if (hdl)                                \
      21             :                                         mapi_explain_result(hdl,stderr); \
      22             :                                 else if (dbh)                           \
      23             :                                         mapi_explain(dbh,stderr);       \
      24             :                                 else                                    \
      25             :                                         fprintf(stderr,"command failed\n"); \
      26             :                                 exit(-1);                               \
      27             :                         } while (0)
      28             : 
      29             : int
      30           1 : main(int argc, char **argv)
      31             : {
      32             :         Mapi dbh;
      33             :         MapiHdl hdl = NULL;
      34             :         int i;
      35             :         char buf[40], *line;
      36             :         int port;
      37             :         int lang = 1;
      38             :         char *l = "sql";
      39             : 
      40           1 :         if (argc != 2 && argc != 3) {
      41           0 :                 printf("usage: smack01 <port> [<language>]\n");
      42           0 :                 exit(-1);
      43             :         }
      44           1 :         if (argc == 3) {
      45           1 :                 l = argv[2];
      46           1 :                 if (strcmp(argv[2], "sql") == 0)
      47             :                         lang = 1;
      48           0 :                 else if (strcmp(argv[2], "mal") == 0)
      49             :                         lang = 3;
      50             :         }
      51             : 
      52             : 
      53           1 :         port = atol(argv[1]);
      54           1 :         dbh = mapi_connect("localhost", port, "monetdb", "monetdb", l, NULL);
      55           1 :         if (dbh == NULL || mapi_error(dbh))
      56           0 :                 die(dbh, hdl);
      57             : 
      58        1001 :         for (i = 0; i < 1000; i++) {
      59             :                 /* printf("setup connection %d\n", i); */
      60        1000 :                 mapi_reconnect(dbh);
      61        1000 :                 if (mapi_error(dbh))
      62           0 :                         die(dbh, hdl);
      63             : 
      64             :                 /* switch of autocommit */
      65        1000 :                 if (lang==1 && (mapi_setAutocommit(dbh, false) != MOK || mapi_error(dbh)))
      66           0 :                         die(dbh,NULL);
      67             : 
      68        1000 :                 if (lang==1)
      69        1000 :                         snprintf(buf, 40, "select %d;", i);
      70             :                 else
      71           0 :                         snprintf(buf, 40, "io.print(%d);", i);
      72        1000 :                 if ((hdl = mapi_query(dbh, buf)) == NULL || mapi_error(dbh))
      73           0 :                         die(dbh, hdl);
      74        6000 :                 while ((line = mapi_fetch_line(hdl))) {
      75             :                         // printf("%s \n", line);
      76             :                         (void) line;
      77             :                 }
      78        1000 :                 if (mapi_error(dbh))
      79           0 :                         die(dbh, hdl);
      80        1000 :                 if (mapi_close_handle(hdl) != MOK)
      81           0 :                         die(dbh, hdl);
      82        1000 :                 mapi_disconnect(dbh);
      83             :                 /* printf("close connection %d\n", i); */
      84             :         }
      85             : 
      86           1 :         mapi_destroy(dbh);
      87             : 
      88             :         return 0;
      89             : }

Generated by: LCOV version 1.14