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
) {
12 while (maria_fetch(res
)) {
13 maria_get_varchar(res
, 0, &fld_title
);
14 printf("%s\n", fld_title
.data
.s
.ptr
);
17 printf("%s\n", res
->msg
);
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
)) {
29 while (maria_fetch(res
)) {
30 maria_get_varchar(res
, 0, &fld_title
);
31 printf("%s\n", fld_title
.data
.s
.ptr
);
34 printf("%s\n", res
->msg
);
37 printf("%s\n", res
->msg
);
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*));
48 printf("%s\n", conn
->msg
);
49 maria_disconnect(conn
);