~brianaker/libdrizzle/install-html-fix

« back to all changes in this revision

Viewing changes to tests/unit/column.c

  • Committer: Continuous Integration
  • Date: 2012-12-29 11:51:43 UTC
  • mfrom: (68.1.1 5.1-trunk)
  • Revision ID: ci@drizzle.org-20121229115143-b2w1xjx16neqxyu2
Merge lp:~brianaker/libdrizzle/yatl_lite_bugreport_fix Build: jenkins-Libdrizzle-17

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 *
36
36
 */
37
37
 
 
38
#include <yatl/lite.h>
 
39
 
38
40
#include <libdrizzle-5.1/libdrizzle.h>
39
41
#include <stdio.h>
40
42
#include <string.h>
41
43
#include <stdlib.h>
42
44
 
43
 
#ifndef EXIT_SKIP
44
 
# define EXIT_SKIP 77
45
 
#endif
46
 
 
47
45
int main(int argc, char *argv[])
48
46
{
49
47
  (void) argc;
50
48
  (void) argv;
51
 
  drizzle_st *con;
52
49
  drizzle_return_t ret;
53
50
  drizzle_result_st *result;
54
51
  drizzle_row_t row;
55
52
  int num_fields;
56
53
 
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
 
  }
 
54
  drizzle_st *con= drizzle_create_tcp("localhost", 3306, "root", "", "libdrizzle", 0);
 
55
  ASSERT_NOT_NULL_(con, "Drizzle connection object creation error");
 
56
 
63
57
  ret = drizzle_connect(con);
64
58
  if (ret != DRIZZLE_RETURN_OK)
65
59
  {
66
 
    printf("Drizzle connection failure\n");
67
60
    drizzle_quit(con);
68
 
    return EXIT_SKIP;
 
61
    SKIP_IF_(ret != DRIZZLE_RETURN_OK, "Drizzle connection failure");
69
62
  }
70
63
 
71
64
  drizzle_query_str(con, "create table libdrizzle.t1 (a int primary key auto_increment, b varchar(255), c timestamp default current_timestamp)", &ret);
72
 
  if (ret != DRIZZLE_RETURN_OK)
73
 
  {
74
 
    printf("Create table failure\n");
75
 
    return EXIT_FAILURE;
76
 
  }
 
65
  ASSERT_TRUE_(ret == DRIZZLE_RETURN_OK, "create table libdrizzle.t1 (a int primary key auto_increment, b varchar(255), c timestamp default current_timestamp)");
77
66
 
78
67
  drizzle_query_str(con, "insert into libdrizzle.t1 (b) values ('this'),('is'),('war')", &ret);
79
 
  if (ret != DRIZZLE_RETURN_OK)
80
 
  {
81
 
    printf("Insert failure\n");
82
 
    return EXIT_FAILURE;
83
 
  }
 
68
  ASSERT_TRUE_(ret == DRIZZLE_RETURN_OK, "insert into libdrizzle.t1 (b) values ('this'),('is'),('war')");
84
69
 
85
70
  result= drizzle_query_str(con, "select * from libdrizzle.t1", &ret);
86
 
  if (ret != DRIZZLE_RETURN_OK)
87
 
  {
88
 
    printf("Select failure\n");
89
 
    return EXIT_FAILURE;
90
 
  }
 
71
  ASSERT_TRUE_(ret == DRIZZLE_RETURN_OK, "select * from libdrizzle.t1");
 
72
 
91
73
  drizzle_result_buffer(result);
92
74
  num_fields= drizzle_result_column_count(result);
93
75
 
94
 
  if (num_fields != 3)
95
 
  {
96
 
    printf("Retrieved bad number of fields\n");
97
 
    return EXIT_FAILURE;
98
 
  }
 
76
  ASSERT_TRUE_(num_fields == 3, "Retrieved bad number of fields");
 
77
 
99
78
  int i= 0;
100
 
  int j= 0;
101
 
  char buf[10];
102
79
  drizzle_column_st *column;
103
80
  while ((row = drizzle_row_next(result)))
104
81
  {
105
82
    drizzle_column_seek(result, 0);
106
 
    j= 0;
 
83
    int j= 0;
107
84
    i++;
108
 
    snprintf(buf, 10, "%d", i);
109
 
    if (strcmp(row[0], buf) != 0)
110
 
    {
111
 
      printf("Retrieved bad row value\n");
112
 
      return EXIT_FAILURE;
113
 
    }
 
85
    char buf[10];
 
86
    snprintf(buf, sizeof(buf), "%d", i);
 
87
    ASSERT_EQ_(strcmp(row[0], buf), 0, "Retrieved bad row value");
114
88
    while ((column= drizzle_column_next(result)))
115
89
    {
116
90
      j++;
117
 
      if (strcmp(drizzle_column_db(column), "libdrizzle") != 0)
118
 
      {
119
 
        printf("Column has bad DB name\n");
120
 
        return EXIT_FAILURE;
121
 
      }
122
 
      if (strcmp(drizzle_column_table(column), "t1") != 0)
123
 
      {
124
 
        printf("Column had bad table name\n");
125
 
        return EXIT_FAILURE;
126
 
      }
127
 
      if ((j == 2) && (drizzle_column_max_size(column) != 255))
128
 
      {
129
 
        printf("Column max size wrong %lu != 255\n", drizzle_column_max_size(column));
130
 
        return EXIT_FAILURE;
131
 
      }
132
 
      if ((j == 2) && (drizzle_column_charset(column) != DRIZZLE_CHARSET_LATIN1_SWEDISH_CI))
133
 
      {
134
 
        printf("Column type wrong, %d != %d\n", drizzle_column_charset(column), DRIZZLE_CHARSET_UTF8_BIN);
135
 
        return EXIT_FAILURE;
136
 
      }
137
 
      if ((j == 3) && (drizzle_column_type(column) != DRIZZLE_COLUMN_TYPE_TIMESTAMP))
138
 
      {
139
 
        printf("Column type wrong\n");
140
 
        return EXIT_FAILURE;
141
 
      }
142
 
    }
143
 
    if (j != 3)
144
 
    {
145
 
      printf("Wrong column count\n");
146
 
      return EXIT_FAILURE;
147
 
    }
 
91
      ASSERT_EQ_(strcmp(drizzle_column_db(column), "libdrizzle"), 0, "Column has bad DB name");
 
92
      ASSERT_EQ_(strcmp(drizzle_column_table(column), "t1"), 0, "Column had bad table name");
 
93
      ASSERT_FALSE_((j == 2) && (drizzle_column_max_size(column) != 255), "Column max size wrong %lu != 255", drizzle_column_max_size(column));
 
94
 
 
95
      ASSERT_FALSE_((j == 2) && (drizzle_column_charset(column) != DRIZZLE_CHARSET_LATIN1_SWEDISH_CI), "Column type wrong, %d != %d", drizzle_column_charset(column), DRIZZLE_CHARSET_UTF8_BIN);
 
96
      ASSERT_FALSE_((j == 3) && (drizzle_column_type(column) != DRIZZLE_COLUMN_TYPE_TIMESTAMP), "Column type wrong");
 
97
    }
 
98
    ASSERT_EQ_(j, 3, "Wrong column count");
148
99
  }
149
100
  /* Should have had 3 rows */
150
 
  if (i != 3)
151
 
  {
152
 
    printf("Retrieved bad number of rows\n");
153
 
    return EXIT_FAILURE;
154
 
  }
 
101
  ASSERT_EQ_(i, 3, "Retrieved bad number of rows");
155
102
 
156
103
  drizzle_result_free(result);
157
104
 
158
105
  drizzle_query_str(con, "drop table libdrizzle.t1", &ret);
159
 
  if (ret != DRIZZLE_RETURN_OK)
160
 
  {
161
 
    printf("Drop table failure\n");
162
 
    return EXIT_FAILURE;
163
 
  }
164
 
 
 
106
  ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "drop table libdrizzle.t1");
165
107
 
166
108
  drizzle_quit(con);
167
109
  return EXIT_SUCCESS;