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 - 2019 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 | #ifdef _MSC_VER |
20 | #define snprintf _snprintf |
21 | #endif |
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 | main(int argc, char **argv) |
35 | { |
36 | Mapi dbh; |
37 | MapiHdl hdl = NULL; |
38 | int i, port, n = 20000; |
39 | char buf[40]; |
40 | int lang = 1; |
41 | char *l = "sql" ; |
42 | |
43 | /* char *line; */ |
44 | |
45 | if (argc != 2 && argc != 3) { |
46 | printf("usage:smack00 <port> [<language>]\n" ); |
47 | exit(-1); |
48 | } |
49 | if (argc == 3) { |
50 | l = argv[2]; |
51 | if (strcmp(argv[2], "sql" ) == 0) |
52 | lang = 1; |
53 | else if (strcmp(argv[2], "mal" ) == 0) |
54 | lang = 3; |
55 | } |
56 | |
57 | port = atol(argv[1]); |
58 | dbh = mapi_connect("localhost" , port, "monetdb" , "monetdb" , l, NULL); |
59 | if (dbh == NULL || mapi_error(dbh)) |
60 | die(dbh, hdl); |
61 | |
62 | /* switch of autocommit */ |
63 | if (lang==1 && (mapi_setAutocommit(dbh, false) != MOK || mapi_error(dbh))) |
64 | die(dbh,NULL); |
65 | |
66 | for (i = 0; i < n; i++) { |
67 | if (lang==1) |
68 | snprintf(buf, 40, "select %d;" , i); |
69 | else |
70 | snprintf(buf, 40, "io.print(%d);" , i); |
71 | if ((hdl = mapi_query(dbh, buf)) == NULL || mapi_error(dbh)) |
72 | die(dbh, hdl); |
73 | while ( (/*line= */ mapi_fetch_line(hdl)) != NULL) { |
74 | /*printf("%s \n", line); */ |
75 | } |
76 | if (mapi_error(dbh)) |
77 | die(dbh, hdl); |
78 | if (mapi_close_handle(hdl) != MOK) |
79 | die(dbh, hdl); |
80 | } |
81 | mapi_destroy(dbh); |
82 | |
83 | return 0; |
84 | } |
85 | |