fix
[libdbw.git] / test / test_mysql.c
blob658242cb93e41e4ad48ccb177ab8fc87846712da
1 #include <stdio.h>
2 #include "mysql/mysql.h"
4 #define QUERY "select al.`Title` from `Artist` ar, `Album` al where ar.`ArtistId` = al.`ArtistId` and ar.`Name` = ?"
6 static void maria_001 (myconn_t *conn, char *name) {
7 myfld_t fld_name = MARIA_DEF_VARCHAR(name, strlen(name));
8 printf("-= %s =-\n", name);
9 myres_t *res = maria_exec(conn, CONST_STR_LEN(QUERY), &fld_name, NULL);
10 if (0 == res->status) {
11 myfld_t fld_title;
12 while (maria_fetch(res)) {
13 maria_get_varchar(res, 0, &fld_title);
14 printf("%s\n", fld_title.data.s.ptr);
16 } else
17 printf("%s\n", res->msg);
18 maria_res_close(res);
21 static void maria_002 (myconn_t *conn, char **names, int name_count) {
22 myres_t *res = maria_prepare(conn, CONST_STR_LEN(QUERY));
23 if (0 == res->status) {
24 for (int i = 0; i < name_count; ++i) {
25 myfld_t fld_name = MARIA_DEF_VARCHAR(names[i], strlen(names[i]));
26 printf("-= %s =-\n", names[i]);
27 if (0 == maria_pexec(res, &fld_name)) {
28 myfld_t fld_title;
29 while (maria_fetch(res)) {
30 maria_get_varchar(res, 0, &fld_title);
31 printf("%s\n", fld_title.data.s.ptr);
33 } else
34 printf("%s\n", res->msg);
36 } else
37 printf("%s\n", res->msg);
38 maria_res_close(res);
41 char *names [] = { "Jimi Hendrix", "Rush", "Creedence Clearwater Revival" };
42 static void maria_test () {
43 myconn_t *conn = maria_connect("127.0.0.1", "Chinook", "shura", NULL);
44 if (0 == conn->status) {
45 maria_001(conn, "Led Zeppelin");
46 maria_002(conn, names, sizeof(names)/sizeof(char*));
47 } else
48 printf("%s\n", conn->msg);
49 maria_disconnect(conn);
52 int main () {
53 maria_test();
54 return 0;