LCOV - code coverage report
Current view: top level - clients/examples/C - smack00.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 17 26 65.4 %
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, port, n = 20000;
      35             :         char buf[40];
      36             :         int lang = 1;
      37             :         char *l = "sql";
      38             : 
      39             :         /* char *line; */
      40             : 
      41           1 :         if (argc != 2 && argc != 3) {
      42           0 :                 printf("usage:smack00 <port> [<language>]\n");
      43           0 :                 exit(-1);
      44             :         }
      45           1 :         if (argc == 3) {
      46           1 :                 l = argv[2];
      47           1 :                 if (strcmp(argv[2], "sql") == 0)
      48             :                         lang = 1;
      49           0 :                 else if (strcmp(argv[2], "mal") == 0)
      50             :                         lang = 3;
      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             :         /* switch of autocommit */
      59           1 :         if (lang==1 && (mapi_setAutocommit(dbh, false) != MOK || mapi_error(dbh)))
      60           0 :                 die(dbh,NULL);
      61             : 
      62       20001 :         for (i = 0; i < n; i++) {
      63       20000 :                 if (lang==1)
      64       20000 :                         snprintf(buf, 40, "select %d;", i);
      65             :                 else
      66           0 :                         snprintf(buf, 40, "io.print(%d);", i);
      67       20000 :                 if ((hdl = mapi_query(dbh, buf)) == NULL || mapi_error(dbh))
      68           0 :                         die(dbh, hdl);
      69      120000 :                 while ( (/*line= */ mapi_fetch_line(hdl)) != NULL) {
      70             :                         /*printf("%s \n", line); */
      71             :                 }
      72       20000 :                 if (mapi_error(dbh))
      73           0 :                         die(dbh, hdl);
      74       20000 :                 if (mapi_close_handle(hdl) != MOK)
      75           0 :                         die(dbh, hdl);
      76             :         }
      77           1 :         mapi_destroy(dbh);
      78             : 
      79             :         return 0;
      80             : }

Generated by: LCOV version 1.14