Exemple #1
0
int
main(int argc, char **argv)
{
	Mapi dbh;
	MapiHdl hdl = NULL;
	int i, port, n = 20000;
	char buf[40];
	int lang = 1;
	char *l = "sql";

	/* char *line; */

	if (argc != 2 && argc != 3) {
		printf("usage:smack00 <port> [<language>]\n");
		exit(-1);
	}
	if (argc == 3) {
		l = argv[2];
		if (strcmp(argv[2], "sql") == 0) 
			lang = 1;
		else if (strcmp(argv[2], "mal") == 0)
			lang = 3;
	}

	port = atol(argv[1]);
	dbh = mapi_connect("localhost", port, "monetdb", "monetdb", l, NULL);
	if (dbh == NULL || mapi_error(dbh))
		die(dbh, hdl);

	/* switch of autocommit */
	if (lang==1 && (mapi_setAutocommit(dbh, 0) != MOK || mapi_error(dbh)))
		die(dbh,NULL);

	for (i = 0; i < n; i++) {
		if (lang==1)
			snprintf(buf, 40, "select %d;", i);
		else
			snprintf(buf, 40, "io.print(%d);", i);
		if ((hdl = mapi_query(dbh, buf)) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		while ( (/*line= */ mapi_fetch_line(hdl)) != NULL) {
			/*printf("%s \n", line); */
		}
		if (mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
	}
	mapi_destroy(dbh);

	return 0;
}
Exemple #2
0
int
main(int argc, char **argv)
{
	Mapi dbh;
	MapiHdl hdl = NULL;
	mapi_int64 rows;

	if (argc != 4) {
		printf("usage:%s <host> <port> <language>\n", argv[0]);
		exit(-1);
	}

	dbh = mapi_connect(argv[1], atoi(argv[2]), "monetdb", "monetdb", argv[3], NULL);
	if (dbh == NULL || mapi_error(dbh))
		die(dbh, hdl);

	mapi_cache_limit(dbh, 2);
	/* mapi_trace_log(dbh, "/tmp/mapilog"); */
	/* mapi_trace(dbh, 1); */
	if (strcmp(argv[3], "sql") == 0) {
		/* switch of autocommit */
		if (mapi_setAutocommit(dbh, 0) != MOK || mapi_error(dbh))
			die(dbh,NULL);
		if ((hdl = mapi_query(dbh, "create table emp(name varchar(20), age int)")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "insert into emp values('John', 23)")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "insert into emp values('Mary', 22)")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "select * from emp")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		rows = mapi_fetch_all_rows(hdl);
		if (mapi_error(dbh))
			die(dbh, hdl);
		printf("rows received " LLFMT "\n", rows);
		while (mapi_fetch_row(hdl)) {
			char *nme = mapi_fetch_field(hdl, 0);
			char *age = mapi_fetch_field(hdl, 1);

			printf("%s is %s\n", nme, age);
		}
	} else if (strcmp(argv[3], "mal") == 0) {
		if ((hdl = mapi_query(dbh, "emp := bat.new(:oid,:str);")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "age := bat.new(:oid,:int);")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "bat.append(emp, \"John\");")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "bat.append(age, 23);")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "bat.append(emp, \"Mary\");")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "bat.append(age, 22);")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "io.print(emp,age);")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		rows = mapi_fetch_all_rows(hdl);
		if (mapi_error(dbh))
			die(dbh, hdl);
		printf("rows received " LLFMT "\n", rows);
		while (mapi_fetch_row(hdl)) {
			char *nme = mapi_fetch_field(hdl, 1);
			char *age = mapi_fetch_field(hdl, 2);

			printf("%s is %s\n", nme, age);
		}
	} else {
		fprintf(stderr, "%s: unknown language, only mal and sql supported\n", argv[0]);
		exit(1);
	}

	if (mapi_error(dbh))
		die(dbh, hdl);
	/* mapi_stat(dbh);
	   printf("mapi_ping %d\n",mapi_ping(dbh)); */
	if (mapi_close_handle(hdl) != MOK)
		die(dbh, hdl);
	mapi_destroy(dbh);

	return 0;
}
Exemple #3
0
SQLRETURN
MNDBFetch(ODBCStmt *stmt, SQLUSMALLINT *RowStatusArray)
{
	ODBCDesc *ard, *ird;
	ODBCDescRec *rec;
	int i;
	SQLULEN row;
	SQLLEN offset;

	/* stmt->startRow is the (0 based) index of the first row we
	 * stmt->need to fetch */

	ard = stmt->ApplRowDescr;
	ird = stmt->ImplRowDescr;

	stmt->retrieved = 0;
	stmt->currentCol = 0;

	stmt->rowSetSize = 0;
	stmt->currentRow = stmt->startRow + 1;
	if (mapi_seek_row(stmt->hdl, stmt->startRow, MAPI_SEEK_SET) != MOK) {
		/* Row value out of range */
		addStmtError(stmt, "HY107", mapi_error_str(stmt->Dbc->mid), 0);
		return SQL_ERROR;
	}

	stmt->State = FETCHED;

	if (stmt->retrieveData == SQL_RD_OFF) {
		/* don't really retrieve the data, just do as if,
		   updating the SQL_DESC_ARRAY_STATUS_PTR */
		stmt->rowSetSize = ard->sql_desc_array_size;

		if (stmt->startRow + stmt->rowSetSize > (SQLLEN) stmt->rowcount)
			stmt->rowSetSize = stmt->rowcount - stmt->startRow;

		if (stmt->rowSetSize <= 0) {
			stmt->rowSetSize = 0;
			return SQL_NO_DATA;
		}
		if (RowStatusArray) {
			for (row = 0; (SQLLEN) row < stmt->rowSetSize; row++) {
				WriteValue(RowStatusArray, SQL_ROW_SUCCESS);
				RowStatusArray++;
			}
			for (; row < ard->sql_desc_array_size; row++) {
				WriteValue(RowStatusArray, SQL_ROW_NOROW);
				RowStatusArray++;
			}
		}
		return SQL_SUCCESS;
	}

	if (ard->sql_desc_bind_offset_ptr)
		offset = *ard->sql_desc_bind_offset_ptr;
	else
		offset = 0;
	for (row = 0; row < ard->sql_desc_array_size; row++) {
		if (mapi_fetch_row(stmt->hdl) == 0) {
			switch (mapi_error(stmt->Dbc->mid)) {
			case MOK:
				if (row == 0)
					return SQL_NO_DATA;
				break;
			case MTIMEOUT:
				if (RowStatusArray)
					WriteValue(RowStatusArray, SQL_ROW_ERROR);
				/* Timeout expired / Communication
				 * link failure */
				addStmtError(stmt, stmt->Dbc->sql_attr_connection_timeout ? "HYT00" : "08S01", mapi_error_str(stmt->Dbc->mid), 0);
				return SQL_ERROR;
			default:
				if (RowStatusArray)
					WriteValue(RowStatusArray, SQL_ROW_ERROR);
				/* General error */
				addStmtError(stmt, "HY000", mapi_error_str(stmt->Dbc->mid), 0);
				return SQL_ERROR;
			}
			break;
		}
		if (RowStatusArray)
			WriteValue(RowStatusArray, SQL_ROW_SUCCESS);

		stmt->rowSetSize++;

		for (i = 1; i <= ird->sql_desc_count; i++)
			ird->descRec[i].already_returned = 0;

		for (i = 1; i <= ard->sql_desc_count; i++) {
			rec = &ard->descRec[i];
			if (rec->sql_desc_data_ptr == NULL)
				continue;
			stmt->retrieved = 0;
			if (ODBCFetch(stmt, i,
				      rec->sql_desc_concise_type,
				      rec->sql_desc_data_ptr,
				      rec->sql_desc_octet_length,
				      rec->sql_desc_octet_length_ptr,
				      rec->sql_desc_indicator_ptr,
				      rec->sql_desc_precision,
				      rec->sql_desc_scale,
				      rec->sql_desc_datetime_interval_precision,
				      offset, row) == SQL_ERROR) {
				if (RowStatusArray)
					WriteValue(RowStatusArray, SQL_ROW_SUCCESS_WITH_INFO);
			}
		}
		if (RowStatusArray)
			RowStatusArray++;
	}
	if (ird->sql_desc_rows_processed_ptr)
		*ird->sql_desc_rows_processed_ptr = (SQLULEN) stmt->rowSetSize;

	if (RowStatusArray)
		while (row++ < ard->sql_desc_array_size) {
			WriteValue(RowStatusArray, SQL_ROW_NOROW);
			RowStatusArray++;
		}

	return stmt->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
}
Exemple #4
0
CAMLprim value mapi_error_stub(value conn)
{
    MapiMsg msg = mapi_error((Mapi) conn);
    return Val_int(index_of_msg(msg));
}
Exemple #5
0
int
main(int argc, char **argv)
{
	int port = 0;
	char *user = NULL;
	char *passwd = NULL;
	char *host = NULL;
	char *dbname = NULL;
	int trace = 0;
	int describe = 0;
	int functions = 0;
	int useinserts = 0;
	int c;
	Mapi mid;
	int quiet = 0;
	stream *out;
	char user_set_as_flag = 0;
	char *table = NULL;
	static struct option long_options[] = {
		{"host", 1, 0, 'h'},
		{"port", 1, 0, 'p'},
		{"database", 1, 0, 'd'},
		{"describe", 0, 0, 'D'},
		{"functions", 0, 0, 'f'},
		{"table", 1, 0, 't'},
		{"inserts", 0, 0, 'N'},
		{"Xdebug", 0, 0, 'X'},
		{"user", 1, 0, 'u'},
		{"quiet", 0, 0, 'q'},
		{"help", 0, 0, '?'},
		{0, 0, 0, 0}
	};

	parse_dotmonetdb(&user, &passwd, NULL, NULL, NULL, NULL);

	while ((c = getopt_long(argc, argv, "h:p:d:Dft:NXu:q?", long_options, NULL)) != -1) {
		switch (c) {
		case 'u':
			if (user)
				free(user);
			user = strdup(optarg);
			user_set_as_flag = 1;
			break;
		case 'h':
			host = optarg;
			break;
		case 'p':
			assert(optarg != NULL);
			port = atoi(optarg);
			break;
		case 'd':
			dbname = optarg;
			break;
		case 'D':
			describe = 1;
			break;
		case 'N':
			useinserts = 1;
			break;
		case 'f':
			if (table)
				usage(argv[0], -1);
			functions = 1;
			break;
		case 't':
			if (table || functions)
				usage(argv[0], -1);
			table = optarg;
			break;
		case 'q':
			quiet = 1;
			break;
		case 'X':
			trace = MAPI_TRACE;
			break;
		case '?':
			/* a bit of a hack: look at the option that the
			   current `c' is based on and see if we recognize
			   it: if -? or --help, exit with 0, else with -1 */
			usage(argv[0], strcmp(argv[optind - 1], "-?") == 0 || strcmp(argv[optind - 1], "--help") == 0 ? 0 : -1);
		default:
			usage(argv[0], -1);
		}
	}

	if (optind == argc - 1)
		dbname = argv[optind];
	else if (optind != argc)
		usage(argv[0], -1);

	/* when config file would provide defaults */
	if (user_set_as_flag)
		passwd = NULL;

	if (user == NULL)
		user = simple_prompt("user", BUFSIZ, 1, prompt_getlogin());
	if (passwd == NULL)
		passwd = simple_prompt("password", BUFSIZ, 0, NULL);

	mid = mapi_connect(host, port, user, passwd, "sql", dbname);
	if (user)
		free(user);
	if (passwd)
		free(passwd);
	if (mid == NULL) {
		fprintf(stderr, "failed to allocate Mapi structure\n");
		exit(2);
	}
	if (mapi_error(mid)) {
		mapi_explain(mid, stderr);
		exit(2);
	}
	if (!quiet) {
		char *motd = mapi_get_motd(mid);

		if (motd)
			fprintf(stderr, "%s", motd);
	}
	mapi_trace(mid, trace);
	mapi_cache_limit(mid, 10000);

	out = file_wastream(stdout, "stdout");
	if (out == NULL) {
		fprintf(stderr, "failed to allocate stream\n");
		exit(2);
	}
	if (!quiet) {
		char buf[27];
		time_t t = time(0);
		char *p;

#ifdef HAVE_CTIME_R3
		ctime_r(&t, buf, sizeof(buf));
#else
#ifdef HAVE_CTIME_R
		ctime_r(&t, buf);
#else
		strncpy(buf, ctime(&t), sizeof(buf));
#endif
#endif
		if ((p = strrchr(buf, '\n')) != NULL)
			*p = 0;
		mnstr_printf(out, "-- msqldump %s %s%s %s\n",
			     describe ? "describe" : "dump",
			     functions ? "functions" : table ? "table " : "database",
			     table ? table : "", buf);
		dump_version(mid, out, "--");
	}
	if (functions)
		c = dump_functions(mid, out, NULL, NULL);
	else if (table)
		c = dump_table(mid, NULL, table, out, describe, 1, useinserts);
	else
		c = dump_database(mid, out, describe, useinserts);
	mnstr_flush(out);

	mapi_destroy(mid);
	if (mnstr_errnr(out)) {
		fprintf(stderr, "%s: %s", argv[0], mnstr_error(out));
		return 1;
	}

	mnstr_destroy(out);
	return c;
}
Exemple #6
0
int
main(int argc, char **argv)
{
	ssize_t  n;
	size_t len, buflen;
	char *host = NULL;
	int portnr = 0;
	char *uri = NULL;
	char *user = NULL;
	char *password = NULL;
	char buf[BUFSIZ], *buffer, *e, *response;
	int done = 0;
	EventRecord event;

	static struct option long_options[15] = {
		{ "dbname", 1, 0, 'd' },
		{ "user", 1, 0, 'u' },
		{ "port", 1, 0, 'p' },
		{ "password", 1, 0, 'P' },
		{ "host", 1, 0, 'h' },
		{ "help", 0, 0, '?' },
		{ "output", 1, 0, 'o' },
		{ "queries", 1, 0, 'q' },
		{ "debug", 0, 0, 'D' },
		{ 0, 0, 0, 0 }
	};

	/* parse config file first, command line options override */
	parse_dotmonetdb(&user, &password, &dbname, NULL, NULL, NULL, NULL);

	while (1) {
		int option_index = 0;
		int c = getopt_long(argc, argv, "d:u:p:P:h:?:o:q:D",
					long_options, &option_index);
		if (c == -1)
			break;
		switch (c) {
		case 'D':
			debug = 1;
			break;
		case 'd':
			if (dbname)
				free(dbname);
			dbname = strdup(optarg);
			break;
		case 'u':
			if (user)
				free(user);
			user = strdup(optarg);
			/* force password prompt */
			if (password)
				free(password);
			password = NULL;
			break;
		case 'P':
			if (password)
				free(password);
			password = strdup(optarg);
			break;
		case 'p':
			if (optarg)
				portnr = atoi(optarg);
			break;
		case 'q':
			if (optarg)
				querypool = atoi(optarg) > 0? atoi(optarg):1;
			break;
		case 'h':
			host = optarg;
			break;
		case '?':
			usageTachograph();
			/* a bit of a hack: look at the option that the
			   current `c' is based on and see if we recognize
			   it: if -? or --help, exit with 0, else with -1 */
			exit(strcmp(argv[optind - 1], "-?") == 0 || strcmp(argv[optind - 1], "--help") == 0 ? 0 : -1);
		default:
				usageTachograph();
			exit(-1);
		}
	}

	if( dbname == NULL){
		usageTachograph();
		exit(-1);
	}

	if (dbname != NULL && strncmp(dbname, "mapi:monetdb://", 15) == 0) {
		uri = dbname;
		dbname = NULL;
	}

#ifdef SIGPIPE
	signal(SIGPIPE, stopListening);
#endif
#ifdef SIGHUP
	signal(SIGHUP, stopListening);
#endif
#ifdef SIGQUIT
	signal(SIGQUIT, stopListening);
#endif
	signal(SIGINT, stopListening);
	signal(SIGTERM, stopListening);
	close(0);

	if (user == NULL)
		user = simple_prompt("user", BUFSIZ, 1, prompt_getlogin());
	if (password == NULL)
		password = simple_prompt("password", BUFSIZ, 0, NULL);

	/* our hostname, how remote servers have to contact us */
	gethostname(hostname, sizeof(hostname));

	/* set up the profiler */
	if (uri)
		dbh = mapi_mapiuri(uri, user, password, "mal");
	else
		dbh = mapi_mapi(host, portnr, user, password, "mal", dbname);
	if (dbh == NULL || mapi_error(dbh))
		die(dbh, hdl);
	mapi_reconnect(dbh);
	if (mapi_error(dbh))
		die(dbh, hdl);
	host = strdup(mapi_get_host(dbh));
	if(debug)
		fprintf(stderr,"-- connection with server %s\n", uri ? uri : host);

	snprintf(buf,BUFSIZ-1,"profiler.setheartbeat(0);");
	if( debug)
		fprintf(stderr,"-- %s\n",buf);
	doQ(buf);

	snprintf(buf, BUFSIZ, " profiler.openstream(0);");
	if( debug)
		fprintf(stderr,"-- %s\n",buf);
	doQ(buf);

	len = 0;
	buflen = BUFSIZ;
	buffer = (char *) malloc(buflen);
	if( buffer == NULL){
		fprintf(stderr,"Could not create input buffer\n");
		exit(-1);
	}
	conn = mapi_get_from(dbh);
	while ((n = mnstr_read(conn, buffer + len, 1, buflen - len-1)) >= 0) {
		if (n == 0 &&
		    (n = mnstr_read(conn, buffer + len, 1, buflen - len-1)) <= 0)
			break;
		buffer[len + n] = 0;
		response = buffer;
		while ((e = strchr(response, '\n')) != NULL) {
			*e = 0;
			if(debug)
				printf("%s\n", response);
			done= keyvalueparser(response, &event);
			if( done == 1){
				update(&event);
			} else if( done == 0){
				if (debug  )
					fprintf(stderr, "PARSE %d:%s\n", done, response);
			}
			response = e + 1;
		}
		/* handle the case that the line is too long to
		 * fit in the buffer */
		if( response == buffer){
			char *new =  (char *) realloc(buffer, buflen + BUFSIZ);
			if( new == NULL){
				fprintf(stderr,"Could not extend input buffer\n");
				exit(-1);
			}
			buffer = new;
			buflen += BUFSIZ;
			len += n;
		}
		/* handle the case the buffer contains more than one
		 * line, and the last line is not completely read yet.
		 * Copy the first part of the incomplete line to the
		 * beginning of the buffer */
		else if (*response) {
Exemple #7
0
int
main(int argc, char **argv)
{
	/* a parameter binding test */
	char *nme = 0;
	int age = 0;
	char *parm[] = { "peter", 0 };
	char *parm2[] = { "25", 0 };
	char *parm3[] = { "peter", "25", 0 };
	Mapi dbh= NULL;
	MapiHdl hdl = NULL;

	if (argc != 4) {
		printf("usage:%s <host> <port> <language>\n", argv[0]);
		exit(-1);
	}

	dbh = mapi_connect(argv[1], atoi(argv[2]), "monetdb", "monetdb", argv[3], NULL);
	if (dbh == NULL || mapi_error(dbh))
		die(dbh, hdl);

	/* mapi_trace(dbh,1); */
	if (strcmp(argv[3], "sql") == 0) {
		/* switch of autocommit */
		if (mapi_setAutocommit(dbh, 0) != MOK || mapi_error(dbh))
			die(dbh,NULL);
		if ((hdl = mapi_query(dbh, "create table emp(name varchar(20), age int)")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query_array(dbh, "insert into emp values('?', ?)", parm3)) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "select * from emp")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_bind(hdl, 0, &nme))
			die(dbh, hdl);
		if (mapi_bind_var(hdl, 1, MAPI_INT, &age))
			die(dbh, hdl);
		while (mapi_fetch_row(hdl)) {
			printf("%s is %d\n", nme, age);
		}
	} else if (strcmp(argv[3], "mal") == 0) {
		if ((hdl = mapi_query(dbh, "emp := bat.new(:oid,:str);")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "age := bat.new(:oid,:int);")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query_array(dbh, "bat.append(emp,\"?\");", parm)) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if ((hdl = mapi_query_array(dbh, "bat.append(age,?);", parm2)) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "io.print(emp,age);")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_bind(hdl, 1, &nme))
			die(dbh, hdl);
		if (mapi_bind_var(hdl, 2, MAPI_INT, &age))
			die(dbh, hdl);
		while (mapi_fetch_row(hdl)) {
			printf("%s is %d\n", nme, age);
		}
	} else {
		fprintf(stderr, "%s: unknown language, only mal and sql supported\n", argv[0]);
		exit(1);
	}

	if (mapi_error(dbh))
		die(dbh, hdl);
	if (mapi_close_handle(hdl) != MOK)
		die(dbh, hdl);
	mapi_destroy(dbh);

	return 0;
}
Exemple #8
0
int
main(int argc, char **argv)
{
	Mapi dbh;
	MapiHdl hdl = NULL;
	mapi_int64 rows, i;
	char *parm[] = { "peter", 0 };
	char *parm2[] = { "25", 0 };
	int j;

	if (argc != 4) {
		printf("usage:%s <host> <port> <language>\n", argv[0]);
		exit(-1);
	}

	dbh = mapi_connect(argv[1], atoi(argv[2]), "monetdb", "monetdb", argv[3], NULL);
	if (dbh == NULL || mapi_error(dbh))
		die(dbh, hdl);

	/* mapi_trace(dbh, 1); */
	if (strcmp(argv[3], "sql") == 0) {
		/* switch of autocommit */
		if (mapi_setAutocommit(dbh, 0) != MOK || mapi_error(dbh))
			die(dbh,NULL);
		if ((hdl = mapi_query(dbh, "create table emp(name varchar(20), age int)")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "insert into emp values('John', 23)")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "insert into emp values('Mary', 22)")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "select * from emp")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
	} else if (strcmp(argv[3], "mal") == 0) {
		if ((hdl = mapi_query(dbh, "emp := bat.new(:oid,:str);")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "age := bat.new(:oid,:int);")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query_array(dbh, "bat.append(emp,\"?\");", parm)) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if ((hdl = mapi_query_array(dbh, "bat.append(age,?);", parm2)) == NULL || mapi_error(dbh))
			die(dbh, hdl);
		if (mapi_close_handle(hdl) != MOK)
			die(dbh, hdl);
		if ((hdl = mapi_query(dbh, "io.print(emp,age);")) == NULL || mapi_error(dbh))
			die(dbh, hdl);
	} else {
		fprintf(stderr, "%s: unknown language, only mal and sql supported\n", argv[0]);
		exit(1);
	}

	/* Retrieve all tuples in the client cache first */
	rows = mapi_fetch_all_rows(hdl);
	if (mapi_error(dbh))
		die(dbh, hdl);
	printf("rows received " LLFMT " with %d fields\n", rows, mapi_get_field_count(hdl));

	/* Interpret the cache as a two-dimensional array */
	for (i = 0; i < rows; i++) {
		if (mapi_seek_row(hdl, i, MAPI_SEEK_SET) || mapi_fetch_row(hdl) == 0)
			break;
		for (j = 0; j < mapi_get_field_count(hdl); j++) {
			printf("%s=%s ", mapi_get_name(hdl, j), mapi_fetch_field(hdl, j));
		}
		printf("\n");
	}
	if (mapi_error(dbh))
		die(dbh, hdl);
	if (mapi_close_handle(hdl) != MOK)
		die(dbh, hdl);
	mapi_destroy(dbh);

	return 0;
}