Changeset: ac03922332ea for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ac03922332ea
Modified Files:
        clients/odbc/driver/ODBCStmt.h
        clients/odbc/driver/SQLExecDirect.c
        clients/odbc/driver/SQLPrepare.c
Branch: Dec2011
Log Message:

ODBC: Pass SQLSTATE that we get from server on to application.


diffs (80 lines):

diff --git a/clients/odbc/driver/ODBCStmt.h b/clients/odbc/driver/ODBCStmt.h
--- a/clients/odbc/driver/ODBCStmt.h
+++ b/clients/odbc/driver/ODBCStmt.h
@@ -221,6 +221,6 @@ SQLRETURN SQLPrepare_(ODBCStmt *stmt, SQ
                      SQLINTEGER nSqlStrLength);
 SQLRETURN SQLSetStmtAttr_(ODBCStmt *stmt, SQLINTEGER Attribute,
                          SQLPOINTER Value, SQLINTEGER StringLength);
-const char *ODBCErrorType(const char *msg);
+const char *ODBCErrorType(const char *msg, const char **emsg);
 
 #endif
diff --git a/clients/odbc/driver/SQLExecDirect.c 
b/clients/odbc/driver/SQLExecDirect.c
--- a/clients/odbc/driver/SQLExecDirect.c
+++ b/clients/odbc/driver/SQLExecDirect.c
@@ -58,10 +58,29 @@ static struct errors {
 };
 
 const char *
-ODBCErrorType(const char *msg)
+ODBCErrorType(const char *msg, const char **emsg)
 {
        struct errors *e;
 
+       if (strlen(msg) > 6 && msg[5] == ':' &&
+           ((msg[0] >= '0' && msg[0] <= '9') ||
+            (msg[0] >= 'A' && msg[0] <= 'Z')) &&
+           ((msg[1] >= '0' && msg[1] <= '9') ||
+            (msg[1] >= 'A' && msg[1] <= 'Z')) &&
+           ((msg[2] >= '0' && msg[2] <= '9') ||
+            (msg[2] >= 'A' && msg[2] <= 'Z')) &&
+           ((msg[3] >= '0' && msg[3] <= '9') ||
+            (msg[3] >= 'A' && msg[3] <= 'Z')) &&
+           ((msg[4] >= '0' && msg[4] <= '9') ||
+            (msg[4] >= 'A' && msg[4] <= 'Z')) &&
+           strncmp(msg, "ERROR", 5) != 0) {
+               *emsg = msg + 6;
+               while (**emsg == ' ')
+                       (*emsg)++;
+               return msg;
+       }
+
+       *emsg = msg;
        for (e = errors; e->error != NULL; e++)
                if (strncmp(msg, e->error, strlen(e->error)) == 0)
                        return e->msg;
@@ -124,10 +143,11 @@ ODBCExecDirect(ODBCStmt *stmt, SQLCHAR *
                if (query == NULL)
                        query = mapi_error_str(stmt->Dbc->mid);
                if (query != NULL) {
-                       const char *e = ODBCErrorType(query);
+                       const char *m;
+                       const char *e = ODBCErrorType(query, &m);
 
                        if (e) {
-                               addStmtError(stmt, e, query, 0);
+                               addStmtError(stmt, e, m, 0);
                                return SQL_ERROR;
                        }
                }
diff --git a/clients/odbc/driver/SQLPrepare.c b/clients/odbc/driver/SQLPrepare.c
--- a/clients/odbc/driver/SQLPrepare.c
+++ b/clients/odbc/driver/SQLPrepare.c
@@ -101,14 +101,14 @@ SQLPrepare_(ODBCStmt *stmt,
        free(s);
        s = NULL;
        if (ret != MOK) {
-               const char *e;
+               const char *e, *m;
 
                /* XXX more fine-grained control required */
                /* Syntax error or access violation */
                if ((s = mapi_result_error(hdl)) == NULL)
                        s = mapi_error_str(stmt->Dbc->mid);
-               if (s && (e = ODBCErrorType(s)) != NULL)
-                       addStmtError(stmt, e, s, 0);
+               if (s && (e = ODBCErrorType(s, &m)) != NULL)
+                       addStmtError(stmt, e, m, 0);
                else
                        addStmtError(stmt, "42000", s, 0);
                return SQL_ERROR;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to