1712.1.1
by Monty Taylor
Merged libdrizzle directly into tree. |
1 |
/*
|
2 |
* Drizzle Client & Protocol Library
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Eric Day (eday@oddments.org)
|
|
5 |
* All rights reserved.
|
|
6 |
*
|
|
7 |
* Use and distribution licensed under the BSD license. See
|
|
1799.2.4
by Monty Taylor
Made BSD files reference root BSD file. |
8 |
* the COPYING.BSD file in the root source directory for full text.
|
1712.1.1
by Monty Taylor
Merged libdrizzle directly into tree. |
9 |
*/
|
10 |
||
11 |
#include <stdio.h> |
|
12 |
#include <string.h> |
|
13 |
||
14 |
#include <libdrizzle/drizzle_client.h> |
|
15 |
||
16 |
#define SIMPLE_MULTI_COUNT 10
|
|
17 |
||
18 |
int main(int argc, char *argv[]) |
|
19 |
{
|
|
20 |
const char *query= "SELECT table_schema,table_name FROM tables"; |
|
21 |
drizzle_st drizzle; |
|
22 |
drizzle_con_st con[SIMPLE_MULTI_COUNT]; |
|
23 |
drizzle_result_st result[SIMPLE_MULTI_COUNT]; |
|
24 |
drizzle_query_st ql[SIMPLE_MULTI_COUNT]; |
|
25 |
drizzle_return_t ret; |
|
26 |
drizzle_row_t row; |
|
27 |
int x; |
|
28 |
||
29 |
if (drizzle_create(&drizzle) == NULL) |
|
30 |
{
|
|
31 |
printf("drizzle_create:NULL\n"); |
|
32 |
return 1; |
|
33 |
}
|
|
34 |
||
35 |
/* Create SIMPLE_MULTI_COUNT connections and initialize query list. */
|
|
36 |
for (x= 0; x < SIMPLE_MULTI_COUNT; x++) |
|
37 |
{
|
|
38 |
if (x == 0) |
|
39 |
{
|
|
40 |
if (drizzle_con_create(&drizzle, &(con[0])) == NULL) |
|
41 |
{
|
|
42 |
printf("drizzle_con_create:%s\n", drizzle_error(&drizzle)); |
|
43 |
return 1; |
|
44 |
}
|
|
45 |
||
46 |
if (argc == 2 && !strcmp(argv[1], "-m")) |
|
47 |
drizzle_con_add_options(&(con[0]), DRIZZLE_CON_MYSQL); |
|
48 |
else if (argc != 1) |
|
49 |
{
|
|
50 |
printf("usage: %s [-m]\n", argv[0]); |
|
51 |
return 1; |
|
52 |
}
|
|
53 |
||
54 |
drizzle_con_set_db(&(con[0]), "information_schema"); |
|
55 |
}
|
|
56 |
else
|
|
57 |
{
|
|
58 |
if (drizzle_con_clone(&drizzle, &(con[x]), &(con[0])) == NULL) |
|
59 |
{
|
|
60 |
printf("drizzle_con_clone:%s\n", drizzle_error(&drizzle)); |
|
61 |
return 1; |
|
62 |
}
|
|
63 |
}
|
|
64 |
||
65 |
if (drizzle_query_add(&drizzle, &(ql[x]), &(con[x]), &(result[x]), query, |
|
66 |
strlen(query), 0, NULL) == NULL) |
|
67 |
{
|
|
68 |
printf("drizzle_query_add:%s\n", drizzle_error(&drizzle)); |
|
69 |
return 1; |
|
70 |
}
|
|
71 |
}
|
|
72 |
||
73 |
ret= drizzle_query_run_all(&drizzle); |
|
74 |
if (ret != DRIZZLE_RETURN_OK) |
|
75 |
{
|
|
76 |
printf("drizzle_query_run_all:%s\n", drizzle_error(&drizzle)); |
|
77 |
return 1; |
|
78 |
}
|
|
79 |
||
80 |
for (x= 0; x < SIMPLE_MULTI_COUNT; x++) |
|
81 |
{
|
|
82 |
if (drizzle_result_error_code(&(result[x])) != 0) |
|
83 |
{
|
|
84 |
printf("%d:%s\n", drizzle_result_error_code(&(result[x])), |
|
85 |
drizzle_result_error(&(result[x]))); |
|
86 |
continue; |
|
87 |
}
|
|
88 |
||
89 |
while ((row= drizzle_row_next(&(result[x]))) != NULL) |
|
90 |
printf("%d %s:%s\n", x, row[0], row[1]); |
|
91 |
}
|
|
92 |
||
93 |
drizzle_free(&drizzle); |
|
94 |
||
95 |
return 0; |
|
96 |
}
|