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;
39 1 : char buf[40], *line;
40 1 : int port;
41 1 : int lang = 1;
42 1 : char *l = "sql";
43 :
44 1 : if (argc != 2 && argc != 3) {
45 0 : printf("usage: smack01 <port> [<language>]\n");
46 0 : exit(-1);
47 : }
48 1 : if (argc == 3) {
49 1 : l = argv[2];
50 1 : if (strcmp(argv[2], "sql") == 0)
51 : lang = 1;
52 0 : else if (strcmp(argv[2], "mal") == 0)
53 1 : lang = 3;
54 : }
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 1001 : for (i = 0; i < 1000; i++) {
63 : /* printf("setup connection %d\n", i); */
64 1000 : mapi_reconnect(dbh);
65 1000 : if (mapi_error(dbh))
66 0 : die(dbh, hdl);
67 :
68 : /* switch of autocommit */
69 1000 : if (lang==1 && (mapi_setAutocommit(dbh, false) != MOK || mapi_error(dbh)))
70 0 : die(dbh,NULL);
71 :
72 1000 : if (lang==1)
73 1000 : snprintf(buf, 40, "select %d;", i);
74 : else
75 0 : snprintf(buf, 40, "io.print(%d);", i);
76 1000 : if ((hdl = mapi_query(dbh, buf)) == NULL || mapi_error(dbh))
77 0 : die(dbh, hdl);
78 6000 : while ((line = mapi_fetch_line(hdl))) {
79 : // printf("%s \n", line);
80 : (void) line;
81 : }
82 1000 : if (mapi_error(dbh))
83 0 : die(dbh, hdl);
84 1000 : if (mapi_close_handle(hdl) != MOK)
85 0 : die(dbh, hdl);
86 1000 : mapi_disconnect(dbh);
87 : /* printf("close connection %d\n", i); */
88 : }
89 :
90 1 : mapi_destroy(dbh);
91 :
92 1 : return 0;
93 : }
|