~linuxjedi/libdrizzle/5.1-docs2

« back to all changes in this revision

Viewing changes to libdrizzle/statement.cc

  • Committer: Continuous Integration
  • Date: 2013-01-13 20:18:49 UTC
  • mfrom: (90.1.4 5.1-malloc-replace)
  • Revision ID: ci@drizzle.org-20130113201849-a0to8usgbnbf5sch
Merge lp:~linuxjedi/libdrizzle/5.1-malloc-replace Build: jenkins-Libdrizzle-46

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
drizzle_stmt_st *drizzle_stmt_prepare(drizzle_st *con, const char *statement, size_t size, drizzle_return_t *ret_ptr)
42
42
{
43
 
  drizzle_stmt_st *stmt= (drizzle_stmt_st*)malloc(sizeof(drizzle_stmt_st));
 
43
  drizzle_stmt_st *stmt= new (std::nothrow) drizzle_stmt_st;
44
44
  if (stmt == NULL)
45
45
  {
46
46
    *ret_ptr= DRIZZLE_RETURN_MEMORY;
47
 
    drizzle_set_error(con, __func__, "malloc");
 
47
    drizzle_set_error(con, __func__, "new");
48
48
    return NULL;
49
49
  }
50
 
  stmt->execute_result= NULL;
51
 
  stmt->param_count= 0;
52
 
  stmt->id= 0;
53
 
  stmt->query_params= NULL;
54
 
  stmt->result_params= NULL;
55
 
  stmt->null_bitmap_length= 0;
56
 
  stmt->null_bitmap= NULL;
57
 
  stmt->new_bind= true;
58
50
  con->stmt= stmt;
59
51
  stmt->con= con;
60
52
 
62
54
                                      statement, size, size, ret_ptr);
63
55
  if (*ret_ptr != DRIZZLE_RETURN_OK)
64
56
  {
65
 
    free(stmt);
 
57
    delete stmt;
66
58
    con->stmt= NULL;
67
59
    return NULL;
68
60
  }
77
69
      *ret_ptr= drizzle_column_skip(stmt->prepare_result);
78
70
      if ((*ret_ptr != DRIZZLE_RETURN_OK) && (*ret_ptr != DRIZZLE_RETURN_EOF))
79
71
      {
80
 
        free(stmt);
 
72
        delete stmt;
81
73
        return NULL;
82
74
      }
83
75
    }
93
85
   * bitmap mask */
94
86
 
95
87
  stmt->null_bitmap_length= (stmt->param_count + 7) / 8;
96
 
  stmt->null_bitmap= (uint8_t*)calloc(stmt->null_bitmap_length, 1);
 
88
  stmt->null_bitmap= new (std::nothrow) uint8_t[stmt->null_bitmap_length]();
97
89
  if (stmt->null_bitmap == NULL)
98
90
  {
99
 
    free(stmt);
 
91
    delete stmt;
100
92
    *ret_ptr= DRIZZLE_RETURN_MEMORY;
101
 
    drizzle_set_error(con, __func__, "malloc");
 
93
    drizzle_set_error(con, __func__, "new");
102
94
    return NULL;
103
95
  }
104
96
 
105
97
  /* Also use the parameter count to allocate the parameters */
106
 
  stmt->query_params= (drizzle_bind_st*)calloc(stmt->param_count, sizeof(drizzle_bind_st));
 
98
  stmt->query_params= new (std::nothrow) drizzle_bind_st[stmt->param_count];
107
99
  stmt->state= DRIZZLE_STMT_PREPARED;
108
100
  stmt->fields= stmt->prepare_result->column_buffer;
109
101
 
141
133
             + (stmt->param_count * 2) /* Parameter type data */
142
134
             + param_lengths; /* Parameter data */
143
135
 
144
 
  buffer = (unsigned char*)malloc(buffer_size);
 
136
  buffer = new (std::nothrow) unsigned char[buffer_size];
145
137
  if (buffer == NULL)
146
138
  {
147
 
    drizzle_set_error(stmt->con, __func__, "malloc");
 
139
    drizzle_set_error(stmt->con, __func__, "new");
148
140
    return DRIZZLE_RETURN_MEMORY;
149
141
  }
150
142
  buffer_pos= buffer;
274
266
      case DRIZZLE_COLUMN_TYPE_TIME2:
275
267
      default:
276
268
        drizzle_set_error(stmt->con, __func__, "unknown type when filling buffer");
277
 
        free(buffer);
 
269
        delete[] buffer;
278
270
        return DRIZZLE_RETURN_UNEXPECTED_DATA;
279
271
        break;
280
272
    }
296
288
  }
297
289
  else
298
290
  {
299
 
    free(buffer);
 
291
    delete[] buffer;
300
292
    return ret;
301
293
  }
302
294
 
309
301
  if (stmt->execute_result->column_count > 0)
310
302
  {
311
303
    ret= drizzle_column_buffer(stmt->execute_result);
312
 
    stmt->result_params= (drizzle_bind_st*)calloc(stmt->execute_result->column_count, sizeof(drizzle_bind_st));
 
304
    stmt->result_params= new (std::nothrow) drizzle_bind_st[stmt->execute_result->column_count];
313
305
  }
314
306
 
315
 
  free(buffer);
 
307
  delete[] buffer;
316
308
  return ret;
317
309
}
318
310
 
336
328
  /* TODO: rework drizzle_command_write so we can send a header and we don't
337
329
   * need this copy
338
330
   * */
339
 
  buffer= (unsigned char*)malloc(len + 6);
 
331
  buffer= new (std::nothrow) unsigned char[len + 6];
340
332
 
341
333
  drizzle_set_byte4(buffer, stmt->id);
342
334
  drizzle_set_byte2(&buffer[4], param_num);
348
340
  stmt->con->options= (drizzle_options_t)((uint8_t)stmt->con->options & (uint8_t)~DRIZZLE_CON_NO_RESULT_READ);
349
341
  stmt->query_params[param_num].options.is_long_data= true;
350
342
 
351
 
  free(buffer);
 
343
  delete[] buffer;
352
344
  return ret;
353
345
}
354
346
 
379
371
    stmt->execute_result= NULL;
380
372
  }
381
373
  stmt->state= DRIZZLE_STMT_PREPARED;
382
 
  free(stmt->result_params);
 
374
  delete[] stmt->result_params;
383
375
 
384
376
  return ret;
385
377
}
552
544
    return DRIZZLE_RETURN_INVALID_ARGUMENT;
553
545
  }
554
546
 
555
 
  free(stmt->null_bitmap);
 
547
  delete[] stmt->null_bitmap;
556
548
  for (uint16_t x= 0; x < stmt->param_count; x++)
557
549
  {
558
550
    if (stmt->query_params[x].options.is_allocated)
560
552
      free(stmt->query_params[x].data);
561
553
    }
562
554
  }
563
 
  free(stmt->query_params);
 
555
  delete[] stmt->query_params;
564
556
  if (stmt->execute_result)
565
557
  {
566
558
    for (uint16_t x= 0; x < stmt->execute_result->column_count; x++)
568
560
      free(stmt->result_params[x].data);
569
561
      free(stmt->result_params[x].converted_data);
570
562
    }
571
 
    free(stmt->result_params);
 
563
    delete[] stmt->result_params;
572
564
    drizzle_result_free(stmt->execute_result);
573
565
  }
574
566
  if (stmt->prepare_result)
581
573
  drizzle_command_write(stmt->con, NULL, DRIZZLE_COMMAND_STMT_CLOSE, buffer, 4,
582
574
                        4, &ret);
583
575
  stmt->con->options= (drizzle_options_t)((uint8_t)stmt->con->options & (uint8_t)~DRIZZLE_CON_NO_RESULT_READ);
584
 
  free(stmt);
 
576
  delete stmt;
585
577
  return ret;
586
578
}
587
579