]> git.sur5r.net Git - openldap/commitdiff
consistently check return value of BindParam*; rework macros to ease parameter bindin...
authorPierangelo Masarati <ando@openldap.org>
Sat, 25 Sep 2004 18:11:06 +0000 (18:11 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sat, 25 Sep 2004 18:11:06 +0000 (18:11 +0000)
servers/slapd/back-sql/add.c
servers/slapd/back-sql/delete.c
servers/slapd/back-sql/entry-id.c
servers/slapd/back-sql/modrdn.c
servers/slapd/back-sql/proto-sql.h
servers/slapd/back-sql/schema-map.c
servers/slapd/back-sql/search.c

index 96bd88c191ff8ddb925ca579f741aebb4ad96e8f..c0918b8ccf1d8b5eea5dfbb88f055d337f208758 100644 (file)
@@ -73,13 +73,7 @@ backsql_modify_delete_all_values(
                return LDAP_SUCCESS;
        }
 
-#ifdef BACKSQL_ARBITRARY_KEY
-       rc = backsql_BindParamStr( asth, 1,
-                       e_id->eid_keyval.bv_val,
-                       BACKSQL_MAX_KEY_LEN );
-#else /* ! BACKSQL_ARBITRARY_KEY */
-       rc = backsql_BindParamID( asth, 1, &e_id->eid_keyval );
-#endif /* ! BACKSQL_ARBITRARY_KEY */
+       rc = backsql_BindParamID( asth, 1, SQL_PARAM_INPUT, &e_id->eid_keyval );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE,
                        "   backsql_modify_delete_all_values(): "
@@ -143,35 +137,59 @@ backsql_modify_delete_all_values(
                                        rs->sr_text = "SQL-backend error";
                                        return rs->sr_err = LDAP_OTHER;
                                }
-                               return LDAP_SUCCESS;
+
+                               continue;
                        }
 
                        if ( BACKSQL_IS_DEL( at->bam_expect_return ) ) {
                                pno = 1;
-                               SQLBindParameter( sth, 1,
-                                       SQL_PARAM_OUTPUT,
-                                       SQL_C_ULONG,
-                                       SQL_INTEGER,
-                                       0, 0, &prc, 0, 0 );
+                               rc = backsql_BindParamInt( sth, 1,
+                                               SQL_PARAM_OUTPUT, &prc );
+                               if ( rc != SQL_SUCCESS ) {
+                                       Debug( LDAP_DEBUG_TRACE,
+                                               "   backsql_modify_delete_all_values(): "
+                                               "error binding output parameter for %s[%d]\n",
+                                               at->bam_ad->ad_cname.bv_val, i, 0 );
+                                       backsql_PrintErrors( bi->db_env, dbh, 
+                                               sth, rc );
+                                       SQLFreeStmt( sth, SQL_DROP );
+
+                                       if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                                               rs->sr_text = "SQL-backend error";
+                                               return rs->sr_err = LDAP_OTHER;
+                                       }
+
+                                       continue;
+                               }
+
                        } else {
                                pno = 0;
                        }
                        po = ( BACKSQL_IS_DEL( at->bam_param_order ) ) > 0;
+                       rc = backsql_BindParamID( sth, pno + 1 + po,
+                               SQL_PARAM_INPUT, &e_id->eid_keyval );
+                       if ( rc != SQL_SUCCESS ) {
+                               Debug( LDAP_DEBUG_TRACE,
+                                       "   backsql_modify_delete_all_values(): "
+                                       "error binding keyval parameter for %s[%d]\n",
+                                       at->bam_ad->ad_cname.bv_val, i, 0 );
+                               backsql_PrintErrors( bi->db_env, dbh, 
+                                       sth, rc );
+                               SQLFreeStmt( sth, SQL_DROP );
+
+                               if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                                       rs->sr_text = "SQL-backend error";
+                                       return rs->sr_err = LDAP_OTHER;
+                               }
+
+                               continue;
+                       }
 #ifdef BACKSQL_ARBITRARY_KEY
-                       SQLBindParameter( sth, pno + 1 + po,
-                               SQL_PARAM_INPUT,
-                               SQL_C_CHAR, SQL_VARCHAR,
-                               0, 0, e_id->eid_keyval.bv_val, 
-                               0, 0 );
                        Debug( LDAP_DEBUG_TRACE,
                                "   backsql_modify_delete_all_values() "
                                "arg%d=%s\n",
                                pno + 1 + po, e_id->eid_keyval.bv_val, 0 );
 #else /* ! BACKSQL_ARBITRARY_KEY */
-                       SQLBindParameter( sth, pno + 1 + po,
-                               SQL_PARAM_INPUT,
-                               SQL_C_ULONG, SQL_INTEGER,
-                               0, 0, &e_id->eid_keyval, 0, 0 );
                        Debug( LDAP_DEBUG_TRACE,
                                "   backsql_modify_delete_all_values() "
                                "arg%d=%lu\n",
@@ -183,11 +201,24 @@ backsql_modify_delete_all_values(
                         * maybe need binary bind?
                         */
                        col_len = strlen( row.cols[ i ] );
-                       SQLBindParameter( sth, pno + 2 - po,
-                               SQL_PARAM_INPUT,
-                               SQL_C_CHAR, SQL_CHAR,
-                               col_len, 0, row.cols[ i ],
-                               col_len, 0 );
+                       rc = backsql_BindParamStr( sth, pno + 2 - po,
+                               SQL_PARAM_INPUT, row.cols[ i ], col_len );
+                       if ( rc != SQL_SUCCESS ) {
+                               Debug( LDAP_DEBUG_TRACE,
+                                       "   backsql_modify_delete_all_values(): "
+                                       "error binding value parameter for %s[%d]\n",
+                                       at->bam_ad->ad_cname.bv_val, i, 0 );
+                               backsql_PrintErrors( bi->db_env, dbh, 
+                                       sth, rc );
+                               SQLFreeStmt( sth, SQL_DROP );
+
+                               if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                                       rs->sr_text = "SQL-backend error";
+                                       return rs->sr_err = LDAP_OTHER;
+                               }
+
+                               continue;
+                       }
         
                        Debug( LDAP_DEBUG_TRACE, 
                                "   backsql_modify_delete_all_values(): "
@@ -393,28 +424,47 @@ add_only:;
 
                                if ( BACKSQL_IS_ADD( at->bam_expect_return ) ) {
                                        pno = 1;
-                                       SQLBindParameter( sth, 1,
-                                               SQL_PARAM_OUTPUT,
-                                               SQL_C_ULONG, SQL_INTEGER,
-                                               0, 0, &prc, 0, 0);
+                                       rc = backsql_BindParamInt( sth, 1,
+                                               SQL_PARAM_OUTPUT, &prc );
+                                       if ( rc != SQL_SUCCESS ) {
+                                               Debug( LDAP_DEBUG_TRACE,
+                                                       "   backsql_modify_internal(): "
+                                                       "error binding output parameter for %s[%d]\n",
+                                                       at->bam_ad->ad_cname.bv_val, i, 0 );
+                                               backsql_PrintErrors( bi->db_env, dbh, 
+                                                       sth, rc );
+                                               SQLFreeStmt( sth, SQL_DROP );
+
+                                               rs->sr_text = "SQL-backend error";
+                                               rs->sr_err = LDAP_OTHER;
+                                               goto done;
+                                       }
+        
                                } else {
                                        pno = 0;
                                }
                                po = ( BACKSQL_IS_ADD( at->bam_param_order ) ) > 0;
+                               rc = backsql_BindParamID( sth, pno + 1 + po,
+                                       SQL_PARAM_INPUT, &e_id->eid_keyval );
+                               if ( rc != SQL_SUCCESS ) {
+                                       Debug( LDAP_DEBUG_TRACE,
+                                               "   backsql_modify_internal(): "
+                                               "error binding keyval parameter for %s[%d]\n",
+                                               at->bam_ad->ad_cname.bv_val, i, 0 );
+                                       backsql_PrintErrors( bi->db_env, dbh, 
+                                               sth, rc );
+                                       SQLFreeStmt( sth, SQL_DROP );
+
+                                       rs->sr_text = "SQL-backend error";
+                                       rs->sr_err = LDAP_OTHER;
+                                       goto done;
+                               }
 #ifdef BACKSQL_ARBITRARY_KEY
-                               SQLBindParameter( sth, pno + 1 + po,
-                                       SQL_PARAM_INPUT, 
-                                       SQL_C_CHAR, SQL_VARCHAR,
-                                       0, 0, e_id->eid_keyval.bv_val, 0, 0 );
                                Debug( LDAP_DEBUG_TRACE,
                                        "   backsql_modify_internal(): "
                                        "arg%d=\"%s\"\n", 
                                        pno + 1 + po, e_id->eid_keyval.bv_val, 0 );
 #else /* ! BACKSQL_ARBITRARY_KEY */
-                               SQLBindParameter( sth, pno + 1 + po,
-                                       SQL_PARAM_INPUT, 
-                                       SQL_C_ULONG, SQL_INTEGER,
-                                       0, 0, &e_id->eid_keyval, 0, 0 );
                                Debug( LDAP_DEBUG_TRACE,
                                        "   backsql_modify_internal(): "
                                        "arg%d=\"%lu\"\n", 
@@ -425,11 +475,21 @@ add_only:;
                                 * check for syntax needed here
                                 * maybe need binary bind?
                                 */
-                               SQLBindParameter( sth, pno + 2 - po,
-                                       SQL_PARAM_INPUT,
-                                       SQL_C_CHAR, SQL_CHAR,
-                                       at_val->bv_len, 0, at_val->bv_val, 
-                                       at_val->bv_len, 0 );
+                               rc = backsql_BindParamBerVal( sth, pno + 2 - po,
+                                       SQL_PARAM_INPUT, at_val );
+                               if ( rc != SQL_SUCCESS ) {
+                                       Debug( LDAP_DEBUG_TRACE,
+                                               "   backsql_modify_internal(): "
+                                               "error binding value parameter for %s[%d]\n",
+                                               at->bam_ad->ad_cname.bv_val, i, 0 );
+                                       backsql_PrintErrors( bi->db_env, dbh, 
+                                               sth, rc );
+                                       SQLFreeStmt( sth, SQL_DROP );
+
+                                       rs->sr_text = "SQL-backend error";
+                                       rs->sr_err = LDAP_OTHER;
+                                       goto done;
+                               }
                                Debug( LDAP_DEBUG_TRACE,
                                        "   backsql_modify_internal(): "
                                        "arg%d=\"%s\"; executing \"%s\"\n", 
@@ -507,34 +567,74 @@ add_only:;
 
                                if ( BACKSQL_IS_DEL( at->bam_expect_return ) ) {
                                        pno = 1;
-                                       SQLBindParameter( sth, 1,
-                                               SQL_PARAM_OUTPUT,
-                                               SQL_C_ULONG, SQL_INTEGER,
-                                               0, 0, &prc, 0, 0 );
+                                       rc = backsql_BindParamInt( sth, 1,
+                                               SQL_PARAM_OUTPUT, &prc );
+                                       if ( rc != SQL_SUCCESS ) {
+                                               Debug( LDAP_DEBUG_TRACE,
+                                                       "   backsql_modify_internal(): "
+                                                       "error binding output parameter for %s[%d]\n",
+                                                       at->bam_ad->ad_cname.bv_val, i, 0 );
+                                               backsql_PrintErrors( bi->db_env, dbh, 
+                                                       sth, rc );
+                                               SQLFreeStmt( sth, SQL_DROP );
+
+                                               rs->sr_text = "SQL-backend error";
+                                               rs->sr_err = LDAP_OTHER;
+                                               goto done;
+                                       }
+
                                } else {
                                        pno = 0;
                                }
                                po = ( BACKSQL_IS_DEL( at->bam_param_order ) ) > 0;
+                               rc = backsql_BindParamID( sth, pno + 1 + po,
+                                       SQL_PARAM_INPUT, &e_id->eid_keyval );
+                               if ( rc != SQL_SUCCESS ) {
+                                       Debug( LDAP_DEBUG_TRACE,
+                                               "   backsql_modify_internal(): "
+                                               "error binding keyval parameter for %s[%d]\n",
+                                               at->bam_ad->ad_cname.bv_val, i, 0 );
+                                       backsql_PrintErrors( bi->db_env, dbh, 
+                                               sth, rc );
+                                       SQLFreeStmt( sth, SQL_DROP );
+
+                                       rs->sr_text = "SQL-backend error";
+                                       rs->sr_err = LDAP_OTHER;
+                                       goto done;
+                               }
 #ifdef BACKSQL_ARBITRARY_KEY
-                               SQLBindParameter( sth, pno + 1 + po,
-                                       SQL_PARAM_INPUT, 
-                                       SQL_C_CHAR, SQL_VARCHAR,
-                                       0, 0, e_id->eid_keyval.bv_val, 0, 0 );
+                               Debug( LDAP_DEBUG_TRACE,
+                                       "   backsql_modify_internal(): "
+                                       "arg%d=\"%s\"\n", 
+                                       pno + 1 + po, e_id->eid_keyval.bv_val, 0 );
 #else /* ! BACKSQL_ARBITRARY_KEY */
-                               SQLBindParameter( sth, pno + 1 + po,
-                                       SQL_PARAM_INPUT, 
-                                       SQL_C_ULONG, SQL_INTEGER,
-                                       0, 0, &e_id->eid_keyval, 0, 0 );
+                               Debug( LDAP_DEBUG_TRACE,
+                                       "   backsql_modify_internal(): "
+                                       "arg%d=\"%lu\"\n", 
+                                       pno + 1 + po, e_id->eid_keyval, 0 );
 #endif /* ! BACKSQL_ARBITRARY_KEY */
 
                                /*
                                 * check for syntax needed here 
                                 * maybe need binary bind?
                                 */
-                               SQLBindParameter( sth, pno + 2 - po,
-                                       SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
-                                       at_val->bv_len, 0, at_val->bv_val, 
-                                       at_val->bv_len, 0 );
+                               rc = backsql_BindParamBerVal( sth, pno + 2 - po,
+                                       SQL_PARAM_INPUT, at_val );
+                               if ( rc != SQL_SUCCESS ) {
+                                       Debug( LDAP_DEBUG_TRACE,
+                                               "   backsql_modify_internal(): "
+                                               "error binding value parameter for %s[%d]\n",
+                                               at->bam_ad->ad_cname.bv_val, i, 0 );
+                                       backsql_PrintErrors( bi->db_env, dbh, 
+                                               sth, rc );
+                                       SQLFreeStmt( sth, SQL_DROP );
+
+                                       if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                                               rs->sr_text = "SQL-backend error";
+                                               rs->sr_err = LDAP_OTHER;
+                                               goto done;
+                                       }
+                               }
 
                                Debug( LDAP_DEBUG_TRACE,
                                        "   backsql_modify_internal(): "
@@ -672,18 +772,49 @@ backsql_add_attr(
 
                if ( BACKSQL_IS_ADD( at_rec->bam_expect_return ) ) {
                        pno = 1;
-                       SQLBindParameter( sth, 1, SQL_PARAM_OUTPUT,
-                                       SQL_C_ULONG, SQL_INTEGER,
-                                       0, 0, &prc, 0, 0 );
+                       rc = backsql_BindParamInt( sth, 1, SQL_PARAM_OUTPUT, &prc );
+                       if ( rc != SQL_SUCCESS ) {
+                               Debug( LDAP_DEBUG_TRACE,
+                                       "   backsql_add_attr(): "
+                                       "error binding output parameter for %s[%d]\n",
+                                       at_rec->bam_ad->ad_cname.bv_val, i, 0 );
+                               backsql_PrintErrors( bi->db_env, dbh, 
+                                       sth, rc );
+                               SQLFreeStmt( sth, SQL_DROP );
+
+                               if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                                       rs->sr_text = "SQL-backend error";
+                                       return rs->sr_err = LDAP_OTHER;
+                               }
+
+                               return LDAP_SUCCESS;
+                       }
+
                } else {
                        pno = 0;
                }
 
                po = ( BACKSQL_IS_ADD( at_rec->bam_param_order ) ) > 0;
                currpos = pno + 1 + po;
-               SQLBindParameter( sth, currpos,
-                               SQL_PARAM_INPUT, SQL_C_ULONG,
-                               SQL_INTEGER, 0, 0, &new_keyval, 0, 0 );
+               rc = backsql_BindParamInt( sth, currpos,
+                               SQL_PARAM_INPUT, &new_keyval );
+               if ( rc != SQL_SUCCESS ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "   backsql_add_attr(): "
+                               "error binding keyval parameter for %s[%d]\n",
+                               at_rec->bam_ad->ad_cname.bv_val, i, 0 );
+                       backsql_PrintErrors( bi->db_env, dbh, 
+                               sth, rc );
+                       SQLFreeStmt( sth, SQL_DROP );
+
+                       if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                               rs->sr_text = "SQL-backend error";
+                               return rs->sr_err = LDAP_OTHER;
+                       }
+
+                       return LDAP_SUCCESS;
+               }
+
                currpos = pno + 2 - po;
 
                /*
@@ -691,8 +822,23 @@ backsql_add_attr(
                 * maybe need binary bind?
                 */
 
-               backsql_BindParamStr( sth, currpos,
-                               at_val->bv_val, at_val->bv_len + 1 );
+               rc = backsql_BindParamBerVal( sth, currpos, SQL_PARAM_INPUT, at_val );
+               if ( rc != SQL_SUCCESS ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "   backsql_add_attr(): "
+                               "error binding value parameter for %s[%d]\n",
+                               at_rec->bam_ad->ad_cname.bv_val, i, 0 );
+                       backsql_PrintErrors( bi->db_env, dbh, 
+                               sth, rc );
+                       SQLFreeStmt( sth, SQL_DROP );
+
+                       if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                               rs->sr_text = "SQL-backend error";
+                               return rs->sr_err = LDAP_OTHER;
+                       }
+
+                       return LDAP_SUCCESS;
+               }
 
 #ifdef LDAP_DEBUG
                snprintf( logbuf, sizeof( logbuf ), "val[%lu], id=%lu",
@@ -958,8 +1104,20 @@ backsql_add( Operation *op, SlapReply *rs )
        }
 
        if ( BACKSQL_IS_ADD( oc->bom_expect_return ) ) {
-               SQLBindParameter( sth, 1, SQL_PARAM_OUTPUT, SQL_C_ULONG, 
-                               SQL_INTEGER, 0, 0, &new_keyval, 0, 0 );
+               rc = backsql_BindParamInt( sth, 1, SQL_PARAM_OUTPUT, &new_keyval );
+               if ( rc != SQL_SUCCESS ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "   backsql_add_attr(): "
+                               "error binding keyval parameter for objectClass %s\n",
+                               oc->bom_oc->soc_cname.bv_val, 0, 0 );
+                       backsql_PrintErrors( bi->db_env, dbh, 
+                               sth, rc );
+                       SQLFreeStmt( sth, SQL_DROP );
+
+                       rs->sr_text = "SQL-backend error";
+                       rs->sr_err = LDAP_OTHER;
+                       goto done;
+               }
        }
 
        Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): executing \"%s\"\n",
@@ -1104,18 +1262,65 @@ backsql_add( Operation *op, SlapReply *rs )
                goto done;
        }
        
-       backsql_BindParamStr( sth, 1, realdn.bv_val, BACKSQL_MAX_DN_LEN );
-       SQLBindParameter( sth, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
-                       0, 0, &oc->bom_id, 0, 0 );
-#ifdef BACKSQL_ARBITRARY_KEY
-       SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
-                       0, 0, parent_id.eid_id.bv_val, 0, 0 );
-#else /* ! BACKSQL_ARBITRARY_KEY */
-       SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
-                       0, 0, &parent_id.eid_id, 0, 0 );
-#endif /* ! BACKSQL_ARBITRARY_KEY */
-       SQLBindParameter( sth, 4, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
-                       0, 0, &new_keyval, 0, 0 );
+       rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &realdn );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_add_attr(): "
+                       "error binding DN parameter for objectClass %s\n",
+                       oc->bom_oc->soc_cname.bv_val, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                       sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               goto done;
+       }
+
+       rc = backsql_BindParamInt( sth, 2, SQL_PARAM_INPUT, &oc->bom_id );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_add_attr(): "
+                       "error binding objectClass ID parameter for objectClass %s\n",
+                       oc->bom_oc->soc_cname.bv_val, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                       sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               goto done;
+       }
+
+       rc = backsql_BindParamID( sth, 3, SQL_PARAM_INPUT, &parent_id.eid_id );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_add_attr(): "
+                       "error binding parent ID parameter for objectClass %s\n",
+                       oc->bom_oc->soc_cname.bv_val, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                       sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               goto done;
+       }
+
+       rc = backsql_BindParamInt( sth, 4, SQL_PARAM_INPUT, &new_keyval );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_add_attr(): "
+                       "error binding entry ID parameter for objectClass %s\n",
+                       oc->bom_oc->soc_cname.bv_val, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                       sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               goto done;
+       }
 
        Debug( LDAP_DEBUG_TRACE, "   backsql_add(): executing \"%s\" for dn \"%s\"\n",
                        bi->insentry_query, op->oq_add.rs_e->e_name.bv_val, 0 );
index 31d0ef8c107a82f560c4f52e68b69a3355d536a6..29e58c07424bef414cd55b34917f5ec03c350ade 100644 (file)
@@ -86,6 +86,7 @@ backsql_delete( Operation *op, SlapReply *rs )
        SQLHDBC                 dbh;
        SQLHSTMT                sth;
        RETCODE                 rc;
+       int                     retval;
        backsql_oc_map_rec      *oc = NULL;
        backsql_entryID         e_id = BACKSQL_ENTRYID_INIT;
        Entry                   e;
@@ -184,21 +185,39 @@ backsql_delete( Operation *op, SlapReply *rs )
 
        if ( BACKSQL_IS_DEL( oc->bom_expect_return ) ) {
                pno = 1;
-               SQLBindParameter( sth, 1, SQL_PARAM_OUTPUT, SQL_C_ULONG,
-                               SQL_INTEGER, 0, 0, &rc, 0, 0 );
+               rc = backsql_BindParamInt( sth, 1, SQL_PARAM_OUTPUT, &retval );
+               if ( rc != SQL_SUCCESS ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "   backsql_delete(): "
+                               "error binding output parameter for objectClass %s\n",
+                               oc->bom_oc->soc_cname.bv_val, 0, 0 );
+                       backsql_PrintErrors( bi->db_env, dbh, 
+                               sth, rc );
+                       SQLFreeStmt( sth, SQL_DROP );
+
+                       rs->sr_text = "SQL-backend error";
+                       rs->sr_err = LDAP_OTHER;
+                       goto done;
+               }
+
        } else {
                pno = 0;
        }
 
-#ifdef BACKSQL_ARBITRARY_KEY
-       SQLBindParameter( sth, pno + 1, SQL_PARAM_INPUT, 
-                       SQL_C_CHAR, SQL_VARCHAR, 0, 0, e_id.eid_keyval.bv_val,
-                       0, 0 );
-#else /* ! BACKSQL_ARBITRARY_KEY */
-       SQLBindParameter( sth, pno + 1, SQL_PARAM_INPUT, 
-                       SQL_C_ULONG, SQL_INTEGER, 0, 0, &e_id.eid_keyval,
-                       0, 0 );
-#endif /* ! BACKSQL_ARBITRARY_KEY */
+       rc = backsql_BindParamID( sth, pno + 1, SQL_PARAM_INPUT, &e_id.eid_keyval );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_delete(): "
+                       "error binding keyval parameter for objectClass %s\n",
+                       oc->bom_oc->soc_cname.bv_val, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                       sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               goto done;
+       }
 
        rc = SQLExecute( sth );
        if ( rc != SQL_SUCCESS ) {
@@ -226,13 +245,22 @@ backsql_delete( Operation *op, SlapReply *rs )
                goto done;
        }
 
-#ifdef BACKSQL_ARBITRARY_KEY
-       SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
-                       0, 0, e_id.eid_id.bv_val, 0, 0 );
-#else /* ! BACKSQL_ARBITRARY_KEY */
-       SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER,
-                       0, 0, &e_id.eid_id, 0, 0 );
-#endif /* ! BACKSQL_ARBITRARY_KEY */
+       rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT, &e_id.eid_id );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_delete(): "
+                       "error binding auxiliary objectClasses "
+                       "entry ID parameter for objectClass %s\n",
+                       oc->bom_oc->soc_cname.bv_val, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                       sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               goto done;
+       }
+
        rc = SQLExecute( sth );
        switch ( rc ) {
        case SQL_NO_DATA:
@@ -267,13 +295,22 @@ backsql_delete( Operation *op, SlapReply *rs )
                goto done;
        }
 
-#ifdef BACKSQL_ARBITRARY_KEY
-       SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
-                       0, 0, e_id.eid_id.bv_val, 0, 0 );
-#else /* ! BACKSQL_ARBITRARY_KEY */
-       SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER,
-                       0, 0, &e_id.eid_id, 0, 0 );
-#endif /* ! BACKSQL_ARBITRARY_KEY */
+       rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT, &e_id.eid_id );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_delete(): "
+                       "error binding referrals entry ID parameter "
+                       "for objectClass %s\n",
+                       oc->bom_oc->soc_cname.bv_val, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                       sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               goto done;
+       }
+
        rc = SQLExecute( sth );
        switch ( rc ) {
        case SQL_NO_DATA:
@@ -308,13 +345,22 @@ backsql_delete( Operation *op, SlapReply *rs )
                goto done;
        }
 
-#ifdef BACKSQL_ARBITRARY_KEY
-       SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
-                       0, 0, e_id.eid_id.bv_val, 0, 0 );
-#else /* ! BACKSQL_ARBITRARY_KEY */
-       SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER,
-                       0, 0, &e_id.eid_id, 0, 0 );
-#endif /* ! BACKSQL_ARBITRARY_KEY */
+       rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT, &e_id.eid_id );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_delete(): "
+                       "error binding entry ID parameter "
+                       "for objectClass %s\n",
+                       oc->bom_oc->soc_cname.bv_val, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                       sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               goto done;
+       }
+
        rc = SQLExecute( sth );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_delete(): "
index 26c2165379e0e3934c7b2b4c33870c5ccaa149ab..0b422d223a49d52e1d5548c9ff57399219b06648 100644 (file)
@@ -139,7 +139,7 @@ backsql_dn2id(
                }
        }
 
-       rc = backsql_BindParamStr( sth, 1, toBind.bv_val, BACKSQL_MAX_DN_LEN );
+       rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &toBind );
        if ( rc != SQL_SUCCESS) {
                /* end TimesTen */ 
                Debug( LDAP_DEBUG_TRACE, "backsql_dn2id(): "
@@ -229,7 +229,7 @@ backsql_count_children(
                return LDAP_OTHER;
        }
 
-       rc = backsql_BindParamStr( sth, 1, dn->bv_val, BACKSQL_MAX_DN_LEN );
+       rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, dn );
        if ( rc != SQL_SUCCESS) {
                /* end TimesTen */ 
                Debug( LDAP_DEBUG_TRACE, "backsql_count_children(): "
@@ -329,12 +329,8 @@ backsql_get_attr_vals( void *v_at, void *v_bsi )
                return 1;
        }
 
-#ifdef BACKSQL_ARBITRARY_KEY
-       rc = backsql_BindParamStr( sth, 1, bsi->bsi_c_eid->eid_keyval.bv_val,
-                      BACKSQL_MAX_KEY_LEN );
-#else /* ! BACKSQL_ARBITRARY_KEY */
-       rc = backsql_BindParamID( sth, 1, &bsi->bsi_c_eid->eid_keyval );
-#endif /* ! BACKSQL_ARBITRARY_KEY */
+       rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT,
+                       &bsi->bsi_c_eid->eid_keyval );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_values(): "
                        "error binding key value parameter\n", 0, 0, 0 );
index 419065ccf6115663a01d5e35a06ad97fd9f37468..83fd4ee0c499f319fbf9fb3bb5e695dab7e5e4bb 100644 (file)
@@ -247,13 +247,22 @@ backsql_modrdn( Operation *op, SlapReply *rs )
                goto done;
        }
 
-#ifdef BACKSQL_ARBITRARY_KEY
-       SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
-                       0, 0, e_id.eid_id.bv_val, 0, 0 );
-#else /* ! BACKSQL_ARBITRARY_KEY */
-       SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER,
-                       0, 0, &e_id.eid_id, 0, 0 );
-#endif /* ! BACKSQL_ARBITRARY_KEY */
+       rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT, &e_id.eid_id );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_delete(): "
+                       "error binding entry ID parameter "
+                       "for objectClass %s\n",
+                       oc->bom_oc->soc_cname.bv_val, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                       sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               goto done;
+       }
+
        rc = SQLExecute( sth );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
@@ -285,20 +294,66 @@ backsql_modrdn( Operation *op, SlapReply *rs )
                goto done;
        }
 
-       backsql_BindParamStr( sth, 1, new_dn.bv_val, BACKSQL_MAX_DN_LEN );
-       SQLBindParameter( sth, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
-                       0, 0, &e_id.eid_oc_id, 0, 0 );
-#ifdef BACKSQL_ARBITRARY_KEY
-       SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
-                       0, 0, new_pe_id.eid_id.bv_val, 0, 0 );
-       SQLBindParameter( sth, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
-                       0, 0, e_id.eid_keyval.bv_val, 0, 0 );
-#else /* ! BACKSQL_ARBITRARY_KEY */
-       SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
-                       0, 0, &new_pe_id.eid_id, 0, 0 );
-       SQLBindParameter( sth, 4, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
-                       0, 0, &e_id.eid_keyval, 0, 0 );
-#endif /* ! BACKSQL_ARBITRARY_KEY */
+       rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &new_dn );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_add_attr(): "
+                       "error binding DN parameter for objectClass %s\n",
+                       oc->bom_oc->soc_cname.bv_val, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                       sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               goto done;
+       }
+
+       rc = backsql_BindParamInt( sth, 2, SQL_PARAM_INPUT, &e_id.eid_oc_id );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_add_attr(): "
+                       "error binding objectClass ID parameter for objectClass %s\n",
+                       oc->bom_oc->soc_cname.bv_val, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                       sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               goto done;
+       }
+
+       rc = backsql_BindParamID( sth, 3, SQL_PARAM_INPUT, &new_pe_id.eid_id );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_add_attr(): "
+                       "error binding parent ID parameter for objectClass %s\n",
+                       oc->bom_oc->soc_cname.bv_val, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                       sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               goto done;
+       }
+
+       rc = backsql_BindParamID( sth, 4, SQL_PARAM_INPUT, &e_id.eid_keyval );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_add_attr(): "
+                       "error binding entry ID parameter for objectClass %s\n",
+                       oc->bom_oc->soc_cname.bv_val, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                       sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               goto done;
+       }
+
        rc = SQLExecute( sth );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
index 8e3fbc3e9994801be5f7492e22bf2c500b378b17..c24e206075e0b738528c1664185fff1e872cc20b 100644 (file)
@@ -160,17 +160,31 @@ void backsql_init_search( backsql_srch_info *bsi,
 
 RETCODE backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char* query, int timeout );
 
-#define backsql_BindParamStr( sth, par_ind, str, maxlen )              \
+#define backsql_BindParamStr( sth, par_ind, io, str, maxlen )          \
        SQLBindParameter( (sth), (SQLUSMALLINT)(par_ind),               \
-                       SQL_PARAM_INPUT,                                \
-                       SQL_C_CHAR, SQL_VARCHAR,                        \
+                       (io), SQL_C_CHAR, SQL_VARCHAR,                  \
                        (SQLUINTEGER)(maxlen), 0, (SQLPOINTER)(str),    \
                        (SQLUINTEGER)(maxlen), NULL )
 
-#define backsql_BindParamID( sth, par_ind, id )                                \
+#define backsql_BindParamBerVal( sth, par_ind, io, bv )                \
+       SQLBindParameter( (sth), (SQLUSMALLINT)(par_ind),               \
+                       (io), SQL_C_CHAR, SQL_VARCHAR,                  \
+                       (SQLUINTEGER)(bv)->bv_len, 0,                   \
+                       (SQLPOINTER)(bv)->bv_val,                       \
+                       (SQLUINTEGER)(bv)->bv_len, NULL )
+
+#define backsql_BindParamInt( sth, par_ind, io, val )                  \
        SQLBindParameter( (sth), (SQLUSMALLINT)(par_ind),               \
-                       SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER,      \
-                       0, 0, (SQLPOINTER)(id), 0, (SQLINTEGER*)NULL )
+                       (io), SQL_C_ULONG, SQL_INTEGER,                 \
+                       0, 0, (SQLPOINTER)(val), 0, (SQLINTEGER*)NULL )
+
+#ifdef BACKSQL_ARBITRARY_KEY
+#define backsql_BindParamID( sth, par_ind, io, id )                    \
+       backsql_BindParamBerVal( (sth), (par_ind), (io), (id) )
+#else /* ! BACKSQL_ARBITRARY_KEY */
+#define backsql_BindParamID( sth, par_ind, io, id )                    \
+       backsql_BindParamInt( (sth), (par_ind), (io), (id) )
+#endif /* ! BACKSQL_ARBITRARY_KEY */
 
 RETCODE backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row );
 
index cd539e8316fc8c272b8065bae29fc6257837ea99..8b2d8f678f4f41985820d4c141dd72be37c1f8d7 100644 (file)
@@ -633,11 +633,12 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh )
                return LDAP_OTHER;
        }
 
-       rc = backsql_BindParamID( sth, 1, &oc_id );
+       rc = backsql_BindParamInt( sth, 1, SQL_PARAM_INPUT, &oc_id );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
                        "error binding param \"oc_id\" for at_query\n", 0, 0, 0 );
                backsql_PrintErrors( si->db_env, dbh, sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
                return LDAP_OTHER;
        }
 
index 52d930b0a982f85e34d2d3eb3e318e16b9b439de..7b1f960e032086728419737811d272dcb1b70330 100644 (file)
@@ -1241,7 +1241,9 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi )
        
        Debug( LDAP_DEBUG_TRACE, "id: '%ld'\n", bsi->bsi_oc->bom_id, 0, 0 );
 
-       if ( backsql_BindParamID( sth, 1, &bsi->bsi_oc->bom_id ) != SQL_SUCCESS ) {
+       rc = backsql_BindParamInt( sth, 1, SQL_PARAM_INPUT,
+                       &bsi->bsi_oc->bom_id );
+       if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
                        "error binding objectclass id parameter\n", 0, 0, 0 );
                bsi->bsi_status = LDAP_OTHER;
@@ -1272,8 +1274,8 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi )
                Debug( LDAP_DEBUG_TRACE, "(base)dn: \"%s\"\n",
                                temp_base_dn, 0, 0 );
 
-               rc = backsql_BindParamStr( sth, 2, temp_base_dn,
-                               BACKSQL_MAX_DN_LEN );
+               rc = backsql_BindParamStr( sth, 2, SQL_PARAM_INPUT,
+                               temp_base_dn, BACKSQL_MAX_DN_LEN );
                if ( rc != SQL_SUCCESS ) {
                        Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
                                "error binding base_dn parameter\n", 0, 0, 0 );
@@ -1331,8 +1333,8 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi )
                Debug( LDAP_DEBUG_TRACE, "(sub)dn: \"%s\"\n", temp_base_dn,
                                0, 0 );
 
-               rc = backsql_BindParamStr( sth, 2, temp_base_dn, 
-                               BACKSQL_MAX_DN_LEN );
+               rc = backsql_BindParamStr( sth, 2, SQL_PARAM_INPUT,
+                               temp_base_dn, BACKSQL_MAX_DN_LEN );
                if ( rc != SQL_SUCCESS ) {
                        Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
                                "error binding base_dn parameter (2)\n",
@@ -1360,15 +1362,12 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi )
 #ifdef BACKSQL_ARBITRARY_KEY
                Debug( LDAP_DEBUG_TRACE, "(one)id: \"%s\"\n",
                                base_id.eid_id.bv_val, 0, 0 );
-
-               rc = backsql_BindParamStr( sth, 2, base_id.eid_id.bv_val,
-                               BACKSQL_MAX_KEY_LEN );
 #else /* ! BACKSQL_ARBITRARY_KEY */
                Debug( LDAP_DEBUG_TRACE, "(one)id: '%lu'\n", base_id.eid_id,
                                0, 0 );
-
-               rc = backsql_BindParamID( sth, 2, &base_id.eid_id );
 #endif /* ! BACKSQL_ARBITRARY_KEY */
+               rc = backsql_BindParamID( sth, 2, SQL_PARAM_INPUT,
+                               &base_id.eid_id );
                backsql_free_entryID( &base_id, 0 );
                if ( rc != SQL_SUCCESS ) {
                        Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "