GdaConnectionEvent * _gda_firebird_make_error (GdaConnection *cnc, const gint statement_type) { FirebirdConnectionData *cdata; GdaConnectionEvent *error_ev; g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL); cdata = (FirebirdConnectionData*) gda_connection_internal_get_provider_data_error (cnc, NULL); if (!cdata) return NULL; error_ev = gda_connection_point_available_event (cnc, GDA_CONNECTION_EVENT_ERROR); gda_connection_event_set_code (error_ev, isc_sqlcode (cdata->status)); ISC_SCHAR *description; const ISC_STATUS *p = cdata->status; description = g_new0 (ISC_SCHAR, 512); fb_interpret (description, 511, &p); g_print ("MAKE_ERROR [%s]\n", description); gda_connection_event_set_source (error_ev, "[GDA Firebird]"); gda_connection_event_set_description (error_ev, description); gda_connection_add_event (cnc, error_ev); g_free (description); return error_ev; }
EXPORT RM_ENTRY(rmc_sqlcode) { ClearParamPool(); ISC_STATUS *stat = AllocStatusPool(); CobolToStatus(stat, &arg_vector[0]); ISC_LONG sqlcode = isc_sqlcode(stat); IntToCobol(&arg_vector[-1], (ISC_UINT64)sqlcode); return (0); }
/* map driver specific error message to PDO error */ void _firebird_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, char const *file, long line TSRMLS_DC) /* {{{ */ { #if 0 pdo_firebird_db_handle *H = stmt ? ((pdo_firebird_stmt *)stmt->driver_data)->H : (pdo_firebird_db_handle *)dbh->driver_data; #endif pdo_error_type *const error_code = stmt ? &stmt->error_code : &dbh->error_code; #if 0 switch (isc_sqlcode(H->isc_status)) { case 0: *error_code = PDO_ERR_NONE; break; default: *error_code = PDO_ERR_CANT_MAP; break; case -104: *error_code = PDO_ERR_SYNTAX; break; case -530: case -803: *error_code = PDO_ERR_CONSTRAINT; break; case -204: case -205: case -206: case -829: *error_code = PDO_ERR_NOT_FOUND; break; *error_code = PDO_ERR_ALREADY_EXISTS; break; *error_code = PDO_ERR_NOT_IMPLEMENTED; break; case -313: case -804: *error_code = PDO_ERR_MISMATCH; break; case -303: case -314: case -413: *error_code = PDO_ERR_TRUNCATED; break; *error_code = PDO_ERR_DISCONNECTED; break; } #else strcpy(*error_code, "HY000"); #endif }
/* print interbase error and save it for ibase_errmsg() */ void _php_ibase_error(TSRMLS_D) /* {{{ */ { char *s = IBG(errmsg); ISC_STATUS *statusp = IB_STATUS; IBG(sql_code) = isc_sqlcode(IB_STATUS); while ((s - IBG(errmsg)) < MAX_ERRMSG - (IBASE_MSGSIZE + 2) && isc_interprete(s, &statusp)) { strcat(IBG(errmsg), " "); s = IBG(errmsg) + strlen(IBG(errmsg)); } php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", IBG(errmsg)); }
/* print interbase error and save it for ibase_errmsg() */ void _php_ibase_error(void) /* {{{ */ { char *s = IBG(errmsg); const ISC_STATUS *statusp = IB_STATUS; IBG(sql_code) = isc_sqlcode(IB_STATUS); while ((s - IBG(errmsg)) < MAX_ERRMSG && fb_interpret(s, MAX_ERRMSG - strlen(IBG(errmsg)) - 1, &statusp)) { strcat(IBG(errmsg), " "); s = IBG(errmsg) + strlen(IBG(errmsg)); } php_error_docref(NULL, E_WARNING, "%s", IBG(errmsg)); }
int fb_error(rlm_sql_firebird_conn_t *conn) { ISC_SCHAR error[2048]; /* Only 1024 bytes should be written to this, but were playing it extra safe */ ISC_STATUS *pstatus; conn->sql_code = 0; /* * Free any previous errors. */ TALLOC_FREE(conn->error); /* * Check if the status array contains an error */ if (IS_ISC_ERROR(conn->status)) { conn->sql_code = isc_sqlcode(conn->status); /* * pstatus is a pointer into the status array which is * advanced by isc_interprete. It's initialised to the * first element of the status array. */ pstatus = &conn->status[0]; /* * It's deprecated because the size of the buffer isn't * passed and this isn't safe. But as were passing a very * large buffer it's unlikely this will be an issue, and * allows us to maintain compatibility with the interbase * API. */ isc_interprete(&error[0], &pstatus); conn->error = talloc_typed_asprintf(conn, "%s. ", &error[0]); while (isc_interprete(&error[0], &pstatus)) { conn->error = talloc_asprintf_append(conn->error, "%s. ", &error[0]); } memset(&conn->status, 0, sizeof(conn->status)); } return conn->sql_code; }
int main (int argc, char** argv) { char dept_no[4]; double percent_inc; short flag0 = 0, flag1 = 0; XSQLDA *sqlda; long sqlcode; char empdb[128]; if (argc > 1) strcpy(empdb, argv[1]); else strcpy(empdb, "employee.fdb"); if (isc_attach_database(status, 0, empdb, &DB, 0, NULL)) { ERREXIT(status, 1) } /* Allocate an input SQLDA. There are two unknown parameters. */ sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(2)); sqlda->sqln = 2; sqlda->sqld = 2; sqlda->version = 1; sqlda->sqlvar[0].sqldata = (char *) &percent_inc; sqlda->sqlvar[0].sqltype = SQL_DOUBLE + 1; sqlda->sqlvar[0].sqllen = sizeof(percent_inc); sqlda->sqlvar[0].sqlind = &flag0; flag0 = 0; sqlda->sqlvar[1].sqldata = dept_no; sqlda->sqlvar[1].sqltype = SQL_TEXT + 1; sqlda->sqlvar[1].sqllen = 3; sqlda->sqlvar[1].sqlind = &flag1; flag1 = 0; /* * Get the next department-percent increase input pair. */ while (get_input(dept_no, &percent_inc)) { printf("\nIncreasing budget for department: %s by %5.2lf percent.\n", dept_no, percent_inc); if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL)) { ERREXIT(status, 1) } /* Update the budget. */ isc_dsql_execute_immediate(status, &DB, &trans, 0, updstr, 1, sqlda); sqlcode = isc_sqlcode(status); if (sqlcode) { /* Don't save the update, if the new budget exceeds the limit. */ if (sqlcode == -625) { printf("\tExceeded budget limit -- not updated.\n"); if (isc_rollback_transaction(status, &trans)) { ERREXIT(status, 1) } continue; } /* Undo all changes, in case of an error. */ else { isc_print_status(status); printf("SQLCODE=%d\n", sqlcode); isc_rollback_transaction(status, &trans); ERREXIT(status, 1) } }