LCOV - code coverage report
Current view: top level - clients/examples/C - smack00.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 27 35 77.1 %
Date: 2024-12-19 20:05:57 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.14