333
343
long statement_type;
334
344
short num_cols, i;
335
345
short length, alignment, type, offset;
346
/* long buffer[MAXLEN*8]; */
337
348
unsigned long long numrows = 0, affectedrows = 0;
338
349
ibase_conn_t *iconn = conn->connection;
340
if (isc_dsql_allocate_statement(iconn->status, &(iconn->db), &stmt)) {
351
if (isc_dsql_allocate_statement(iconn->status_vector, &(iconn->db), &stmt)) {
352
if (iconn->status_vector[0] == 1 && iconn->status_vector[1]) {
354
long* pvector = iconn->status_vector;
355
isc_interprete(msg, &pvector);
356
_dbd_internal_error_handler(conn, msg, DBI_ERROR_CLIENT);
344
sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH (1));
361
sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(1));
346
363
sqlda->version = 1;
348
if (isc_dsql_prepare(iconn->status, &(iconn->trans), &stmt, 0, (char *)statement, 3, sqlda)) {
365
if (isc_dsql_prepare(iconn->status_vector, &(iconn->trans), &stmt, 0, (char *)statement, 3, sqlda)) {
366
if (iconn->status_vector[0] == 1 && iconn->status_vector[1]) {
368
long* pvector = iconn->status_vector;
369
isc_interprete(msg, &pvector);
370
_dbd_internal_error_handler(conn, msg, DBI_ERROR_CLIENT);
350
isc_dsql_free_statement(iconn->status, &stmt, DSQL_drop);
373
isc_dsql_free_statement(iconn->status_vector, &stmt, DSQL_drop);
354
if (!isc_dsql_sql_info(iconn->status, &stmt, sizeof(stmt_info), stmt_info,
377
if (!isc_dsql_sql_info(iconn->status_vector, &stmt, sizeof(stmt_info), stmt_info,
355
378
sizeof(info_buffer), info_buffer)) {
356
379
l = (short) isc_vax_integer((char *) info_buffer + 1, 2);
357
380
statement_type = isc_vax_integer((char *) info_buffer + 3, l);
359
383
/* Execute a non-select statement.*/
360
384
if (!sqlda->sqld) {
361
if (isc_dsql_execute(iconn->status, &(iconn->trans), &stmt , SQL_DIALECT_V6, NULL)) {
385
if (isc_dsql_execute(iconn->status_vector, &(iconn->trans), &stmt , SQL_DIALECT_V6, NULL)) {
386
if (iconn->status_vector[0] == 1 && iconn->status_vector[1]) {
388
long* pvector = iconn->status_vector;
389
isc_interprete(msg, &pvector);
390
_dbd_internal_error_handler(conn, msg, DBI_ERROR_CLIENT);
363
isc_dsql_free_statement(iconn->status, &stmt, DSQL_drop);
393
isc_dsql_free_statement(iconn->status_vector, &stmt, DSQL_drop);
366
396
/* Commit DDL statements if that is what sql_info says */
367
397
if (iconn->trans && (statement_type == isc_info_sql_stmt_ddl)) {
369
if (isc_commit_transaction(iconn->status, &(iconn->trans))) {
399
if (isc_commit_transaction(iconn->status_vector, &(iconn->trans))) {
400
if (iconn->status_vector[0] == 1 && iconn->status_vector[1]) {
402
long* pvector = iconn->status_vector;
403
isc_interprete(msg, &pvector);
404
_dbd_internal_error_handler(conn, msg, DBI_ERROR_CLIENT);
371
isc_dsql_free_statement(iconn->status, &stmt, DSQL_drop);
407
isc_dsql_free_statement(iconn->status_vector, &stmt, DSQL_drop);
374
isc_start_transaction(iconn->status, &(iconn->trans), 1, &(iconn->db), 0, NULL);
410
isc_start_transaction(iconn->status_vector, &(iconn->trans), 1, &(iconn->db), 0, NULL);
414
/* Process select statements. */
378
/* Process select statements. */
380
418
num_cols = sqlda->sqld;
381
419
numrows = 1; /* Firebird can't say how many rows there is, in this early stage.
382
420
We need to fetch all rows and count them :( */
422
/* HACK HACK HACK MH:2008-01-02 */
423
/* I don't really know how much needs to be allocated
424
here. The Firebird example code and the docs won't
425
tell me. I just know that the previously used hard
426
limit (4096) is not enough to run the test program
427
successfully. I'm assuming here that in the worst
428
case num_cols columns contain strings of the maximum
429
allowed length, and that this is just about
430
sufficient. I may be wasting memory here, or the
431
code just so happens to work for the tests
432
applied. If crashes or strange results are reported,
433
revisit this issue */
434
buffer = malloc(32768*num_cols);
385
436
/* Need more room. */
386
437
if (sqlda->sqln < num_cols) {