]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-sql/sql-wrap.c
should address ITS#3861
[openldap] / servers / slapd / back-sql / sql-wrap.c
index f69caae989e711280e42b05fbc82be70935b0277..61beb4f14a176808d4aafb595f1d440817c9e632 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright 1999-2005 The OpenLDAP Foundation.
  * Portions Copyright 1999 Dmitry Kovalev.
+ * Portions Copyright 2002 Pierangelo Masarati.
  * Portions Copyright 2004 Mark Adamson.
  * All rights reserved.
  *
@@ -16,7 +17,8 @@
  */
 /* ACKNOWLEDGEMENTS:
  * This work was initially developed by Dmitry Kovalev for inclusion
- * by OpenLDAP Software.
+ * by OpenLDAP Software.  Additional significant contributors include
+ * Pierangelo Masarati and Mark Adamson.
  */
 
 #include "portable.h"
@@ -59,8 +61,6 @@ RETCODE
 backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout )
 {
        RETCODE         rc;
-       char            drv_name[ 30 ];
-       SWORD           len;
 
        rc = SQLAllocStmt( dbh, sth );
        if ( rc != SQL_SUCCESS ) {
@@ -71,36 +71,43 @@ backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout )
        Debug( LDAP_DEBUG_TRACE, "==>backsql_Prepare()\n", 0, 0, 0 );
 #endif /* BACKSQL_TRACE */
 
-       SQLGetInfo( dbh, SQL_DRIVER_NAME, drv_name, sizeof( drv_name ), &len );
+#ifdef BACKSQL_MSSQL_WORKAROUND
+       {
+               char            drv_name[ 30 ];
+               SWORD           len;
+
+               SQLGetInfo( dbh, SQL_DRIVER_NAME, drv_name, sizeof( drv_name ), &len );
 
 #ifdef BACKSQL_TRACE
-       Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): driver name=\"%s\"\n",
-                       drv_name, 0, 0 );
+               Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): driver name=\"%s\"\n",
+                               drv_name, 0, 0 );
 #endif /* BACKSQL_TRACE */
 
-       ldap_pvt_str2upper( drv_name );
-       if ( !strncmp( drv_name, "SQLSRV32.DLL", sizeof( drv_name ) ) ) {
-               /*
-                * stupid default result set in MS SQL Server
-                * does not support multiple active statements
-                * on the same connection -- so we are trying 
-                * to make it not to use default result set...
-                */
-               Debug( LDAP_DEBUG_TRACE, "_SQLprepare(): "
-                       "enabling MS SQL Server default result "
-                       "set workaround\n", 0, 0, 0 );
-               rc = SQLSetStmtOption( *sth, SQL_CONCURRENCY, 
-                               SQL_CONCUR_ROWVER );
-               if ( rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) {
-                       Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): "
-                               "SQLSetStmtOption(SQL_CONCURRENCY,"
-                               "SQL_CONCUR_ROWVER) failed:\n", 
-                               0, 0, 0 );
-                       backsql_PrintErrors( SQL_NULL_HENV, dbh, *sth, rc );
-                       SQLFreeStmt( *sth, SQL_DROP );
-                       return rc;
+               ldap_pvt_str2upper( drv_name );
+               if ( !strncmp( drv_name, "SQLSRV32.DLL", STRLENOF( "SQLSRV32.DLL" ) ) ) {
+                       /*
+                        * stupid default result set in MS SQL Server
+                        * does not support multiple active statements
+                        * on the same connection -- so we are trying 
+                        * to make it not to use default result set...
+                        */
+                       Debug( LDAP_DEBUG_TRACE, "_SQLprepare(): "
+                               "enabling MS SQL Server default result "
+                               "set workaround\n", 0, 0, 0 );
+                       rc = SQLSetStmtOption( *sth, SQL_CONCURRENCY, 
+                                       SQL_CONCUR_ROWVER );
+                       if ( rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) {
+                               Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): "
+                                       "SQLSetStmtOption(SQL_CONCURRENCY,"
+                                       "SQL_CONCUR_ROWVER) failed:\n", 
+                                       0, 0, 0 );
+                               backsql_PrintErrors( SQL_NULL_HENV, dbh, *sth, rc );
+                               SQLFreeStmt( *sth, SQL_DROP );
+                               return rc;
+                       }
                }
        }
+#endif /* BACKSQL_MSSQL_WORKAROUND */
 
        if ( timeout > 0 ) {
                Debug( LDAP_DEBUG_TRACE, "_SQLprepare(): "
@@ -119,7 +126,7 @@ backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout )
                        0, 0, 0 );
 #endif /* BACKSQL_TRACE */
 
-       return SQLPrepare( *sth, query, SQL_NTS );
+       return SQLPrepare( *sth, (SQLCHAR *)query, SQL_NTS );
 }
 
 RETCODE
@@ -167,7 +174,7 @@ backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row )
                                        (SQLUINTEGER)( sizeof( colname ) - 1 ),
                                        &name_len, &col_type,
                                        &col_prec, &col_scale, &col_null );
-                       ber_str2bv( colname, 0, 1, &row->col_names[ i - 1 ] );
+                       ber_str2bv( (char *)colname, 0, 1, &row->col_names[ i - 1 ] );
 #ifdef BACKSQL_TRACE
                        Debug( LDAP_DEBUG_TRACE, "backsql_BindRowAsStrings: "
                                "col_name=%s, col_prec[%d]=%d\n",