40
39
#include <getopt.h>
41
#include <libdrizzle/drizzle_client.h>
41
#include <libdrizzle/libdrizzle.hpp>
43
43
#include <unistd.h>
45
47
int main(int argc, char *argv[])
47
49
const char* db= "information_schema";
48
50
const char* host= NULL;
51
const char* user= NULL;
52
const char* password= NULL;
51
55
const char* query= "select table_schema, table_name from tables";
52
56
drizzle_verbose_t verbose= DRIZZLE_VERBOSE_NEVER;
54
for (int c; (c = getopt(argc, argv, "d:h:mp:q:v")) != -1; )
58
for (int c; (c = getopt(argc, argv, "d:h:mp:u:P:q:v")) != -1; )
81
case DRIZZLE_VERBOSE_NEVER:
82
verbose= DRIZZLE_VERBOSE_FATAL;
84
case DRIZZLE_VERBOSE_FATAL:
85
verbose= DRIZZLE_VERBOSE_ERROR;
87
case DRIZZLE_VERBOSE_ERROR:
88
verbose= DRIZZLE_VERBOSE_INFO;
90
case DRIZZLE_VERBOSE_INFO:
91
verbose= DRIZZLE_VERBOSE_DEBUG;
93
case DRIZZLE_VERBOSE_DEBUG:
94
verbose= DRIZZLE_VERBOSE_CRAZY;
96
case DRIZZLE_VERBOSE_CRAZY:
97
case DRIZZLE_VERBOSE_MAX:
91
if (verbose < DRIZZLE_VERBOSE_MAX)
92
verbose= static_cast<drizzle_verbose_t>(verbose + 1);
103
printf("usage: %s [-d <db>] [-h <host>] [-m] [-p <port>] [-q <query>] "
105
printf("\t-d <db> - Database to use for query\n");
106
printf("\t-h <host> - Host to listen on\n");
107
printf("\t-m - Use the MySQL protocol\n");
108
printf("\t-p <port> - Port to listen on\n");
109
printf("\t-q <query> - Query to run\n");
110
printf("\t-v - Increase verbosity level\n");
97
"usage: " << argv[0] << " [-d <db>] [-h <host>] [-m] [-p <port>] [-q <query>] [-v]\n"
98
"\t-d <db> - Database to use for query\n"
99
"\t-h <host> - Host to connect to\n"
100
"\t-m - Use the MySQL protocol\n"
101
"\t-p <port> - Port to connect to\n"
102
"\t-u <user> - User\n"
103
"\t-P <pass> - Password\n"
104
"\t-q <query> - Query to run\n"
105
"\t-v - Increase verbosity level\n";
116
if (drizzle_create(&drizzle) == NULL)
118
printf("drizzle_create:NULL\n");
122
drizzle_set_verbose(&drizzle, verbose);
124
drizzle_con_st* con= new drizzle_con_st;
125
if (drizzle_con_create(&drizzle, con) == NULL)
127
printf("drizzle_con_create:NULL\n");
110
drizzle::drizzle_c drizzle;
111
drizzle_set_verbose(&drizzle.b_, verbose);
112
drizzle::connection_c* con= new drizzle::connection_c(drizzle);
132
drizzle_con_add_options(con, DRIZZLE_CON_MYSQL);
134
drizzle_con_set_tcp(con, host, port);
135
drizzle_con_set_db(con, db);
137
drizzle_result_st result;
138
drizzle_return_t ret;
139
(void)drizzle_query_str(con, &result, query, &ret);
140
if (ret != DRIZZLE_RETURN_OK)
142
printf("drizzle_query:%s\n", drizzle_con_error(con));
146
ret= drizzle_result_buffer(&result);
147
if (ret != DRIZZLE_RETURN_OK)
149
printf("drizzle_result_buffer:%s\n", drizzle_con_error(con));
153
while (drizzle_row_t row= drizzle_row_next(&result))
155
for (int x= 0; x < drizzle_result_column_count(&result); x++)
156
printf("%s%s", x == 0 ? "" : ":", row[x] == NULL ? "NULL" : row[x]);
160
drizzle_result_free(&result);
161
drizzle_con_free(con);
162
drizzle_free(&drizzle);
114
drizzle_con_add_options(&con->b_, DRIZZLE_CON_MYSQL);
115
con->set_tcp(host, port);
116
con->set_auth(user, password);
118
drizzle::result_c result;
119
if (con->query(result, query))
121
cerr << "query: " << con->error() << endl;
124
while (drizzle_row_t row= result.row_next())
126
for (int x= 0; x < result.column_count(); x++)
130
cout << (row[x] ? row[x] : "NULL");