2
* Drizzle Client & Protocol Library
4
* Copyright (C) 2008 Eric Day (eday@oddments.org)
7
* Use and distribution licensed under the BSD license. See
8
* the COPYING file in this directory for full text.
16
#include <libdrizzle/drizzle_client.h>
18
int main(int argc, char *argv[])
21
const char *db= "INFORMATION_SCHEMA";
22
const char *host= NULL;
25
const char *query= "SELECT TABLE_SCHEMA,TABLE_NAME FROM TABLES";
26
drizzle_verbose_t verbose= DRIZZLE_VERBOSE_NEVER;
29
drizzle_result_st result;
34
while ((c = getopt(argc, argv, "d:h:mp:q:v")) != -1)
51
port= (in_port_t)atoi(optarg);
63
printf("usage: %s [-d <db>] [-h <host>] [-m] [-p <port>] [-q <query>] "
65
printf("\t-d <db> - Database to use for query\n");
66
printf("\t-h <host> - Host to listen on\n");
67
printf("\t-m - Use the MySQL protocol\n");
68
printf("\t-p <port> - Port to listen on\n");
69
printf("\t-q <query> - Query to run\n");
70
printf("\t-v - Increase verbosity level\n");
75
if (drizzle_create(&drizzle) == NULL)
77
printf("drizzle_create:NULL\n");
81
drizzle_set_verbose(&drizzle, verbose);
83
if (drizzle_con_create(&drizzle, &con) == NULL)
85
printf("drizzle_con_create:NULL\n");
90
drizzle_con_add_options(&con, DRIZZLE_CON_MYSQL);
92
drizzle_con_set_tcp(&con, host, port);
93
drizzle_con_set_db(&con, db);
95
(void)drizzle_query_str(&con, &result, query, &ret);
96
if (ret != DRIZZLE_RETURN_OK)
98
printf("drizzle_query:%s\n", drizzle_con_error(&con));
102
ret= drizzle_result_buffer(&result);
103
if (ret != DRIZZLE_RETURN_OK)
105
printf("drizzle_result_buffer:%s\n", drizzle_con_error(&con));
109
while ((row= (char **)drizzle_row_next(&result)) != NULL)
111
for (x= 0; x < drizzle_result_column_count(&result); x++)
112
printf("%s%s", x == 0 ? "" : ":", row[x] == NULL ? "NULL" : row[x]);
116
drizzle_result_free(&result);
117
drizzle_con_free(&con);
118
drizzle_free(&drizzle);