]> git.sur5r.net Git - openldap/commitdiff
various fixes and improvements
authorPierangelo Masarati <ando@openldap.org>
Mon, 2 Sep 2002 19:39:31 +0000 (19:39 +0000)
committerPierangelo Masarati <ando@openldap.org>
Mon, 2 Sep 2002 19:39:31 +0000 (19:39 +0000)
servers/slapd/back-sql/entry-id.c
servers/slapd/back-sql/entry-id.h
servers/slapd/back-sql/modify.c
servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql
servers/slapd/back-sql/schema-map.c
servers/slapd/back-sql/sql-types.h
servers/slapd/back-sql/sql-wrap.c

index e1a45c7f1e9b6b36f8d0a89d4162bb168a508027..ccc4f1391e35d3c7506457e144d203435815d26b 100644 (file)
@@ -164,22 +164,23 @@ backsql_dn2id(
 }
 
 int
-backsql_has_children(
+backsql_count_children(
        backsql_info            *bi,
        SQLHDBC                 dbh,
-       struct berval           *dn )
+       struct berval           *dn,
+       unsigned long           *nchildren )
 {
        SQLHSTMT                sth; 
        BACKSQL_ROW_NTS         row;
        RETCODE                 rc;
-       int                     res;
+       int                     res = LDAP_SUCCESS;
 
-       Debug( LDAP_DEBUG_TRACE, "==>backsql_has_children(): dn='%s'\n", 
+       Debug( LDAP_DEBUG_TRACE, "==>backsql_count_children(): dn='%s'\n", 
                        dn->bv_val, 0, 0 );
 
        if ( dn->bv_len > BACKSQL_MAX_DN_LEN ) {
                Debug( LDAP_DEBUG_TRACE, 
-                       "backsql_has_children(): DN \"%s\" (%ld bytes) "
+                       "backsql_count_children(): DN \"%s\" (%ld bytes) "
                        "exceeds max DN length (%d):\n",
                        dn->bv_val, dn->bv_len, BACKSQL_MAX_DN_LEN );
                return LDAP_OTHER;
@@ -192,7 +193,7 @@ backsql_has_children(
        rc = backsql_Prepare( dbh, &sth, bi->has_children_query, 0 );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, 
-                       "backsql_has_children(): error preparing SQL:\n%s", 
+                       "backsql_count_children(): error preparing SQL:\n%s", 
                        bi->has_children_query, 0, 0);
                backsql_PrintErrors( SQL_NULL_HENV, dbh, sth, rc );
                SQLFreeStmt( sth, SQL_DROP );
@@ -202,7 +203,7 @@ backsql_has_children(
        rc = backsql_BindParamStr( sth, 1, dn->bv_val, BACKSQL_MAX_DN_LEN );
        if ( rc != SQL_SUCCESS) {
                /* end TimesTen */ 
-               Debug( LDAP_DEBUG_TRACE, "backsql_has_children(): "
+               Debug( LDAP_DEBUG_TRACE, "backsql_count_children(): "
                        "error binding dn=\"%s\" parameter:\n", 
                        dn->bv_val, 0, 0 );
                backsql_PrintErrors( SQL_NULL_HENV, dbh, sth, rc );
@@ -212,7 +213,7 @@ backsql_has_children(
 
        rc = SQLExecute( sth );
        if ( rc != SQL_SUCCESS ) {
-               Debug( LDAP_DEBUG_TRACE, "backsql_has_children(): "
+               Debug( LDAP_DEBUG_TRACE, "backsql_count_children(): "
                        "error executing query (\"%s\", \"%s\"):\n", 
                        bi->has_children_query, dn->bv_val, 0 );
                backsql_PrintErrors( SQL_NULL_HENV, dbh, sth, rc );
@@ -224,10 +225,11 @@ backsql_has_children(
        
        rc = SQLFetch( sth );
        if ( BACKSQL_SUCCESS( rc ) ) {
-               if ( strtol( row.cols[ 0 ], NULL, 0 ) > 0 ) {
-                       res = LDAP_COMPARE_TRUE;
-               } else {
-                       res = LDAP_COMPARE_FALSE;
+               char *end;
+
+               *nchildren = strtol( row.cols[ 0 ], &end, 0 );
+               if ( end[ 0 ] != '\0' ) {
+                       res = LDAP_OTHER;
                }
 
        } else {
@@ -237,12 +239,30 @@ backsql_has_children(
 
        SQLFreeStmt( sth, SQL_DROP );
 
-       Debug( LDAP_DEBUG_TRACE, "<==backsql_has_children(): %s\n",
-                       res == LDAP_COMPARE_TRUE ? "yes" : "no", 0, 0 );
+       Debug( LDAP_DEBUG_TRACE, "<==backsql_count_children(): %lu\n",
+                       *nchildren, 0, 0 );
 
        return res;
 }
 
+int
+backsql_has_children(
+       backsql_info            *bi,
+       SQLHDBC                 dbh,
+       struct berval           *dn )
+{
+       unsigned long   nchildren;
+       int             rc;
+
+       rc = backsql_count_children( bi, dbh, dn, &nchildren );
+
+       if ( rc == LDAP_SUCCESS ) {
+               return nchildren > 0 ? LDAP_COMPARE_TRUE : LDAP_COMPARE_FALSE;
+       }
+
+       return rc;
+}
+
 int
 backsql_get_attr_vals( backsql_at_map_rec *at, backsql_srch_info *bsi )
 {
@@ -289,7 +309,7 @@ backsql_get_attr_vals( backsql_at_map_rec *at, backsql_srch_info *bsi )
        rc = SQLFetch( sth );
        for ( ; BACKSQL_SUCCESS( rc ); rc = SQLFetch( sth ) ) {
                for ( i = 0; i < row.ncols; i++ ) {
-                       if ( row.is_null[ i ] > 0 ) {
+                       if ( row.value_len[ i ] > 0 ) {
                                struct berval   bv;
 
                                bv.bv_val = row.cols[ i ];
index c29470b4e8ae8166528e8b3e2b90547542f46676..1481dda39820c080110a6471a8867dfba5a24f7f 100644 (file)
@@ -21,8 +21,12 @@ typedef struct backsql_entryID {
 
 int backsql_dn2id( backsql_info *bi, backsql_entryID *id,
                SQLHDBC dbh, struct berval *dn );
+
+int backsql_count_children( backsql_info *bi, SQLHDBC dbh,
+               struct berval *dn, unsigned long *nchildren );
 int backsql_has_children( backsql_info *bi, SQLHDBC dbh, struct berval *dn );
 
+
 /* returns next */
 backsql_entryID *backsql_free_entryID( backsql_entryID *id, int freeit );
 
index bff2f9f8ed8bf009cc40b39e3f5fde60058d6658..d83eec1837cea07556d54141f443ecb2da0307a1 100644 (file)
 
 static int
 backsql_modify_internal(
-       backsql_info            *bi,
+       BackendDB               *be,
+       Connection              *conn,
+       Operation               *op,
        SQLHDBC                 dbh, 
        backsql_oc_map_rec      *oc,
        backsql_entryID         *e_id,
        Modifications           *modlist,
        const char              **text )
 {
+       backsql_info    *bi = (backsql_info*)be->be_private;
        RETCODE         rc;
        SQLHSTMT        sth;
        Modifications   *ml;
@@ -490,8 +493,8 @@ backsql_modify(
                 * FIXME: we don't want to send back 
                 * excessively detailed messages
                 */
-               send_ldap_result( conn, op, res, "", 
-                               res == LDAP_OTHER ?  "SQL-backend error" : "", 
+               send_ldap_result( conn, op, res, NULL,
+                               res == LDAP_OTHER ?  "SQL-backend error" : "",
                                NULL, NULL );
                return 1;
        }
@@ -500,7 +503,7 @@ backsql_modify(
        if ( res != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_modify(): "
                        "could not lookup entry id\n", 0, 0, 0 );
-               send_ldap_result( conn, op, res , ""
+               send_ldap_result( conn, op, res , NULL
                                res == LDAP_OTHER ? "SQL-backend error" : "",
                                NULL, NULL );
                return 1;
@@ -523,7 +526,7 @@ backsql_modify(
                 * FIXME: we don't want to send back 
                 * excessively detailed messages
                 */
-               send_ldap_result( conn, op, LDAP_OTHER, "",
+               send_ldap_result( conn, op, LDAP_OTHER, NULL,
                                "SQL-backend error", NULL, NULL );
                return 1;
        }
@@ -535,19 +538,13 @@ backsql_modify(
                res = LDAP_INSUFFICIENT_ACCESS;
 
        } else {
-               res = backsql_modify_internal( bi, dbh, oc, &e_id, 
-                               modlist, &text );
+               res = backsql_modify_internal( be, conn, op,
+                               dbh, oc, &e_id, modlist, &text );
        }
 
        if ( res == LDAP_SUCCESS ) {
                /*
                 * Commit only if all operations succeed
-                *
-                * FIXME: backsql_modify_internal() does not fail 
-                * if add/delete operations are not available, or
-                * if a multiple value add actually results in a replace, 
-                * or if a single operation on an attribute fails 
-                * for any reason
                 */
                SQLTransact( SQL_NULL_HENV, dbh, 
                                op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
@@ -555,7 +552,7 @@ backsql_modify(
        send_ldap_result( conn, op, res, NULL, text, NULL, NULL );
        Debug( LDAP_DEBUG_TRACE, "<==backsql_modify()\n", 0, 0, 0 );
 
-       return 0;
+       return op->o_noop;
 }
 
 int
@@ -596,7 +593,7 @@ backsql_modrdn(
                Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
                        "could not get connection handle - exiting\n", 
                        0, 0, 0 );
-               send_ldap_result( conn, op, res, "",
+               send_ldap_result( conn, op, res, NULL,
                                res == LDAP_OTHER ?  "SQL-backend error" : "",
                                NULL, NULL );
                return 1;
@@ -606,7 +603,7 @@ backsql_modrdn(
        if ( res != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
                        "could not lookup entry id\n", 0, 0, 0 );
-               send_ldap_result( conn, op, res, "",
+               send_ldap_result( conn, op, res, NULL,
                                res == LDAP_OTHER ?  "SQL-backend error" : "",
                                NULL, NULL );
                return 1;
@@ -638,7 +635,7 @@ backsql_modrdn(
                Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
                        "parent is \"\" - aborting\n", 0, 0, 0 );
                send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, 
-                               "", "not allowed within namingContext", 
+                               NULL, "not allowed within namingContext", 
                                NULL, NULL );
                goto modrdn_return;
        }
@@ -664,7 +661,8 @@ backsql_modrdn(
                        Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
                                "newSuperior is \"\" - aborting\n", 0, 0, 0 );
                        send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, 
-                                       "", "not allowed within namingContext", 
+                                       NULL,
+                                       "not allowed within namingContext", 
                                        NULL, NULL );
                        goto modrdn_return;
                }
@@ -703,8 +701,9 @@ backsql_modrdn(
                Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
                        "newSuperior is equal to entry being moved "
                        "- aborting\n", 0, 0, 0 );
-               send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", 
-                               NULL, NULL, NULL );
+               send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
+                               NULL, "newSuperior is equal to old DN",
+                               NULL, NULL );
                goto modrdn_return;
        }
 
@@ -713,8 +712,8 @@ backsql_modrdn(
                Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
                        "new dn is invalid ('%s') - aborting\n",
                        new_dn.bv_val, 0, 0 );
-               send_ldap_result( conn, op, LDAP_INVALID_DN_SYNTAX, "", 
-                               NULL, NULL, NULL );
+               send_ldap_result( conn, op, LDAP_INVALID_DN_SYNTAX,
+                               NULL, "new DN is invalid", NULL, NULL );
                goto modrdn_return;
        }
        
@@ -725,7 +724,7 @@ backsql_modrdn(
        if ( res != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
                        "could not lookup old parent entry id\n", 0, 0, 0 );
-               send_ldap_result( conn, op, res, ""
+               send_ldap_result( conn, op, res, NULL
                                res == LDAP_OTHER ? "SQL-backend error" : "",
                                NULL, NULL );
                goto modrdn_return;
@@ -738,7 +737,7 @@ backsql_modrdn(
        if ( res != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
                        "could not lookup new parent entry id\n", 0, 0, 0 );
-               send_ldap_result( conn, op, res, "",
+               send_ldap_result( conn, op, res, NULL,
                                res == LDAP_OTHER ? "SQL-backend error" : "",
                                NULL, NULL );
                goto modrdn_return;
@@ -759,8 +758,8 @@ backsql_modrdn(
                        "failed to delete record from ldap_entries\n",
                        0, 0, 0 );
                backsql_PrintErrors( bi->db_env, dbh, sth, rc );
-               send_ldap_result( conn, op, LDAP_OTHER, "",
-                               "SQL-backend error", NULL, NULL );
+               send_ldap_result( conn, op, LDAP_OTHER,
+                               NULL, "SQL-backend error", NULL, NULL );
                goto modrdn_return;
        }
 
@@ -780,8 +779,8 @@ backsql_modrdn(
                Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
                        "could not insert ldap_entries record\n", 0, 0, 0 );
                backsql_PrintErrors( bi->db_env, dbh, sth, rc );
-               send_ldap_result( conn, op, LDAP_OTHER, "",
-                               "SQL-backend error", NULL, NULL );
+               send_ldap_result( conn, op, LDAP_OTHER,
+                               NULL, "SQL-backend error", NULL, NULL );
                goto modrdn_return;
        }
 
@@ -853,18 +852,13 @@ backsql_modrdn(
        }
 
        oc = backsql_id2oc( bi, e_id.oc_id );
-       res = backsql_modify_internal( bi, dbh, oc, &e_id, mod, &text );
+       res = backsql_modify_internal( be, conn, op, 
+                       dbh, oc, &e_id, mod, &text );
 
        if ( res == LDAP_SUCCESS ) {
 
                /*
                 * Commit only if all operations succeed
-                *
-                * FIXME: backsql_modify_internal() does not fail 
-                * if add/delete operations are not available, or
-                * if a multiple value add actually results in a replace, 
-                * or if a single operation on an attribute fails for any
-                * reason
                 */
                SQLTransact( SQL_NULL_HENV, dbh,
                                op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
@@ -896,10 +890,10 @@ modrdn_return:
                }
        }
 
-       send_ldap_result( conn, op, res, "", text, NULL, NULL );
+       send_ldap_result( conn, op, res, NULL, text, NULL, NULL );
 
        Debug( LDAP_DEBUG_TRACE, "<==backsql_modrdn()\n", 0, 0, 0 );
-       return 0;
+       return op->o_noop;
 }
 
 int
@@ -931,38 +925,44 @@ backsql_add(
        Debug( LDAP_DEBUG_TRACE, "==>backsql_add(): adding entry '%s'\n",
                        e->e_name.bv_val, 0, 0 );
 
-       for ( at = e->e_attrs; at != NULL; at = at->a_next ) {
-               if ( at->a_desc == slap_schema.si_ad_objectClass ) {
-                       if ( global_schemacheck ) {
-                               const char      *text = NULL;
-                               char            textbuf[ 1024 ];
-                               size_t          textlen = sizeof( textbuf );
-                               struct berval   soc;
-
-                               int rc = structural_class( at->a_vals, &soc, 
-                                               NULL, &text, textbuf, textlen );
-                               if ( rc != LDAP_SUCCESS ) {
-                                       break;
-                               }
-                               oc = backsql_name2oc( bi, &soc );
+       /* check schema */
+       if ( global_schemacheck ) {
+               const char      *text = NULL;
+               char            textbuf[ SLAP_TEXT_BUFLEN ] = { '\0' };
+               int             rc;
+               rc = entry_schema_check( be, e, NULL,
+                               &text, textbuf, sizeof( textbuf ) );
+               if ( rc != LDAP_SUCCESS ) {
 
-                       } else {
+                       Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
+                               "entry failed schema check -- aborting\n",
+                               0, 0, 0 );
+                       send_ldap_result( conn, op, rc, NULL,
+                                       "operation not permitted "
+                                       "within namingContext",
+                                       NULL, NULL );
+                       return 1;
+               }
+       }
 
-                               /*
-                                * FIXME: only the objectClass provided first
-                                * is considered when creating a new entry
-                                */
-                               oc = backsql_name2oc( bi, &at->a_vals[ 0 ] );
-                       }
+       /* search structural objectClass */
+       for ( at = e->e_attrs; at != NULL; at = at->a_next ) {
+               if ( at->a_desc == slap_schema.si_ad_structuralObjectClass ) {
                        break;
                }
        }
 
+       /* there must exist */
+       assert( at != NULL );
+
+       /* I guess we should play with sub/supertypes to find a suitable oc */
+       oc = backsql_name2oc( bi, &at->a_vals[0] );
+
        if ( oc == NULL ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
                        "cannot determine objectclass of entry -- aborting\n",
                        0, 0, 0 );
-               send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, "",
+               send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
                                "operation not permitted within namingContext",
                                NULL, NULL );
                return 1;
@@ -972,7 +972,7 @@ backsql_add(
                Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
                        "create procedure is not defined for this objectclass "
                        "- aborting\n", 0, 0, 0 );
-               send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, "",
+               send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
                                "operation not permitted within namingContext",
                                NULL, NULL );
                return 1;
@@ -980,9 +980,9 @@ backsql_add(
        } else if ( BACKSQL_CREATE_NEEDS_SELECT( bi )
                        && oc->create_keyval == NULL ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
-                       "create procedure needs select, but none is defined"
-                       "- aborting\n", 0, 0, 0 );
-               send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, "",
+                       "create procedure needs select procedure, "
+                       "but none is defined - aborting\n", 0, 0, 0 );
+               send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
                                "operation not permitted within namingContext",
                                NULL, NULL );
                return 1;
@@ -993,7 +993,7 @@ backsql_add(
                Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
                        "could not get connection handle - exiting\n", 
                        0, 0, 0 );
-               send_ldap_result( conn, op, prc, "",
+               send_ldap_result( conn, op, prc, NULL,
                                prc == LDAP_OTHER ?  "SQL-backend error" : "",
                                NULL, NULL );
                return 1;
@@ -1007,8 +1007,8 @@ backsql_add(
                Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
                        "entry '%s' exists\n",
                        e->e_name.bv_val, 0, 0 );
-               send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, "", 
-                               NULL, NULL, NULL );
+               send_ldap_result( conn, op, LDAP_ALREADY_EXISTS,
+                               NULL, NULL, NULL, NULL );
                return 1;
        }
 
@@ -1027,7 +1027,8 @@ backsql_add(
                        pdn.bv_val, 0, 0 );
 
                if ( res != LDAP_NO_SUCH_OBJECT ) {
-                       send_ldap_result( conn, op, res, "", NULL, NULL, NULL );
+                       send_ldap_result( conn, op, res,
+                                       NULL, NULL, NULL, NULL );
                        return 1;
                }
 
@@ -1036,7 +1037,7 @@ backsql_add(
                 */
                while ( 1 ) {
                        struct berval   dn;
-                       char            *matched = "";
+                       char            *matched = NULL;
 
                        dn = pdn;
                        dnParent( &dn, &pdn );
@@ -1057,8 +1058,8 @@ backsql_add(
                                /* fail over to next case */
 
                        default:
-                               send_ldap_result( conn, op, res, matched, 
-                                               NULL, NULL, NULL );
+                               send_ldap_result( conn, op, res,
+                                               matched, NULL, NULL, NULL );
                                return 1;
                        } 
                }
@@ -1081,14 +1082,10 @@ backsql_add(
                return 1;
        }
 
-#ifndef BACKSQL_REALLOC_STMT
        rc = SQLAllocStmt( dbh, &sth );
-#else /* BACKSQL_REALLOC_STMT */
-       rc = backsql_Prepare( dbh, &sth, oc->create_proc, 0 );
-#endif /* BACKSQL_REALLOC_STMT */
        if ( rc != SQL_SUCCESS ) {
-               send_ldap_result( conn, op, LDAP_OTHER, "",
-                               "SQL-backend error", NULL, NULL );
+               send_ldap_result( conn, op, LDAP_OTHER,
+                               NULL, "SQL-backend error", NULL, NULL );
                return 1;
        }
 
@@ -1099,24 +1096,23 @@ backsql_add(
 
        Debug( LDAP_DEBUG_TRACE, "backsql_add(): executing '%s'\n",
                oc->create_proc, 0, 0 );
-#ifndef BACKSQL_REALLOC_STMT
        rc = SQLExecDirect( sth, oc->create_proc, SQL_NTS );
-#else /* BACKSQL_REALLOC_STMT */
-       rc = SQLExecute( sth );
-#endif /* BACKSQL_REALLOC_STMT */
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
                        "create_proc execution failed\n", 0, 0, 0 );
                backsql_PrintErrors( bi->db_env, dbh, sth, rc);
                SQLFreeStmt( sth, SQL_DROP );
-               send_ldap_result( conn, op, LDAP_OTHER, "",
-                               "SQL-backend error", NULL, NULL );
+               send_ldap_result( conn, op, LDAP_OTHER,
+                               NULL, "SQL-backend error", NULL, NULL );
                return 1;
        }
+       if ( op->o_noop ) {
+               SQLTransact( SQL_NULL_HENV, dbh, SQL_ROLLBACK );
+       }
 
        if ( !BACKSQL_IS_ADD( oc->expect_return ) ) {
                SWORD           ncols;
-               SQLINTEGER      is_null;
+               SQLINTEGER      value_len;
 
                if ( BACKSQL_CREATE_NEEDS_SELECT( bi ) ) {
 #ifndef BACKSQL_REALLOC_STMT
@@ -1125,16 +1121,18 @@ backsql_add(
                        SQLFreeStmt( sth, SQL_DROP );
                        rc = SQLAllocStmt( dbh, &sth );
                        if ( rc != SQL_SUCCESS ) {
-                               send_ldap_result( conn, op, LDAP_OTHER, "",
-                                       "SQL-backend error", NULL, NULL );
+                               send_ldap_result( conn, op, LDAP_OTHER,
+                                               NULL, "SQL-backend error",
+                                               NULL, NULL );
                                return 1;
                        }
 #endif /* BACKSQL_REALLOC_STMT */
 
                        rc = SQLExecDirect( sth, oc->create_keyval, SQL_NTS );
                        if ( rc != SQL_SUCCESS ) {
-                               send_ldap_result( conn, op, LDAP_OTHER, "",
-                                       "SQL-backend error", NULL, NULL );
+                               send_ldap_result( conn, op, LDAP_OTHER,
+                                               NULL, "SQL-backend error",
+                                               NULL, NULL );
                                return 1;
                        }
                }
@@ -1150,8 +1148,8 @@ backsql_add(
                                0, 0, 0 );
                        backsql_PrintErrors( bi->db_env, dbh, sth, rc);
                        SQLFreeStmt( sth, SQL_DROP );
-                       send_ldap_result( conn, op, LDAP_OTHER, "",
-                                       "SQL-backend error", NULL, NULL );
+                       send_ldap_result( conn, op, LDAP_OTHER,
+                                       NULL, "SQL-backend error", NULL, NULL );
                        return 1;
 
                } else if ( ncols != 1 ) {
@@ -1160,8 +1158,8 @@ backsql_add(
                                ncols, 0, 0 );
                        backsql_PrintErrors( bi->db_env, dbh, sth, rc);
                        SQLFreeStmt( sth, SQL_DROP );
-                       send_ldap_result( conn, op, LDAP_OTHER, "",
-                                       "SQL-backend error", NULL, NULL );
+                       send_ldap_result( conn, op, LDAP_OTHER,
+                                       NULL, "SQL-backend error", NULL, NULL );
                        return 1;
                }
 
@@ -1186,25 +1184,20 @@ backsql_add(
                rc = SQLBindCol( sth, (SQLUSMALLINT)1, SQL_C_ULONG,
                                (SQLPOINTER)&new_keyval, 
                                (SQLINTEGER)sizeof( new_keyval ), 
-                               &is_null );
+                               &value_len );
 
                rc = SQLFetch( sth );
 
-#if 0
-               /*
-                * FIXME: what does is_null mean?
-                */
-               if ( is_null ) {
+               if ( value_len <= 0 ) {
                        Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
-                               "create_proc result is null\n",
+                               "create_proc result is empty?\n",
                                0, 0, 0 );
                        backsql_PrintErrors( bi->db_env, dbh, sth, rc);
                        SQLFreeStmt( sth, SQL_DROP );
-                       send_ldap_result( conn, op, LDAP_OTHER, "",
-                                       "SQL-backend error", NULL, NULL );
+                       send_ldap_result( conn, op, LDAP_OTHER,
+                                       NULL, "SQL-backend error", NULL, NULL );
                        return 1;
                }
-#endif
        }
 
 #ifndef BACKSQL_REALLOC_STMT
@@ -1245,7 +1238,7 @@ backsql_add(
 
                        if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
                                send_ldap_result( conn, op, 
-                                               LDAP_UNWILLING_TO_PERFORM, "",
+                                               LDAP_UNWILLING_TO_PERFORM, NULL,
                                                "operation not permitted "
                                                "within namingContext",
                                                NULL, NULL );
@@ -1263,7 +1256,7 @@ backsql_add(
 
                        if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
                                send_ldap_result( conn, op, 
-                                               LDAP_UNWILLING_TO_PERFORM, "",
+                                               LDAP_UNWILLING_TO_PERFORM, NULL,
                                                "operation not permitted "
                                                "within namingContext",
                                                NULL, NULL );
@@ -1278,9 +1271,8 @@ backsql_add(
                if ( rc != SQL_SUCCESS ) {
 
                        if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
-                               send_ldap_result( conn, op, 
-                                               LDAP_OTHER, "",
-                                               "SQL-backend error",
+                               send_ldap_result( conn, op, LDAP_OTHER,
+                                               NULL, "SQL-backend error",
                                                NULL, NULL );
                                return 1;
                        }
@@ -1347,8 +1339,8 @@ backsql_add(
                                backsql_PrintErrors( bi->db_env, dbh, sth, rc );
 
                                if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
-                                       send_ldap_result( conn, op, 
-                                                       LDAP_OTHER, "",
+                                       send_ldap_result( conn, op, LDAP_OTHER,
+                                                       NULL,
                                                        "SQL-backend error",
                                                        NULL, NULL );
                                        return 1;
@@ -1365,8 +1357,8 @@ backsql_add(
 #ifdef BACKSQL_REALLOC_STMT
        rc = backsql_Prepare( dbh, &sth, bi->insentry_query, 0 );
        if ( rc != SQL_SUCCESS ) {
-               send_ldap_result( conn, op, LDAP_OTHER, "",
-                               "SQL-backend error", NULL, NULL );
+               send_ldap_result( conn, op, LDAP_OTHER,
+                               NULL, "SQL-backend error", NULL, NULL );
                return 1;
        }
 #endif /* BACKSQL_REALLOC_STMT */
@@ -1397,8 +1389,8 @@ backsql_add(
                 * execute delete_proc to delete data added !!!
                 */
                SQLFreeStmt( sth, SQL_DROP );
-               send_ldap_result( conn, op, LDAP_OTHER, "", 
-                               "SQL-backend error", NULL, NULL );
+               send_ldap_result( conn, op, LDAP_OTHER,
+                               NULL, "SQL-backend error", NULL, NULL );
                return 1;
        }
        
@@ -1406,19 +1398,18 @@ backsql_add(
 
        /*
         * Commit only if all operations succeed
-        *
-        * FIXME: backsql_add() does not fail if add operations 
-        * are not available for some attributes, or if
-        * a multiple value add actually results in a replace, 
-        * or if a single operation on an attribute fails 
-        * for any reason
         */
        SQLTransact( SQL_NULL_HENV, dbh, 
-                               op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
+                       op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
+
+       /*
+        * FIXME: NOOP does not work for add -- it works for all 
+        * the other operations, and I don't get the reason :(
+        */
+
+       send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL );
 
-       send_ldap_result( conn, op, LDAP_SUCCESS, "",
-                       NULL, NULL, NULL );
-       return 0;
+       return op->o_noop;
 }
 
 int
@@ -1454,7 +1445,7 @@ backsql_delete(
                        "no write access to parent\n", 
                        0, 0, 0 );
                send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, 
-                               "", NULL, NULL, NULL );
+                               NULL, NULL, NULL, NULL );
                return 1;
 
        }
@@ -1464,7 +1455,7 @@ backsql_delete(
                Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
                        "could not get connection handle - exiting\n", 
                        0, 0, 0 );
-               send_ldap_result( conn, op, res, ""
+               send_ldap_result( conn, op, res, NULL
                                res == LDAP_OTHER ? "SQL-backend error" : "",
                                NULL, NULL );
                return 1;
@@ -1474,7 +1465,7 @@ backsql_delete(
        if ( res != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
                        "could not lookup entry id\n", 0, 0, 0 );
-               send_ldap_result( conn, op, res, "", NULL, NULL, NULL );
+               send_ldap_result( conn, op, res, NULL, NULL, NULL, NULL );
                return 1;
        }
 
@@ -1499,9 +1490,9 @@ backsql_delete(
        oc = backsql_id2oc( bi, e_id.oc_id );
        if ( oc == NULL ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
-                       "cannot determine objectclass of entry "
-                       "-- aborting\n", 0, 0, 0 );
-               send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, "",
+                       "cannot determine objectclass of entry -- aborting\n",
+                       0, 0, 0 );
+               send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
                                "operation not permitted within namingContext",
                                NULL, NULL );
                return 1;
@@ -1511,7 +1502,7 @@ backsql_delete(
                Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
                        "delete procedure is not defined "
                        "for this objectclass - aborting\n", 0, 0, 0 );
-               send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, "",
+               send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
                                "operation not permitted within namingContext",
                                NULL, NULL );
                return 1;
@@ -1537,8 +1528,8 @@ backsql_delete(
                        "delete_proc execution failed\n", 0, 0, 0 );
                backsql_PrintErrors( bi->db_env, dbh, sth, rc );
                SQLFreeStmt( sth, SQL_DROP );
-               send_ldap_result( conn, op, LDAP_OTHER, "",
-                               "SQL-backend error", NULL, NULL );
+               send_ldap_result( conn, op, LDAP_OTHER,
+                               NULL, "SQL-backend error", NULL, NULL );
                return 1;
        }
 #ifndef BACKSQL_REALLOC_STMT
@@ -1557,8 +1548,8 @@ backsql_delete(
                        0, 0, 0 );
                backsql_PrintErrors( bi->db_env, dbh, sth, rc );
                SQLFreeStmt( sth, SQL_DROP );
-               send_ldap_result( conn, op, LDAP_OTHER, "",
-                               "SQL-backend error", NULL, NULL );
+               send_ldap_result( conn, op, LDAP_OTHER,
+                               NULL, "SQL-backend error", NULL, NULL );
                return 1;
        }
        
@@ -1574,11 +1565,11 @@ backsql_delete(
         * for any reason
         */
        SQLTransact( SQL_NULL_HENV, dbh, 
-                               op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
+                       op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
 
-       send_ldap_result( conn, op, LDAP_SUCCESS, "", NULL, NULL, NULL );
+       send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL );
        Debug( LDAP_DEBUG_TRACE, "<==backsql_delete()\n", 0, 0, 0 );
-       return 0;
+       return op->o_noop;
 }
 
 #endif /* SLAPD_SQL */
index 7100a26884c80504a91a6c2d6b7739c561eedcdc..bd82a582a55cec0c09be2c78d079b2cdd7d4aeef 100644 (file)
@@ -48,7 +48,7 @@ insert into ldap_entries (id,dn,oc_map_id,parent,keyval) values (6,'documentTitl
 
 insert into ldap_entry_objclasses (entry_id,oc_name) values (4,'referral');
 
-insert into ldap_referrals (entry_id,url) values (4,'http://localhost');
+insert into ldap_referrals (entry_id,url) values (4,'ldap://localhost/');
 
 -- procedures
 
index d3a7956dcda41e3ce1115b8e08894019d7edceb1..a0194561d05580797daa6b23bd099eef1c53f593 100644 (file)
@@ -239,16 +239,16 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh )
                
                ber_str2bv( oc_row.cols[ 2 ], 0, 1, &oc_map->keytbl );
                ber_str2bv( oc_row.cols[ 3 ], 0, 1, &oc_map->keycol );
-               oc_map->create_proc = ( oc_row.is_null[ 4 ] < 0 ) ? NULL 
+               oc_map->create_proc = ( oc_row.value_len[ 4 ] < 0 ) ? NULL 
                        : ch_strdup( oc_row.cols[ 4 ] );
 
                colnum = 5;
                if ( BACKSQL_CREATE_NEEDS_SELECT( si ) ) {
                        colnum = 6;
-                       oc_map->create_keyval = ( oc_row.is_null[ 5 ] < 0 ) 
+                       oc_map->create_keyval = ( oc_row.value_len[ 5 ] < 0 ) 
                                ? NULL : ch_strdup( oc_row.cols[ 5 ] );
                }
-               oc_map->delete_proc = ( oc_row.is_null[ colnum ] < 0 ) ? NULL 
+               oc_map->delete_proc = ( oc_row.value_len[ colnum ] < 0 ) ? NULL 
                        : ch_strdup( oc_row.cols[ colnum ] );
                oc_map->expect_return = strtol( oc_row.cols[ colnum + 1 ], 
                                NULL, 0 );
@@ -332,7 +332,7 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh )
                        }
                                
                        ber_str2bv( at_row.cols[ 1 ], 0, 1, &at_map->sel_expr );
-                       if ( at_row.is_null[ 8 ] < 0 ) {
+                       if ( at_row.value_len[ 8 ] < 0 ) {
                                at_map->sel_expr_u.bv_val = NULL;
                                at_map->sel_expr_u.bv_len = 0;
                        } else {
@@ -343,17 +343,22 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh )
                        ber_str2bv( at_row.cols[ 2 ], 0, 0, &bv );
                        backsql_merge_from_clause( &at_map->from_tbls, 
                                        &tmpslen, &bv );
-                       if ( at_row.is_null[ 3 ] < 0 ) {
+                       if ( at_row.value_len[ 3 ] < 0 ) {
                                at_map->join_where.bv_val = NULL;
                                at_map->join_where.bv_len = 0;
                        } else {
                                ber_str2bv( at_row.cols[ 3 ], 0, 1, 
                                                &at_map->join_where );
                        }
-                       at_map->add_proc = ( at_row.is_null[ 4 ] < 0 ) ? NULL
-                               : ch_strdup( at_row.cols[4] );
-                       at_map->delete_proc = ( at_row.is_null[ 5 ] < 0 ) ? NULL
-                               : ch_strdup( at_row.cols[ 5 ] );
+                       at_map->add_proc = NULL;
+                       if ( at_row.value_len[ 4 ] > 0 ) {
+                               at_map->add_proc = ch_strdup( at_row.cols[4] );
+                       }
+                       at_map->delete_proc = NULL;
+                       if ( at_row.value_len[ 5 ] > 0 ) {
+                               at_map->delete_proc
+                                       = ch_strdup( at_row.cols[ 5 ] );
+                       }
                        at_map->param_order = strtol( at_row.cols[ 6 ], 
                                        NULL, 0 );
                        at_map->expect_return = strtol( at_row.cols[ 7 ],
index f3eee45ef400f333243336d4ab4319e094f2d9fd..9723d1e09bcf495caf7581cd440cdf9a64b8b665 100644 (file)
@@ -18,7 +18,7 @@ typedef struct {
        BerVarray       col_names;
        UDWORD          *col_prec;
        char            **cols;
-       SQLINTEGER      *is_null;
+       SQLINTEGER      *value_len;
 } BACKSQL_ROW_NTS;
 
 #endif /* __BACKSQL_SQL_TYPES_H__ */
index cde2d30ecb746fc60a95f508258f2ed5f67761ea..f6d3a81cf490899c1f6b02df575ccdf9926bc59a 100644 (file)
@@ -65,13 +65,13 @@ backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout )
        }
 
 #ifdef BACKSQL_TRACE
-       Debug( LDAP_DEBUG_TRACE, "==>_SQLPrepare()\n", 0, 0, 0 );
+       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_TRACE
-       Debug( LDAP_DEBUG_TRACE, "_SQLPrepare(): driver name='%s'\n",
+       Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): driver name='%s'\n",
                        drv_name, 0, 0 );
 #endif /* BACKSQL_TRACE */
 
@@ -89,7 +89,7 @@ backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout )
                rc = SQLSetStmtOption( *sth, SQL_CONCURRENCY, 
                                SQL_CONCUR_ROWVER );
                if ( rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) {
-                       Debug( LDAP_DEBUG_TRACE, "_SQLPrepare(): "
+                       Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): "
                                "SQLSetStmtOption(SQL_CONCURRENCY,"
                                "SQL_CONCUR_ROWVER) failed:\n", 
                                0, 0, 0 );
@@ -108,7 +108,7 @@ backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout )
        }
 
 #ifdef BACKSQL_TRACE
-       Debug( LDAP_DEBUG_TRACE, "<==_SQLPrepare() calling SQLPrepare()\n",
+       Debug( LDAP_DEBUG_TRACE, "<==backsql_Prepare() calling SQLPrepare()\n",
                        0, 0, 0 );
 #endif /* BACKSQL_TRACE */
 
@@ -160,7 +160,7 @@ backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row )
        rc = SQLNumResultCols( sth, &row->ncols );
        if ( rc != SQL_SUCCESS ) {
 #ifdef BACKSQL_TRACE
-               Debug( LDAP_DEBUG_TRACE, "_SQLBindRowAsStrings(): "
+               Debug( LDAP_DEBUG_TRACE, "backsql_BindRowAsStrings(): "
                        "SQLNumResultCols() failed:\n", 0, 0, 0 );
 #endif /* BACKSQL_TRACE */
                
@@ -177,7 +177,7 @@ backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row )
                                sizeof( char * ) );
                row->col_prec = (UDWORD *)ch_calloc( row->ncols,
                                sizeof( UDWORD ) );
-               row->is_null = (SQLINTEGER *)ch_calloc( row->ncols,
+               row->value_len = (SQLINTEGER *)ch_calloc( row->ncols,
                                sizeof( SQLINTEGER ) );
                for ( i = 1; i <= row->ncols; i++ ) {
                        rc = SQLDescribeCol( sth, (SQLSMALLINT)i, &colname[ 0 ],
@@ -213,7 +213,7 @@ backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row )
                                                SQL_C_CHAR,
                                                (SQLPOINTER)row->cols[ i - 1 ],
                                                col_prec + 1,
-                                               &row->is_null[ i - 1 ] );
+                                               &row->value_len[ i - 1 ] );
                        } else {
                                row->cols[ i - 1 ] = (char *)ch_calloc( col_prec + 1, sizeof( char ) );
                                row->col_prec[ i - 1 ] = col_prec;
@@ -221,7 +221,7 @@ backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row )
                                                SQL_C_CHAR,
                                                (SQLPOINTER)row->cols[ i - 1 ],
                                                col_prec + 1,
-                                               &row->is_null[ i - 1 ] );
+                                               &row->value_len[ i - 1 ] );
                        }
                }
 
@@ -247,7 +247,7 @@ backsql_FreeRow( BACKSQL_ROW_NTS *row )
        ber_bvarray_free( row->col_names );
        ldap_charray_free( row->cols );
        free( row->col_prec );
-       free( row->is_null );
+       free( row->value_len );
 
        return SQL_SUCCESS;
 }