~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/pipe_query.cc

  • Committer: Mark Atwood
  • Date: 2011-11-22 17:04:41 UTC
  • mfrom: (2462.1.3 drizzle-include)
  • Revision ID: me@mark.atwood.name-20111122170441-5dehm0e0ax20z19b
mergeĀ lp:~brianaker/drizzle/fedora-16-fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
  char *buffer= NULL;
55
55
  size_t buffer_size= 0;
56
56
  ssize_t read_size= 0;
57
 
  drizzle_st *drizzle;
 
57
  drizzle_st drizzle;
 
58
  drizzle_con_st *con= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
58
59
  drizzle_result_st result;
 
60
  drizzle_return_t ret;
 
61
  drizzle_field_t field;
59
62
  size_t offset;
60
63
  size_t size;
61
64
  size_t total;
62
65
 
 
66
  if (con == NULL)
 
67
  {
 
68
    printf("Failed to allocate memory for drizzle connection");
 
69
    exit(1);
 
70
  }
 
71
 
63
72
  /* The docs say this might fail, so check for errors. */
64
 
  if ((drizzle= drizzle_create()) == NULL)
 
73
  if (drizzle_create(&drizzle) == NULL)
65
74
  {
66
75
    printf("drizzle_create:failed\n");
67
76
    exit(1);
68
77
  }
69
78
 
70
 
  drizzle_con_st *con;
71
 
  if ((con= drizzle_con_create(drizzle)) == NULL)
 
79
  if (drizzle_con_create(&drizzle, con) == NULL)
72
80
  {
73
 
    printf("drizzle_con_create:%s\n", drizzle_error(drizzle));
 
81
    printf("drizzle_con_create:%s\n", drizzle_error(&drizzle));
74
82
    exit(1);
75
83
  }
76
84
 
138
146
 
139
147
  } while ((read_size= read(0, buffer + buffer_size, BUFFER_CHUNK)) != 0);
140
148
 
141
 
  drizzle_return_t ret;
142
149
  (void)drizzle_query(con, &result, buffer, buffer_size, &ret);
143
150
  if (ret != DRIZZLE_RETURN_OK)
144
151
  {
145
 
      printf("drizzle_query:%s\n", drizzle_error(drizzle));
 
152
    printf("drizzle_query:%s\n", drizzle_error(&drizzle));
146
153
    return 1;
147
154
  }
148
155
 
151
158
  ret= drizzle_column_skip(&result);
152
159
  if (ret != DRIZZLE_RETURN_OK)
153
160
  {
154
 
    printf("drizzle_column_skip:%s\n", drizzle_error(drizzle));
 
161
    printf("drizzle_column_skip:%s\n", drizzle_error(&drizzle));
155
162
    return 1;
156
163
  }
157
164
 
159
166
  {
160
167
    while (1)
161
168
    {
162
 
      drizzle_field_t field= drizzle_field_read(&result, &offset, &size, &total, &ret);
 
169
      field= drizzle_field_read(&result, &offset, &size, &total, &ret);
163
170
      if (ret == DRIZZLE_RETURN_ROW_END)
164
 
      {
165
171
        break;
166
 
      }
167
172
      else if (ret != DRIZZLE_RETURN_OK)
168
173
      {
169
 
        printf("drizzle_field_read:%s\n", drizzle_error(drizzle));
 
174
        printf("drizzle_field_read:%s\n", drizzle_error(&drizzle));
170
175
        return 1;
171
176
      }
172
177
 
173
178
      if (field == NULL)
174
 
      {
175
179
        printf("NULL");
176
 
      }
177
180
      else
178
 
      {
179
181
        printf("%.*s", (int)size, field);
180
 
      }
181
182
 
182
183
      if (offset + size == total)
183
 
      {
184
184
        printf("\t");
185
 
      }
186
185
    }
187
186
 
188
187
    printf("\n");
190
189
 
191
190
  if (ret != DRIZZLE_RETURN_OK)
192
191
  {
193
 
    printf("drizzle_row_read:%s\n", drizzle_error(drizzle));
 
192
    printf("drizzle_row_read:%s\n", drizzle_error(&drizzle));
194
193
    return 1;
195
194
  }
196
195
 
197
196
  drizzle_result_free(&result);
198
197
  drizzle_con_free(con);
199
 
  drizzle_free(drizzle);
 
198
  drizzle_free(&drizzle);
200
199
 
 
200
  free(con);
201
201
  return 0;
202
202
}