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

ODBC: differentiate errors in SQLPrepare (like in SQLExecDirect).
Also fix the strings which we compare: the ! is already removed by mapilib.


diffs (94 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,5 +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);
 
 #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
@@ -44,19 +44,30 @@ static struct errors {
        const char *error;
        const char *msg;
 } errors[] = {
-       {"!syntax error", "42000"},
-       {"!DROP TABLE: no such table", "42S02"},
-       {"!DROP VIEW: unknown view", "42S02"},
-       {"!ALTER TABLE: no such table", "42S02"},
-       {"!CREATE INDEX: no such table", "42S02"},
-       {"!SELECT: no such table", "42S02"},
-       {"!INSERT INTO: no such table", "42S02"},
-       {"!DELETE FROM: no such table", "42S02"},
-       {"!UPDATE: no such table", "42S02"},
-       {"!CONSTRAINT FOREIGN KEY: no such table", "42S02"},
+       {"syntax error", "42000"},
+       {"DROP TABLE: no such table", "42S02"},
+       {"DROP VIEW: unknown view", "42S02"},
+       {"ALTER TABLE: no such table", "42S02"},
+       {"CREATE INDEX: no such table", "42S02"},
+       {"SELECT: no such table", "42S02"},
+       {"INSERT INTO: no such table", "42S02"},
+       {"DELETE FROM: no such table", "42S02"},
+       {"UPDATE: no such table", "42S02"},
+       {"CONSTRAINT FOREIGN KEY: no such table", "42S02"},
        {NULL, NULL},           /* sentinel */
 };
 
+const char *
+ODBCErrorType(const char *msg)
+{
+       struct errors *e;
+
+       for (e = errors; e->error != NULL; e++)
+               if (strncmp(msg, e->error, strlen(e->error)) == 0)
+                       return e->msg;
+       return NULL;
+}
+
 static SQLRETURN
 ODBCExecDirect(ODBCStmt *stmt, SQLCHAR *StatementText, SQLINTEGER TextLength)
 {
@@ -113,13 +124,12 @@ ODBCExecDirect(ODBCStmt *stmt, SQLCHAR *
                if (query == NULL)
                        query = mapi_error_str(stmt->Dbc->mid);
                if (query != NULL) {
-                       struct errors *e;
+                       const char *e = ODBCErrorType(query);
 
-                       for (e = errors; e->error != NULL; e++)
-                               if (strncmp(query, e->error, strlen(e->error)) 
== 0) {
-                                       addStmtError(stmt, e->msg, query, 0);
-                                       return SQL_ERROR;
-                               }
+                       if (e) {
+                               addStmtError(stmt, e, query, 0);
+                               return SQL_ERROR;
+                       }
                }
                /* General error */
                addStmtError(stmt, "HY000", query, 0);
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
@@ -100,11 +100,16 @@ SQLPrepare_(ODBCStmt *stmt,
        free(s);
        s = NULL;
        if (ret != MOK) {
+               const char *e;
+
                /* 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);
-               addStmtError(stmt, "42000", s, 0);
+               if (s && (e = ODBCErrorType(s)) != NULL)
+                       addStmtError(stmt, e, s, 0);
+               else
+                       addStmtError(stmt, "42000", s, 0);
                return SQL_ERROR;
        }
        if (mapi_rows_affected(hdl) > (1 << 16)) {
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to