~drizzle-trunk/libdrizzle/jenkins-Libdrizzle-29

« back to all changes in this revision

Viewing changes to tests/unit/column.c

  • Committer: Continuous Integration
  • Date: 2012-12-27 22:20:37 UTC
  • mfrom: (62.2.4 5.1-tests)
  • Revision ID: ci@drizzle.org-20121227222037-7ppxx42d00f6h58j
Merge lp:~linuxjedi/libdrizzle/5.1-tests Build: jenkins-Libdrizzle-10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab: 
 
2
 *
 
3
 *  Drizzle Client & Protocol Library
 
4
 *
 
5
 * Copyright (C) 2012 Andrew Hutchings (andrew@linuxjedi.co.uk)
 
6
 * All rights reserved.
 
7
 *
 
8
 * Redistribution and use in source and binary forms, with or without
 
9
 * modification, are permitted provided that the following conditions are
 
10
 * met:
 
11
 *
 
12
 *     * Redistributions of source code must retain the above copyright
 
13
 * notice, this list of conditions and the following disclaimer.
 
14
 *
 
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
 
18
 * distribution.
 
19
 *
 
20
 *     * The names of its contributors may not be used to endorse or
 
21
 * promote products derived from this software without specific prior
 
22
 * written permission.
 
23
 *
 
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.
 
35
 *
 
36
 */
 
37
 
 
38
#include <libdrizzle-5.1/libdrizzle.h>
 
39
#include <stdio.h>
 
40
#include <string.h>
 
41
#include <stdlib.h>
 
42
 
 
43
#ifndef EXIT_SKIP
 
44
# define EXIT_SKIP 77
 
45
#endif
 
46
 
 
47
int main(int argc, char *argv[])
 
48
{
 
49
  (void) argc;
 
50
  (void) argv;
 
51
  drizzle_st *con;
 
52
  drizzle_return_t ret;
 
53
  drizzle_result_st *result;
 
54
  drizzle_row_t row;
 
55
  int num_fields;
 
56
 
 
57
  con = drizzle_create_tcp("localhost", 3306, "root", "", "libdrizzle", 0);
 
58
  if (con == NULL)
 
59
  {
 
60
    printf("Drizzle connection object creation error\n");
 
61
    return EXIT_FAILURE;
 
62
  }
 
63
  ret = drizzle_connect(con);
 
64
  if (ret != DRIZZLE_RETURN_OK)
 
65
  {
 
66
    printf("Drizzle connection failure\n");
 
67
    return EXIT_SKIP;
 
68
  }
 
69
 
 
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)
 
72
  {
 
73
    printf("Create table failure\n");
 
74
    return EXIT_FAILURE;
 
75
  }
 
76
 
 
77
  drizzle_query_str(con, "insert into libdrizzle.t1 (b) values ('this'),('is'),('war')", &ret);
 
78
  if (ret != DRIZZLE_RETURN_OK)
 
79
  {
 
80
    printf("Insert failure\n");
 
81
    return EXIT_FAILURE;
 
82
  }
 
83
 
 
84
  result= drizzle_query_str(con, "select * from libdrizzle.t1", &ret);
 
85
  if (ret != DRIZZLE_RETURN_OK)
 
86
  {
 
87
    printf("Select failure\n");
 
88
    return EXIT_FAILURE;
 
89
  }
 
90
  drizzle_result_buffer(result);
 
91
  num_fields= drizzle_result_column_count(result);
 
92
 
 
93
  if (num_fields != 3)
 
94
  {
 
95
    printf("Retrieved bad number of fields\n");
 
96
    return EXIT_FAILURE;
 
97
  }
 
98
  int i= 0;
 
99
  int j= 0;
 
100
  char buf[10];
 
101
  drizzle_column_st *column;
 
102
  while ((row = drizzle_row_next(result)))
 
103
  {
 
104
    drizzle_column_seek(result, 0);
 
105
    j= 0;
 
106
    i++;
 
107
    snprintf(buf, 10, "%d", i);
 
108
    if (strcmp(row[0], buf) != 0)
 
109
    {
 
110
      printf("Retrieved bad row value\n");
 
111
      return EXIT_FAILURE;
 
112
    }
 
113
    while ((column= drizzle_column_next(result)))
 
114
    {
 
115
      j++;
 
116
      if (strcmp(drizzle_column_db(column), "libdrizzle") != 0)
 
117
      {
 
118
        printf("Column has bad DB name\n");
 
119
        return EXIT_FAILURE;
 
120
      }
 
121
      if (strcmp(drizzle_column_table(column), "t1") != 0)
 
122
      {
 
123
        printf("Column had bad table name\n");
 
124
        return EXIT_FAILURE;
 
125
      }
 
126
      if ((j == 2) && (drizzle_column_max_size(column) != 255))
 
127
      {
 
128
        printf("Column max size wrong %lu != 255\n", drizzle_column_max_size(column));
 
129
        return EXIT_FAILURE;
 
130
      }
 
131
      if ((j == 2) && (drizzle_column_charset(column) != DRIZZLE_CHARSET_LATIN1_SWEDISH_CI))
 
132
      {
 
133
        printf("Column type wrong, %d != %d\n", drizzle_column_charset(column), DRIZZLE_CHARSET_UTF8_BIN);
 
134
        return EXIT_FAILURE;
 
135
      }
 
136
      if ((j == 3) && (drizzle_column_type(column) != DRIZZLE_COLUMN_TYPE_TIMESTAMP))
 
137
      {
 
138
        printf("Column type wrong\n");
 
139
        return EXIT_FAILURE;
 
140
      }
 
141
    }
 
142
    if (j != 3)
 
143
    {
 
144
      printf("Wrong column count\n");
 
145
      return EXIT_FAILURE;
 
146
    }
 
147
  }
 
148
  /* Should have had 3 rows */
 
149
  if (i != 3)
 
150
  {
 
151
    printf("Retrieved bad number of rows\n");
 
152
    return EXIT_FAILURE;
 
153
  }
 
154
 
 
155
  drizzle_result_free(result);
 
156
 
 
157
  drizzle_query_str(con, "drop table libdrizzle.t1", &ret);
 
158
  if (ret != DRIZZLE_RETURN_OK)
 
159
  {
 
160
    printf("Drop table failure\n");
 
161
    return EXIT_FAILURE;
 
162
  }
 
163
 
 
164
 
 
165
  drizzle_quit(con);
 
166
  return EXIT_SUCCESS;
 
167
}