36 #include <freetds/odbc.h>
39 #include "replacements.h"
54 #define ODBCERR(s3,msg) { msg, s3 }
56 ODBCERR(
"IM007",
"No data source or driver specified"),
58 ODBCERR(
"01002",
"Disconnect error"),
59 ODBCERR(
"01004",
"Data truncated"),
60 ODBCERR(
"01504",
"The UPDATE or DELETE statement does not include a WHERE clause"),
61 ODBCERR(
"01508",
"Statement disqualified for blocking"),
62 ODBCERR(
"01S00",
"Invalid connection string attribute"),
63 ODBCERR(
"01S01",
"Error in row"),
64 ODBCERR(
"01S02",
"Option value changed"),
65 ODBCERR(
"01S06",
"Attempt to fetch before the result set returned the first rowset"),
66 ODBCERR(
"01S07",
"Fractional truncation"),
67 ODBCERR(
"07001",
"Wrong number of parameters"),
68 ODBCERR(
"07002",
"Too many columns"),
69 ODBCERR(
"07005",
"The statement did not return a result set"),
70 ODBCERR(
"07006",
"Invalid conversion"),
71 ODBCERR(
"07009",
"Invalid descriptor index"),
72 ODBCERR(
"08001",
"Unable to connect to data source"),
73 ODBCERR(
"08002",
"Connection in use"),
74 ODBCERR(
"08003",
"Connection is closed"),
75 ODBCERR(
"08004",
"The application server rejected establishment of the connection"),
76 ODBCERR(
"08007",
"Connection failure during transaction"),
77 ODBCERR(
"08S01",
"Communication link failure"),
78 ODBCERR(
"0F001",
"The LOB token variable does not currently represent any value"),
79 ODBCERR(
"21S01",
"Insert value list does not match column list"),
80 ODBCERR(
"22001",
"String data right truncation"),
81 ODBCERR(
"22002",
"Invalid output or indicator buffer specified"),
82 ODBCERR(
"22003",
"Numeric value out of range"),
83 ODBCERR(
"22005",
"Error in assignment"),
84 ODBCERR(
"22007",
"Invalid datetime format"),
85 ODBCERR(
"22008",
"Datetime field overflow"),
86 ODBCERR(
"22011",
"A substring error occurred"),
87 ODBCERR(
"22012",
"Division by zero is invalid"),
88 ODBCERR(
"22015",
"Interval field overflow"),
89 ODBCERR(
"22018",
"Invalid character value for cast specification"),
90 ODBCERR(
"22019",
"Invalid escape character"),
91 ODBCERR(
"22025",
"Invalid escape sequence"),
92 ODBCERR(
"22026",
"String data, length mismatch"),
93 ODBCERR(
"23000",
"Integrity constraint violation"),
94 ODBCERR(
"24000",
"Invalid cursor state"),
95 ODBCERR(
"24504",
"The cursor identified in the UPDATE, DELETE, SET, or GET statement is not positioned on a row"),
96 ODBCERR(
"25501",
"Invalid transaction state"),
97 ODBCERR(
"28000",
"Invalid authorization specification"),
98 ODBCERR(
"34000",
"Invalid cursor name"),
99 ODBCERR(
"37000",
"Invalid SQL syntax"),
100 ODBCERR(
"40001",
"Serialization failure"),
101 ODBCERR(
"40003",
"Statement completion unknown"),
102 ODBCERR(
"42000",
"Syntax error or access violation"),
103 ODBCERR(
"42601",
"PARMLIST syntax error"),
104 ODBCERR(
"42818",
"The operands of an operator or function are not compatible"),
105 ODBCERR(
"42895",
"The value of a host variable in the EXECUTE or OPEN statement cannot be used because of its data type"),
106 ODBCERR(
"428A1",
"Unable to access a file referenced by a host file variable"),
107 ODBCERR(
"44000",
"Integrity constraint violation"),
108 ODBCERR(
"54028",
"The maximum number of concurrent LOB handles has been reached"),
109 ODBCERR(
"56084",
"LOB data is not supported in DRDA"),
110 ODBCERR(
"58004",
"Unexpected system failure"),
111 ODBCERR(
"HY000",
"General driver error"),
112 ODBCERR(
"HY001",
"Memory allocation failure"),
113 ODBCERR(
"HY002",
"Invalid column number"),
114 ODBCERR(
"HY003",
"Program type out of range"),
115 ODBCERR(
"HY004",
"Invalid data type"),
116 ODBCERR(
"HY007",
"Associated statement is not prepared"),
117 ODBCERR(
"HY008",
"Operation was cancelled"),
118 ODBCERR(
"HY009",
"Invalid argument value"),
119 ODBCERR(
"HY010",
"Function sequence error"),
120 ODBCERR(
"HY011",
"Operation invalid at this time"),
121 ODBCERR(
"HY012",
"Invalid transaction code"),
122 ODBCERR(
"HY013",
"Unexpected memory handling error"),
123 ODBCERR(
"HY014",
"No more handles"),
124 ODBCERR(
"HY016",
"Cannot modify an implementation row descriptor"),
125 ODBCERR(
"HY017",
"Invalid use of an automatically allocated descriptor handle"),
126 ODBCERR(
"HY018",
"Server declined cancel request"),
127 ODBCERR(
"HY021",
"Inconsistent descriptor information"),
128 ODBCERR(
"HY024",
"Invalid attribute value"),
129 ODBCERR(
"HY090",
"Invalid string or buffer length"),
130 ODBCERR(
"HY091",
"Descriptor type out of range"),
131 ODBCERR(
"HY092",
"Invalid option"),
132 ODBCERR(
"HY093",
"Invalid parameter number"),
133 ODBCERR(
"HY094",
"Invalid scale value"),
134 ODBCERR(
"HY096",
"Information type out of range"),
135 ODBCERR(
"HY097",
"Column type out of range"),
136 ODBCERR(
"HY098",
"Scope type out of range"),
137 ODBCERR(
"HY099",
"Nullable type out of range"),
138 ODBCERR(
"HY100",
"Uniqueness option type out of range"),
139 ODBCERR(
"HY101",
"Accuracy option type out of range"),
140 ODBCERR(
"HY103",
"Direction option out of range"),
141 ODBCERR(
"HY104",
"Invalid precision value"),
142 ODBCERR(
"HY105",
"Invalid parameter type"),
143 ODBCERR(
"HY106",
"Fetch type out of range"),
144 ODBCERR(
"HY107",
"Row value out of range"),
145 ODBCERR(
"HY108",
"Concurrency option out of range"),
146 ODBCERR(
"HY109",
"Invalid cursor position"),
147 ODBCERR(
"HY110",
"Invalid driver completion"),
148 ODBCERR(
"HY111",
"Invalid bookmark value"),
149 ODBCERR(
"HY501",
"Invalid data source name"),
150 ODBCERR(
"HY503",
"Invalid file name length"),
151 ODBCERR(
"HY506",
"Error closing a file"),
152 ODBCERR(
"HY509",
"Error deleting a file"),
153 ODBCERR(
"HYC00",
"Driver not capable"),
154 ODBCERR(
"HYT00",
"Timeout expired"),
155 ODBCERR(
"HYT01",
"Connection timeout expired"),
156 ODBCERR(
"S0001",
"Database object already exists"),
157 ODBCERR(
"S0002",
"Database object does not exist"),
158 ODBCERR(
"S0011",
"Index already exists"),
159 ODBCERR(
"S0012",
"Index not found"),
160 ODBCERR(
"S0021",
"Column already exists"),
161 ODBCERR(
"S0022",
"Column not found"),
239 int settled, current, best;
250 for (settled = 0; settled < errs->
num_errors; settled++) {
252 for (current = settled; current < errs->
num_errors; current++) {
291 if (istrans == 1 && errs->
errs[current].
msgstate >= 10) {
302 if (best != settled) {
303 swapbuf = errs->
errs[settled];
304 errs->
errs[settled] = errs->
errs[best];
305 errs->
errs[best] = swapbuf;
331 while (pmap->
v3[0]) {
339 strlcpy(dest_state, sqlstate, 6);
407 if (!
strcmp(sqlstate,
"01004") || !
strcmp(sqlstate,
"01S02")) {
420 const char *server,
int row)
445 #define SQLS_MAP(v2,v3) if (strcmp(p,v2) == 0) {strcpy(p,v3); return;}
451 if (p[0] ==
'S' && p[1] ==
'0' && p[2] ==
'0') {
509 static const char msgprefix[] =
"[FreeTDS][SQL Server]";
513 if (numRecord <= 0 || cbErrorMsgMax < 0)
516 if (!handle || ((
TDS_CHK *) handle)->htype != handleType)
520 switch (handleType) {
523 odbc_ver =
dbc->env->attr.odbc_version;
528 odbc_ver =
dbc->env->attr.odbc_version;
532 odbc_ver = ((
TDS_ENV *) handle)->attr.odbc_version;
536 odbc_ver =
dbc->env->attr.odbc_version;
542 if (numRecord >
errs->num_errors)
565 *pfNativeError =
errs->errs[numRecord].
native;
570 ODBC_FUNC(
SQLError, (
P(
SQLHENV,henv),
P(
SQLHDBC,hdbc),
P(
SQLHSTMT,hstmt),
PCHAR(szSqlState),
P(
SQLINTEGER FAR *,pfNativeError),
616 if (!handle || ((
TDS_CHK *) handle)->htype != handleType)
619 switch (handleType) {
644 odbc_ver =
env->attr.odbc_version;
647 switch (diagIdentifier) {
682 if (numRecord >
errs->num_errors)
689 switch (diagIdentifier) {
722 if (
dbc &&
dbc->tds_socket &&
dbc->tds_socket->conn->spid > 0)
723 cplen = sprintf(
tmp,
"%d",
dbc->tds_socket->conn->spid);
746 msg =
dbc->tds_socket->conn->server;
749 if (
stmt->dbc->tds_socket)
750 msg =
stmt->dbc->tds_socket->conn->server;
static const struct s_v3to2map v3to2map[]
void odbc_errs_add(struct _sql_errors *errs, const char *sqlstate, const char *msg)
add an error to list
static void sqlstate2to3(char *state)
void odbc_errs_reset(struct _sql_errors *errs)
reset errors
static void odbc_errs_pop(struct _sql_errors *errs)
Remove first element.
void odbc_errs_add_rdbms(struct _sql_errors *errs, TDS_UINT native, const char *sqlstate, const char *msg, int linenum, int msgstate, const char *server, int row)
Add an error to list.
static const struct s_SqlMsgMap SqlMsgMap[]
static void rank_errors(struct _sql_errors *errs)
static SQLRETURN _SQLGetDiagRec(SQLSMALLINT handleType, SQLHANDLE handle, SQLSMALLINT numRecord, SQLCHAR *szSqlState, SQLINTEGER FAR *pfNativeError, SQLCHAR *szErrorMsg, SQLSMALLINT cbErrorMsgMax, SQLSMALLINT FAR *pcbErrorMsg)
static void odbc_get_v2state(const char *sqlstate, char *dest_state)
static const char * odbc_get_msg(const char *sqlstate)
#define odbc_set_string(dbc, buf, buf_len, out_len, s, s_len)
TDS_DBC * desc_get_dbc(TDS_DESC *desc)
SQLRETURN _SQLRowCount(SQLHSTMT hstmt, SQLINTEGER FAR *pcrow)
#define odbc_set_string_oct(dbc, buf, buf_len, out_len, s, s_len)
#define TDS_RESIZE(p, n_elem)
tds_sysdep_uint32_type TDS_UINT
#define ODBC_FUNC(name, params)
#define SQL_DIAG_SS_MSGSTATE
if(yy_accept[yy_current_state])
int strcmp(const char *str1, const char *str2)
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
SQLRETURN SQLError(SQLHENV EnvironmentHandle, SQLHDBC ConnectionHandle, SQLHSTMT StatementHandle, SQLCHAR *Sqlstate, SQLINTEGER *NativeError, SQLCHAR *MessageText, SQLSMALLINT BufferLength, SQLSMALLINT *TextLength)
SQLRETURN SQLGetDiagRec(SQLSMALLINT HandleType, SQLHANDLE Handle, SQLSMALLINT RecNumber, SQLCHAR *Sqlstate, SQLINTEGER *NativeError, SQLCHAR *MessageText, SQLSMALLINT BufferLength, SQLSMALLINT *TextLength)
#define SQL_DIAG_DYNAMIC_FUNCTION_CODE
SQLRETURN SQLGetDiagField(SQLSMALLINT HandleType, SQLHANDLE Handle, SQLSMALLINT RecNumber, SQLSMALLINT DiagIdentifier, SQLPOINTER DiagInfo, SQLSMALLINT BufferLength, SQLSMALLINT *StringLength)
#define SQL_DIAG_ROW_COUNT
#define SQL_DIAG_CONNECTION_NAME
#define SQL_DIAG_SQLSTATE
#define SQL_DIAG_MESSAGE_TEXT
#define SQL_INVALID_HANDLE
#define SQL_SUCCESS_WITH_INFO
#define SQL_DIAG_SERVER_NAME
#define SQL_DIAG_RETURNCODE
#define SQL_DIAG_CLASS_ORIGIN
#define SQL_DIAG_SUBCLASS_ORIGIN
#define SQL_DIAG_DYNAMIC_FUNCTION
#define SQL_NO_DATA_FOUND
#define SQL_ROW_NUMBER_UNKNOWN
#define SQL_DIAG_COLUMN_NUMBER
#define SQL_DIAG_CURSOR_ROW_COUNT
#define SQL_COLUMN_NUMBER_UNKNOWN
#define SQL_DIAG_ROW_NUMBER
unsigned short SQLUSMALLINT
signed short int SQLSMALLINT
#define row(bind, expected)