~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzleclient/client.c

  • Committer: Monty Taylor
  • Date: 2009-02-08 11:11:30 UTC
  • mto: This revision was merged to the branch mainline in revision 852.
  • Revision ID: mordred@inaugust.com-20090208111130-futpwptxv5he3boe
Renamed non-prefixed things from libdrizzleclient to drizzleclient.

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
*****************************************************************************/
95
95
safe_read_error_hook_func safe_read_error_hook= NULL;
96
96
 
97
 
uint32_t cli_safe_read(DRIZZLE *drizzle)
 
97
uint32_t drizzleclient_cli_safe_read(DRIZZLE *drizzle)
98
98
{
99
99
  NET *net= &drizzle->net;
100
100
  uint32_t len=0;
110
110
    drizzle_disconnect(drizzle);
111
111
    drizzle_set_error(drizzle, net->last_errno == CR_NET_PACKET_TOO_LARGE ?
112
112
                      CR_NET_PACKET_TOO_LARGE : CR_SERVER_LOST,
113
 
                      sqlstate_get_unknown());
 
113
                      drizzleclient_sqlstate_get_unknown());
114
114
    return (packet_error);
115
115
  }
116
116
  if (net->read_pos[0] == 255)
133
133
          (unknown error sql state).
134
134
        */
135
135
 
136
 
        strcpy(net->sqlstate, sqlstate_get_unknown());
 
136
        strcpy(net->sqlstate, drizzleclient_sqlstate_get_unknown());
137
137
      }
138
138
 
139
139
      strncpy(net->last_error,(char*) pos, min((uint32_t) len,
140
140
              (uint32_t) sizeof(net->last_error)-1));
141
141
    }
142
142
    else
143
 
      drizzle_set_error(drizzle, CR_UNKNOWN_ERROR, sqlstate_get_unknown());
 
143
      drizzle_set_error(drizzle, CR_UNKNOWN_ERROR, drizzleclient_sqlstate_get_unknown());
144
144
    /*
145
145
      Cover a protocol design error: error packet does not
146
146
      contain the server status. Therefore, the client has no way
158
158
}
159
159
 
160
160
bool
161
 
cli_advanced_command(DRIZZLE *drizzle, enum enum_server_command command,
 
161
drizzleclient_cli_advanced_command(DRIZZLE *drizzle, enum enum_server_command command,
162
162
         const unsigned char *header, uint32_t header_length,
163
163
         const unsigned char *arg, uint32_t arg_length, bool skip_check)
164
164
{
175
175
      drizzle->server_status & SERVER_MORE_RESULTS_EXISTS)
176
176
  {
177
177
    drizzle_set_error(drizzle, CR_COMMANDS_OUT_OF_SYNC,
178
 
                      sqlstate_get_unknown());
 
178
                      drizzleclient_sqlstate_get_unknown());
179
179
    return(1);
180
180
  }
181
181
 
182
 
  net_clear_error(net);
 
182
  drizzleclient_drizzleclient_net_clear_error(net);
183
183
  drizzle->info=0;
184
184
  drizzle->affected_rows= ~(uint64_t) 0;
185
185
  /*
187
187
    the previous command was a shutdown command, we may have the
188
188
    response for the COM_QUIT already in the communication buffer
189
189
  */
190
 
  net_clear(&drizzle->net, (command != COM_QUIT));
 
190
  drizzleclient_net_clear(&drizzle->net, (command != COM_QUIT));
191
191
 
192
 
  if (net_write_command(net,(unsigned char) command, header, header_length,
 
192
  if (drizzleclient_net_write_command(net,(unsigned char) command, header, header_length,
193
193
      arg, arg_length))
194
194
  {
195
195
    if (net->last_errno == CR_NET_PACKET_TOO_LARGE)
196
196
    {
197
 
      drizzle_set_error(drizzle, CR_NET_PACKET_TOO_LARGE, sqlstate_get_unknown());
 
197
      drizzle_set_error(drizzle, CR_NET_PACKET_TOO_LARGE, drizzleclient_sqlstate_get_unknown());
198
198
      goto end;
199
199
    }
200
200
    drizzle_disconnect(drizzle);
201
201
    if (drizzle_reconnect(drizzle) || stmt_skip)
202
202
      goto end;
203
 
    if (net_write_command(net,(unsigned char) command, header, header_length,
 
203
    if (drizzleclient_net_write_command(net,(unsigned char) command, header, header_length,
204
204
        arg, arg_length))
205
205
    {
206
 
      drizzle_set_error(drizzle, CR_SERVER_GONE_ERROR, sqlstate_get_unknown());
 
206
      drizzle_set_error(drizzle, CR_SERVER_GONE_ERROR, drizzleclient_sqlstate_get_unknown());
207
207
      goto end;
208
208
    }
209
209
  }
210
210
  result=0;
211
211
  if (!skip_check)
212
 
    result= ((drizzle->packet_length=cli_safe_read(drizzle)) == packet_error ?
 
212
    result= ((drizzle->packet_length=drizzleclient_cli_safe_read(drizzle)) == packet_error ?
213
213
       1 : 0);
214
214
end:
215
215
  return(result);
216
216
}
217
217
 
218
 
void free_old_query(DRIZZLE *drizzle)
 
218
void drizzleclient_free_old_query(DRIZZLE *drizzle)
219
219
{
220
220
  if (drizzle->fields)
221
221
  {
260
260
          *drizzle->unbuffered_fetch_owner= true;
261
261
      }
262
262
    }
263
 
    free_rows(result->data);
 
263
    drizzleclient_free_rows(result->data);
264
264
    /* TODO: free result->fields */
265
265
    if (result->row)
266
266
      free((unsigned char*) result->row);
273
273
 
274
274
/* Read all rows (fields or data) from server */
275
275
 
276
 
DRIZZLE_DATA *cli_read_rows(DRIZZLE *drizzle, DRIZZLE_FIELD *DRIZZLE_FIELDs, uint32_t fields)
 
276
DRIZZLE_DATA *drizzleclient_cli_read_rows(DRIZZLE *drizzle, DRIZZLE_FIELD *DRIZZLE_FIELDs, uint32_t fields)
277
277
{
278
278
  uint32_t  field;
279
279
  uint32_t pkt_len;
284
284
  DRIZZLE_ROWS **prev_ptr,*cur;
285
285
  NET *net = &drizzle->net;
286
286
 
287
 
  if ((pkt_len= cli_safe_read(drizzle)) == packet_error)
 
287
  if ((pkt_len= drizzleclient_cli_safe_read(drizzle)) == packet_error)
288
288
    return(0);
289
289
  if (!(result=(DRIZZLE_DATA*) malloc(sizeof(DRIZZLE_DATA))))
290
290
  {
291
291
    drizzle_set_error(drizzle, CR_OUT_OF_MEMORY,
292
 
                      sqlstate_get_unknown());
 
292
                      drizzleclient_sqlstate_get_unknown());
293
293
    return(0);
294
294
  }
295
295
  memset(result, 0, sizeof(DRIZZLE_DATA));
301
301
    The last EOF packet is either a 254 (0xFE) character followed by 1-7 status bytes.
302
302
 
303
303
    This doesn't conflict with normal usage of 254 which stands for a
304
 
    string where the length of the string is 8 bytes. (see net_field_length())
 
304
    string where the length of the string is 8 bytes. (see drizzleclient_net_field_length())
305
305
  */
306
306
 
307
307
  while (*(cp=net->read_pos) != DRIZZLE_PROTOCOL_NO_MORE_DATA || pkt_len >= 8)
310
310
    if (!(cur= (DRIZZLE_ROWS*) malloc(sizeof(DRIZZLE_ROWS))) ||
311
311
        !(cur->data= ((DRIZZLE_ROW) malloc((fields+1)*sizeof(char *)+pkt_len))))
312
312
    {
313
 
      free_rows(result);
314
 
      drizzle_set_error(drizzle, CR_OUT_OF_MEMORY, sqlstate_get_unknown());
 
313
      drizzleclient_free_rows(result);
 
314
      drizzle_set_error(drizzle, CR_OUT_OF_MEMORY, drizzleclient_sqlstate_get_unknown());
315
315
      return(0);
316
316
    }
317
317
    *prev_ptr=cur;
320
320
    end_to=to+pkt_len-1;
321
321
    for (field=0 ; field < fields ; field++)
322
322
    {
323
 
      if ((len= net_field_length(&cp)) == NULL_LENGTH)
 
323
      if ((len= drizzleclient_net_field_length(&cp)) == NULL_LENGTH)
324
324
      {            /* null field */
325
325
        cur->data[field] = 0;
326
326
      }
329
329
        cur->data[field] = to;
330
330
        if (len > (uint32_t) (end_to - to))
331
331
        {
332
 
          free_rows(result);
 
332
          drizzleclient_free_rows(result);
333
333
          drizzle_set_error(drizzle, CR_MALFORMED_PACKET,
334
 
                            sqlstate_get_unknown());
 
334
                            drizzleclient_sqlstate_get_unknown());
335
335
          return(0);
336
336
        }
337
337
        memcpy(to, cp, len);
346
346
      }
347
347
    }
348
348
    cur->data[field]=to;      /* End of last field */
349
 
    if ((pkt_len=cli_safe_read(drizzle)) == packet_error)
 
349
    if ((pkt_len=drizzleclient_cli_safe_read(drizzle)) == packet_error)
350
350
    {
351
 
      free_rows(result);
 
351
      drizzleclient_free_rows(result);
352
352
      return(0);
353
353
    }
354
354
  }
375
375
  unsigned char *pos, *prev_pos, *end_pos;
376
376
  NET *net= &drizzle->net;
377
377
 
378
 
  if ((pkt_len=cli_safe_read(drizzle)) == packet_error)
 
378
  if ((pkt_len=drizzleclient_cli_safe_read(drizzle)) == packet_error)
379
379
    return -1;
380
380
  if (pkt_len <= 8 && net->read_pos[0] == DRIZZLE_PROTOCOL_NO_MORE_DATA)
381
381
  {
391
391
  end_pos=pos+pkt_len;
392
392
  for (field=0 ; field < fields ; field++)
393
393
  {
394
 
    if ((len= net_field_length(&pos)) == NULL_LENGTH)
 
394
    if ((len= drizzleclient_net_field_length(&pos)) == NULL_LENGTH)
395
395
    {            /* null field */
396
396
      row[field] = 0;
397
397
      *lengths++=0;
401
401
      if (len > (uint32_t) (end_pos - pos))
402
402
      {
403
403
        drizzle_set_error(drizzle, CR_UNKNOWN_ERROR,
404
 
                          sqlstate_get_unknown());
 
404
                          drizzleclient_sqlstate_get_unknown());
405
405
        return -1;
406
406
      }
407
407
      row[field] = (char*) pos;
435
435
        drizzle_set_error(drizzle,
436
436
                          res->unbuffered_fetch_cancelled ?
437
437
                          CR_FETCH_CANCELED : CR_COMMANDS_OUT_OF_SYNC,
438
 
                          sqlstate_get_unknown());
 
438
                          drizzleclient_sqlstate_get_unknown());
439
439
      }
440
440
      else if (!(read_one_row(drizzle, res->field_count, res->row, res->lengths)))
441
441
      {