1
/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
* Drizzle Client & Protocol Library
5
* Copyright (C) 2012 Andrew Hutchings (andrew@linuxjedi.co.uk)
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions are
12
* * Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
15
* * Redistributions in binary form must reproduce the above
16
* copyright notice, this list of conditions and the following disclaimer
17
* in the documentation and/or other materials provided with the
20
* * The names of its contributors may not be used to endorse or
21
* promote products derived from this software without specific prior
24
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
#include <libdrizzle-5.1/libdrizzle.h>
47
int main(int argc, char *argv[])
53
drizzle_result_st *result;
57
con = drizzle_create_tcp("localhost", 3306, "root", "", "libdrizzle", 0);
60
printf("Drizzle connection object creation error\n");
63
ret = drizzle_connect(con);
64
if (ret != DRIZZLE_RETURN_OK)
66
printf("Drizzle connection failure\n");
70
drizzle_query_str(con, "create table libdrizzle.t1 (a int primary key auto_increment, b varchar(255), c timestamp default current_timestamp)", &ret);
71
if (ret != DRIZZLE_RETURN_OK)
73
printf("Create table failure\n");
77
drizzle_query_str(con, "insert into libdrizzle.t1 (b) values ('this'),('is'),('war')", &ret);
78
if (ret != DRIZZLE_RETURN_OK)
80
printf("Insert failure\n");
84
result= drizzle_query_str(con, "select * from libdrizzle.t1", &ret);
85
if (ret != DRIZZLE_RETURN_OK)
87
printf("Select failure\n");
90
drizzle_result_buffer(result);
91
num_fields= drizzle_result_column_count(result);
95
printf("Retrieved bad number of fields\n");
101
drizzle_column_st *column;
102
while ((row = drizzle_row_next(result)))
104
drizzle_column_seek(result, 0);
107
snprintf(buf, 10, "%d", i);
108
if (strcmp(row[0], buf) != 0)
110
printf("Retrieved bad row value\n");
113
while ((column= drizzle_column_next(result)))
116
if (strcmp(drizzle_column_db(column), "libdrizzle") != 0)
118
printf("Column has bad DB name\n");
121
if (strcmp(drizzle_column_table(column), "t1") != 0)
123
printf("Column had bad table name\n");
126
if ((j == 2) && (drizzle_column_max_size(column) != 255))
128
printf("Column max size wrong %lu != 255\n", drizzle_column_max_size(column));
131
if ((j == 2) && (drizzle_column_charset(column) != DRIZZLE_CHARSET_LATIN1_SWEDISH_CI))
133
printf("Column type wrong, %d != %d\n", drizzle_column_charset(column), DRIZZLE_CHARSET_UTF8_BIN);
136
if ((j == 3) && (drizzle_column_type(column) != DRIZZLE_COLUMN_TYPE_TIMESTAMP))
138
printf("Column type wrong\n");
144
printf("Wrong column count\n");
148
/* Should have had 3 rows */
151
printf("Retrieved bad number of rows\n");
155
drizzle_result_free(result);
157
drizzle_query_str(con, "drop table libdrizzle.t1", &ret);
158
if (ret != DRIZZLE_RETURN_OK)
160
printf("Drop table failure\n");