fix
[libdbw.git] / test / test_mdb.c
blob0fd6836cd144773103397cea86ceac5e0e618241
1 #include <stdio.h>
2 #include "monetdb/monetdb.h"
4 #define QUERY "select al.title from artist ar, album al where ar.artistId = al.artistId and ar.name = '?'"
6 static void mdb_001 (mdbconn_t *conn, char *name) {
7 printf("-= %s =-\n", name);
8 mdbres_t *res = mdb_exec(conn, QUERY, name, NULL);
9 if (0 == res->status) {
10 while (mdb_fetch(res))
11 printf("%s\n", mdb_get(res, 0));
12 } else
13 printf("%s\n", res->msg);
14 mdb_close(res);
17 static void mdb_002 (mdbconn_t *conn, char **names, int name_count) {
18 mdbres_t *res = mdb_prepare(conn, QUERY);
19 if (0 == res->status) {
20 for (int i = 0; i < name_count; ++i) {
21 printf("-= %s =-\n", names[i]);
22 if (0 == mdb_pexec(conn, res, names[i], NULL))
23 while (mdb_fetch(res))
24 printf("%s\n", mdb_get(res, 0));
26 } else
27 printf("%s\n", res->msg);
28 mdb_close(res);
31 char *names [] = { "Jimi Hendrix", "Rush", "Creedence Clearwater Revival" };
32 static void mdb_test () {
33 mdbconn_t *conn = mdb_connect("localhost", 50000, "chinook", "monetdb", "monetdb");
34 if (0 == conn->status) {
35 mdb_001(conn, "Led Zeppelin");
36 mdb_002(conn, names, sizeof(names)/sizeof(char*));
37 } else
38 printf("%s\n", conn->msg);
39 mdb_disconnect(conn);
42 int main () {
43 mdb_test();
44 return 0;