Example #1
0
void
odbc_errs_add(struct _sql_errors *errs, const char *sqlstate, const char *msg)
{
	int n;

	assert(sqlstate);
	if (!errs)
		return;

	n = errs->num_errors;
	if (!TDS_RESIZE(errs->errs, n + 1)) {
		errs->lastrc = SQL_ERROR;
		return;
	}

	memset(&errs->errs[n], 0, sizeof(struct _sql_error));
	errs->errs[n].native = 0;
	strlcpy(errs->errs[n].state3, sqlstate, 6);
	odbc_get_v2state(errs->errs[n].state3, errs->errs[n].state2);

	/* TODO why driver ?? -- freddy77 */
	errs->errs[n].server = strdup("DRIVER");
	errs->errs[n].msg = msg ? strdup(msg) : odbc_get_msg(errs->errs[n].state3);
	++errs->num_errors;

	/* updated last error */
	if (!strcmp(sqlstate, "01004") || !strcmp(sqlstate, "01S02")) {
		if (errs->lastrc != SQL_ERROR)
			errs->lastrc = SQL_SUCCESS_WITH_INFO;
	} else {
		errs->lastrc = SQL_ERROR;
	}

	tdsdump_log(TDS_DBG_FUNC, "odbc_errs_add: \"%s\"\n", errs->errs[n].msg);
}
Example #2
0
void
odbc_errs_add(struct _sql_errors *errs, const char *sqlstate, const char *msg, const char *server)
{
	struct _sql_error *p;
	int n = errs->num_errors;

	assert(sqlstate);

	if (errs->errs)
		p = (struct _sql_error *) realloc(errs->errs, sizeof(struct _sql_error) * (n + 1));
	else
		p = (struct _sql_error *) malloc(sizeof(struct _sql_error));
	if (!p)
		return;
	errs->errs = p;

	memset(&errs->errs[n], 0, sizeof(struct _sql_error));
	errs->errs[n].native = 0;
	strncpy(errs->errs[n].state3, sqlstate, 5);
	errs->errs[n].state3[5] = '\0';
	odbc_get_v2state(errs->errs[n].state3, errs->errs[n].state2);

	/* TODO why driver ?? -- freddy77 */
	errs->errs[n].server = (server) ? strdup(server) : strdup("DRIVER");
	errs->errs[n].msg = msg ? strdup(msg) : odbc_get_msg(errs->errs[n].state3);
	++errs->num_errors;
}