Skip to Content.
Sympa Menu

shibboleth-dev - Re: Testing ODBC store

Subject: Shibboleth Developers

List archive

Re: Testing ODBC store


Chronological Thread 
  • From: giacomo tenaglia <>
  • To:
  • Subject: Re: Testing ODBC store
  • Date: Thu, 17 Jan 2008 16:18:04 +0100

On Wed, Jan 16, 2008 at 05:33:57PM +0100, giacomo tenaglia wrote:
> Anyway I'm working at it in order to get the ODBC Store working with
> Oracle, then I'll send it to the list. It's the first time I'm using the
> ODBC API so I'm not sure of what's considered "best practice" in dealing
> with these issues, and I was not able to find any meaningful
> documentation with examples.

Hi,
I finally got the ODBC Store on Oracle to work.

Here you can find the patch to odbc-store.cpp (I only changed the code
of the method ODBCStorageService::createRow).
Two quick notes:
- I've only used SQLBindParam on string variables (context, key, value);
- I don't have figured out if the check on log_error ("supposedly
integrity violation?") had to be present so I blindly included it
after every SQLBindParam().

I hope this can be useful, now I will do some intensive testing of the
store in a load balanced environment and let you know.

giacomo

--
giacomo tenaglia
Technical Student at CERN IT/DES-SIS
CNR Biblioteca d'Area di Bologna - http://biblio.bo.cnr.it
Phone +41 76 5003376 -
sip:
diff -ru shibboleth-2.0/odbc-store/odbc-store.cpp shibboleth-2.0-gt/odbc-store/odbc-store.cpp
--- shibboleth-2.0/odbc-store/odbc-store.cpp	2007-10-22 00:01:10.000000000 +0200
+++ shibboleth-2.0-gt/odbc-store/odbc-store.cpp	2008-01-17 16:07:05.000000000 +0100
@@ -419,17 +419,56 @@
     ODBCConn conn(getHDBC());
     ODBCStatement stmt(getHSTMT(conn));
 
-    // Prepare and exectute insert statement.
+    // Prepare insert statement.
     char *scontext = makeSafeSQL(context);
     char *skey = makeSafeSQL(key);
     char *svalue = makeSafeSQL(value);
-    string q  = string("INSERT ") + table + " VALUES ('" + scontext + "','" + skey + "'," + timebuf + ",1,'" + svalue + "')";
+    string q  = string("INSERT INTO ") + table + " VALUES (?,?," + timebuf + ",1,?)";
+    SQLRETURN sr = SQLPrepare(stmt, (SQLCHAR*)q.c_str(), SQL_NTS);
+    if (!SQL_SUCCEEDED(sr)) {
+        m_log.error("SQLPrepare failed (t=%s, c=%s, k=%s)", table, context, key);
+        if (log_error(stmt, SQL_HANDLE_STMT, "23000"))
+            return false;   // supposedly integrity violation?
+        throw IOException("ODBC StorageService failed to insert record.");
+    } else {
+	m_log.debug("SQLPrepare() succeded. SQL: %s", q.c_str());
+    }
+    
+    // bind string parameters
+    SQLINTEGER b_ind = SQL_NTS;
+    sr = SQLBindParam(stmt, 1, SQL_C_CHAR, SQL_VARCHAR, 0, 0, scontext, &b_ind);
+    if (!SQL_SUCCEEDED(sr)) {
+        m_log.error("SQLBindParam failed (context = %s)", context);
+        if (log_error(stmt, SQL_HANDLE_STMT, "23000"))
+            return false;
+        throw IOException("ODBC StorageService failed to insert record.");
+    } else {
+	m_log.debug("SQLBindParam succeded (context = %s)", context);
+    }
+    sr = SQLBindParam(stmt, 2, SQL_C_CHAR, SQL_VARCHAR, 0, 0, skey, &b_ind);
+    if (!SQL_SUCCEEDED(sr)) {
+        m_log.error("SQLBindParam failed (key = %s)", key);
+        if (log_error(stmt, SQL_HANDLE_STMT, "23000"))
+            return false;
+        throw IOException("ODBC StorageService failed to insert record.");
+    } else {
+	m_log.debug("SQLBindParam succeded (key = %s)", key);
+    }
+    sr = SQLBindParam(stmt, 3, SQL_C_CHAR, SQL_LONGVARCHAR, 0, 0, svalue, &b_ind);
+    if (!SQL_SUCCEEDED(sr)) {
+        m_log.error("SQLBindParam failed (value = %s)", value);
+        if (log_error(stmt, SQL_HANDLE_STMT, "23000"))
+            return false;
+        throw IOException("ODBC StorageService failed to insert record.");
+    } else {
+	m_log.debug("SQLBindParam succeded (value = %s)", value);
+    }
     freeSafeSQL(scontext, context);
     freeSafeSQL(skey, key);
     freeSafeSQL(svalue, value);
-    m_log.debug("SQL: %s", q.c_str());
 
-    SQLRETURN sr=SQLExecDirect(stmt, (SQLCHAR*)q.c_str(), SQL_NTS);
+    // Execute insert statement.
+    sr = SQLExecute(stmt);
     if (!SQL_SUCCEEDED(sr)) {
         m_log.error("insert record failed (t=%s, c=%s, k=%s)", table, context, key);
         if (log_error(stmt, SQL_HANDLE_STMT, "23000"))



Archive powered by MHonArc 2.6.16.

Top of Page