Subject | SELECT & transaction using C API |
---|---|
Author | marek22@centrum.cz |
Post date | 2004-11-18T14:48:31Z |
Hi,
I'm using Firebird 1.5.1-3 (debian package) in C and have a problem. I
want to have two SELECT in same function and would like to have it as
fast as possible. I tried to have it in one transaction and there was
problem with open cursor. After I tried to divide it into two
transactions then it looks ok (even fetch returns 0L) but value wasn't
set. Both parts works when the second one is in commentary block. This
is the code:
isc_start_transaction(status_vector, &(trans), 1, &(pc_data->db), 0, NULL);
isc_dsql_prepare(status_vector, &trans, &(pc_data->stat_stmt), 0, sql_query, 1,
pc_data->stat_sqlda);
isc_dsql_execute(status_vector, &trans, &(pc_data->stat_stmt), 1, pc_data->stat_sqlda);
if ((fetch_stat = isc_dsql_fetch(status_vector, &(pc_data->stat_stmt), 1,
pc_data->stat_sqlda)) == 0L) {
result = pc_data->stat_id;
} else {
DEBUG(0,("SQL Problem in get_long_from_file(): %ld\n",fetch_stat));
result = FIREFS_SQL_ERROR;
}
// block dividing into two transaction
isc_commit_transaction(status_vector, &(trans));
trans = 0L;
isc_start_transaction(status_vector, &(trans), 1, &(pc_data->db), 0, NULL);
if ((result != FIREFS_SQL_ERROR)) {
char buffer[BUFFER_LENGTH]; buffer[BUFFER_LENGTH-1] = '\0';
snprintf(buffer, BUFFER_LENGTH-1, "%ld",result);
sql_query = strxcat(6,sql_select," FROM tblfile, rel_ctn_fil WHERE tblfile.id_fil =
rel_ctn_fil.tbl_id_fil AND rel_ctn_fil.tbl_id_ctn =
isc_dsql_prepare(status_vector, &trans, &(pc_data->stat_stmt), 0, sql_query, 1,
pc_data->fstat_sqlda);
isc_dsql_execute(status_vector, &trans, &(pc_data->stat_stmt), 1,
pc_data->fstat_sqlda);
if ((fetch_stat = isc_dsql_fetch(status_vector, &(pc_data->stat_stmt), 1,
pc_data->fstat_sqlda)) == 0L) {
result = pc_data->stat_id;
} else {
DEBUG(0,("SQL Problem in get_long_from_file(): (2) %ld\n",fetch_stat));
result = FIREFS_SQL_ERROR;
}
}
isc_commit_transaction(status_vector, &(trans));
PS: excuse formation pls (webmail :( )
I'm using Firebird 1.5.1-3 (debian package) in C and have a problem. I
want to have two SELECT in same function and would like to have it as
fast as possible. I tried to have it in one transaction and there was
problem with open cursor. After I tried to divide it into two
transactions then it looks ok (even fetch returns 0L) but value wasn't
set. Both parts works when the second one is in commentary block. This
is the code:
isc_start_transaction(status_vector, &(trans), 1, &(pc_data->db), 0, NULL);
isc_dsql_prepare(status_vector, &trans, &(pc_data->stat_stmt), 0, sql_query, 1,
pc_data->stat_sqlda);
isc_dsql_execute(status_vector, &trans, &(pc_data->stat_stmt), 1, pc_data->stat_sqlda);
if ((fetch_stat = isc_dsql_fetch(status_vector, &(pc_data->stat_stmt), 1,
pc_data->stat_sqlda)) == 0L) {
result = pc_data->stat_id;
} else {
DEBUG(0,("SQL Problem in get_long_from_file(): %ld\n",fetch_stat));
result = FIREFS_SQL_ERROR;
}
// block dividing into two transaction
isc_commit_transaction(status_vector, &(trans));
trans = 0L;
isc_start_transaction(status_vector, &(trans), 1, &(pc_data->db), 0, NULL);
if ((result != FIREFS_SQL_ERROR)) {
char buffer[BUFFER_LENGTH]; buffer[BUFFER_LENGTH-1] = '\0';
snprintf(buffer, BUFFER_LENGTH-1, "%ld",result);
sql_query = strxcat(6,sql_select," FROM tblfile, rel_ctn_fil WHERE tblfile.id_fil =
rel_ctn_fil.tbl_id_fil AND rel_ctn_fil.tbl_id_ctn =
isc_dsql_prepare(status_vector, &trans, &(pc_data->stat_stmt), 0, sql_query, 1,
pc_data->fstat_sqlda);
isc_dsql_execute(status_vector, &trans, &(pc_data->stat_stmt), 1,
pc_data->fstat_sqlda);
if ((fetch_stat = isc_dsql_fetch(status_vector, &(pc_data->stat_stmt), 1,
pc_data->fstat_sqlda)) == 0L) {
result = pc_data->stat_id;
} else {
DEBUG(0,("SQL Problem in get_long_from_file(): (2) %ld\n",fetch_stat));
result = FIREFS_SQL_ERROR;
}
}
isc_commit_transaction(status_vector, &(trans));
PS: excuse formation pls (webmail :( )