Date: Monday, January 16, 2006 @ 20:01:00
  Author: marc
    Path: /cvsroot/carob/odbsequoia/src

Modified: abstract_item.cpp (1.3 -> 1.4) abstract_item.hpp (1.6 -> 1.7)
          explicit_type.cpp (1.4 -> 1.5)

First implementation of SQLGetDiagFieldW()


-------------------+
 abstract_item.cpp |  104 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 abstract_item.hpp |   16 ++++++++
 explicit_type.cpp |    6 +--
 3 files changed, 121 insertions(+), 5 deletions(-)


Index: odbsequoia/src/abstract_item.cpp
diff -u odbsequoia/src/abstract_item.cpp:1.3 
odbsequoia/src/abstract_item.cpp:1.4
--- odbsequoia/src/abstract_item.cpp:1.3        Thu Jan 12 23:43:38 2006
+++ odbsequoia/src/abstract_item.cpp    Mon Jan 16 20:01:00 2006
@@ -27,6 +27,45 @@
 using namespace ODBSeqNS;
 
 SQLRETURN
+ODBCItem::get_diag_fieldw(SQLSMALLINT RecNumber, SQLSMALLINT DiagIdentifier,
+                          SQLPOINTER DiagInfoPtr,
+                          SQLSMALLINT BufferLength, SQLSMALLINT * 
StringLengthPtr)
+{
+    // all this could be as simple as: "if (RecNumber>0)",
+    // but MS has decided otherwise
+
+    switch (DiagIdentifier) {
+
+        // header fields
+    case SQL_DIAG_CURSOR_ROW_COUNT:
+    case SQL_DIAG_DYNAMIC_FUNCTION:
+    case SQL_DIAG_DYNAMIC_FUNCTION_CODE:
+    case SQL_DIAG_NUMBER:
+    case SQL_DIAG_RETURNCODE:
+    case SQL_DIAG_ROW_COUNT:
+        return get_header_diag_fieldw(DiagIdentifier,
+                                      DiagInfoPtr, BufferLength,  
StringLengthPtr);
+
+        // record fields
+    case SQL_DIAG_CLASS_ORIGIN:
+    case SQL_DIAG_COLUMN_NUMBER:
+    case SQL_DIAG_CONNECTION_NAME:
+    case SQL_DIAG_MESSAGE_TEXT:
+    case SQL_DIAG_NATIVE:
+    case SQL_DIAG_ROW_NUMBER:
+    case SQL_DIAG_SERVER_NAME:
+    case SQL_DIAG_SQLSTATE:
+    case SQL_DIAG_SUBCLASS_ORIGIN:
+        return get_record_diag_fieldw(RecNumber, DiagIdentifier,
+                                      DiagInfoPtr, BufferLength, 
StringLengthPtr);
+
+    default:
+        return SQL_ERROR;
+    }
+}
+
+
+SQLRETURN
 ODBCItem::get_diag_recw(SQLSMALLINT RecNumber,
                         SQLWCHAR * Sqlstate, SQLINTEGER * NativeErrorPtr,
                         SQLWCHAR * MessageText,
@@ -38,7 +77,8 @@
 
     const DiagRecord& this_rec = this->diag_records[RecNumber - 1];
 
-    toSQLW(this_rec.sql_state, Sqlstate, 6, TextLengthPtr /* ignored */);
+    SQLLEN ignored;
+    toSQLW(this_rec.sql_state, Sqlstate, 6, &ignored);
 
     *NativeErrorPtr = this_rec.native_err;
 
@@ -49,6 +89,68 @@
 }
 
 
+SQLRETURN
+ODBCItem::get_record_diag_fieldw(SQLSMALLINT RecNumber, SQLSMALLINT 
DiagIdentifier,
+                                 SQLPOINTER DiagInfoPtr,
+                                 SQLSMALLINT BufferLength, SQLSMALLINT * 
StringLengthPtr)
+{
+    if (RecNumber > (SQLSMALLINT) this->diag_records.size())
+        return SQL_NO_DATA;
+    
+    if (RecNumber < 1)
+        return SQL_ERROR;    
+
+    const DiagRecord& this_rec = this->diag_records[RecNumber - 1];
+
+    switch (DiagIdentifier) {
+
+        SQLSMALLINT wlen;
+
+        // 1. first deal with "standard" records fields,
+        // i.e., same code as get_diag_recw() above
+    case SQL_DIAG_SQLSTATE:
+        // see unixodbc bug on sizes:
+        // <http://permalink.gmane.org/gmane.comp.db.unixodbc.devel/1760>
+        toSQLW(this_rec.sql_state,
+               (SQLWCHAR *) DiagInfoPtr, BufferLength/sizeof(SQLWCHAR), &wlen);
+        *StringLengthPtr = wlen*sizeof(SQLWCHAR);
+        return SQL_SUCCESS;
+        
+    case SQL_DIAG_NATIVE:
+        * (SQLINTEGER *) DiagInfoPtr = this_rec.native_err;
+        return SQL_SUCCESS;
+
+    case SQL_DIAG_MESSAGE_TEXT:
+        toSQLW(this_rec.message,
+               (SQLWCHAR *) DiagInfoPtr, BufferLength/sizeof(SQLWCHAR), &wlen);
+        *StringLengthPtr = wlen*sizeof(SQLWCHAR);
+        return SQL_SUCCESS;
+
+        // 2. fields that cannot be get using get_diag_recw() above
+        // TODO
+
+    default:
+            return SQL_ERROR;
+    }
+
+    return SQL_SUCCESS;
+
+}
+
+SQLRETURN
+ODBCItem::get_header_diag_fieldw(SQLSMALLINT DiagIdentifier,
+                                 SQLPOINTER DiagInfoPtr,
+                                 SQLSMALLINT BufferLength, SQLSMALLINT * 
StringLengthPtr)
+{
+    switch(DiagIdentifier) {
+
+    case SQL_DIAG_NUMBER:
+        * (SQLINTEGER *) DiagInfoPtr = this->diag_records.size();
+        return SQL_SUCCESS;
+    }        
+
+    return SQL_ERROR;
+}
 
 /*
  * Local Variables:
Index: odbsequoia/src/abstract_item.hpp
diff -u odbsequoia/src/abstract_item.hpp:1.6 
odbsequoia/src/abstract_item.hpp:1.7
--- odbsequoia/src/abstract_item.hpp:1.6        Fri Jan 13 00:14:03 2006
+++ odbsequoia/src/abstract_item.hpp    Mon Jan 16 20:01:00 2006
@@ -49,9 +49,25 @@
                   SQLWCHAR * Sqlstate, SQLINTEGER * NativeErrorPtr,
                   SQLWCHAR * MessageText,
                   SQLSMALLINT BufferLength, SQLSMALLINT * TextLengthPtr);
+
+    SQLRETURN
+    get_diag_fieldw(SQLSMALLINT RecNumber, SQLSMALLINT DiagIdentifier,
+                    SQLPOINTER DiagInfoPtr,
+                    SQLSMALLINT BufferLength, SQLSMALLINT * StringLengthPtr);
+
     virtual ~ODBCItem() { };
 
 protected:
+    virtual SQLRETURN
+    get_header_diag_fieldw(SQLSMALLINT DiagIdentifier,
+                           SQLPOINTER DiagInfoPtr,
+                           SQLSMALLINT BufferLength, SQLSMALLINT * 
StringLengthPtr);
+
+    virtual SQLRETURN
+    get_record_diag_fieldw(SQLSMALLINT RecNumber, SQLSMALLINT DiagIdentifier,
+                           SQLPOINTER DiagInfoPtr,
+                           SQLSMALLINT BufferLength, SQLSMALLINT * 
StringLengthPtr);
+
     std::vector<DiagRecord> diag_records;
     ODBCItem& owner;
 };
Index: odbsequoia/src/explicit_type.cpp
diff -u odbsequoia/src/explicit_type.cpp:1.4 
odbsequoia/src/explicit_type.cpp:1.5
--- odbsequoia/src/explicit_type.cpp:1.4        Thu Jan 12 21:15:20 2006
+++ odbsequoia/src/explicit_type.cpp    Mon Jan 16 20:01:00 2006
@@ -124,11 +124,9 @@
      SQLSMALLINT *     StringLengthPtr)
 {
     ODBCItem *item = objectify(HandleType, Handle);
-
-    // Not implemented: debugguer trap
-    item = NULL; delete item;
     
-    return SQL_ERROR;
+    return item->get_diag_fieldw(RecNumber, DiagIdentifier, DiagInfoPtr,
+                                 BufferLength, StringLengthPtr);
 
 }
 

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to