]> git.sur5r.net Git - openldap/commitdiff
more definitive improvements; now write operations are consistent; plugged some more...
authorPierangelo Masarati <ando@openldap.org>
Wed, 25 Aug 2004 10:41:13 +0000 (10:41 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 25 Aug 2004 10:41:13 +0000 (10:41 +0000)
16 files changed:
servers/slapd/back-sql/add.c
servers/slapd/back-sql/back-sql.h
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/rdbms_depend/ibmdb2/testdb_metadata.sql
servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql
servers/slapd/back-sql/schema-map.c
servers/slapd/back-sql/search.c
servers/slapd/back-sql/sql-wrap.c
servers/slapd/back-sql/util.c
tests/data/sql-read.out
tests/data/sql-write.out
tests/scripts/sql-test000-read
tests/scripts/sql-test900-write

index d561a6ef110d2f983275f88615078c5925419abc..ea216b905e374e6320b9fa50f52ba26bb9643d52 100644 (file)
                || ( (vals) && BER_BVISNULL( &((vals)[ 0 ]) ) ) \
        )
 
+int
+backsql_modify_delete_all_values(
+       Operation               *op,
+       SlapReply               *rs,
+       SQLHDBC                 dbh, 
+       backsql_entryID         *e_id,
+       backsql_at_map_rec      *at )
+{
+       backsql_info    *bi = (backsql_info *)op->o_bd->be_private;
+       RETCODE         rc;
+       SQLHSTMT        asth;
+       BACKSQL_ROW_NTS row;
+
+       rc = backsql_Prepare( dbh, &asth, at->bam_query, 0 );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_modify_delete_all_values(): "
+                       "error preparing query\n", 0, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                               asth, rc );
+
+               if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                       rs->sr_text = "SQL-backend error";
+                       return rs->sr_err = LDAP_OTHER;
+               }
+               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 */
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_modify_delete_all_values(): "
+                       "error binding key value parameter\n",
+                       0, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                               asth, rc );
+               SQLFreeStmt( asth, SQL_DROP );
+
+               if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                       rs->sr_text = "SQL-backend error";
+                       return rs->sr_err = LDAP_OTHER;
+               }
+
+               return LDAP_SUCCESS;
+       }
+                       
+       rc = SQLExecute( asth );
+       if ( !BACKSQL_SUCCESS( rc ) ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_modify_delete_all_values(): "
+                       "error executing attribute query\n",
+                       0, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                               asth, rc );
+               SQLFreeStmt( asth, SQL_DROP );
+
+               if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                       rs->sr_text = "SQL-backend error";
+                       return rs->sr_err = LDAP_OTHER;
+               }
+
+               return LDAP_SUCCESS;
+       }
+
+       backsql_BindRowAsStrings( asth, &row );
+       for ( rc = SQLFetch( asth );
+                       BACKSQL_SUCCESS( rc );
+                       rc = SQLFetch( asth ) )
+       {
+               int                     i;
+               /* first parameter no, parameter order */
+               SQLUSMALLINT            pno, po;
+               /* procedure return code */
+               int                     prc;
+               
+               for ( i = 0; i < row.ncols; i++ ) {
+                       SQLHSTMT        sth;
+                       
+                       rc = backsql_Prepare( dbh, &sth, at->bam_delete_proc, 0 );
+                       if ( rc != SQL_SUCCESS ) {
+                               Debug( LDAP_DEBUG_TRACE,
+                                       "   backsql_modify_delete_all_values(): "
+                                       "error preparing query %s\n",
+                                       at->bam_delete_proc, 0, 0 );
+                               backsql_PrintErrors( bi->db_env, dbh, 
+                                               sth, rc );
+
+                               if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                                       rs->sr_text = "SQL-backend error";
+                                       return rs->sr_err = LDAP_OTHER;
+                               }
+                               return LDAP_SUCCESS;
+                       }
+
+                       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 );
+                       } else {
+                               pno = 0;
+                       }
+                       po = ( BACKSQL_IS_DEL( at->bam_param_order ) ) > 0;
+#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",
+                               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,
+                               0, 0, row.cols[ i ],
+                               strlen( row.cols[ i ] ), 0 );
+        
+                       Debug( LDAP_DEBUG_TRACE, 
+                               "   backsql_modify_delete_all_values(): "
+                               "arg%d=%s; executing \"%s\"\n",
+                               pno + 2 - po, row.cols[ i ],
+                               at->bam_delete_proc );
+                       rc = SQLExecute( sth );
+                       if ( rc != SQL_SUCCESS ) {
+                               Debug( LDAP_DEBUG_TRACE,
+                                       "   backsql_modify_delete_all_values(): "
+                                       "delete_proc "
+                                       "execution failed\n",
+                                       0, 0, 0 );
+                               backsql_PrintErrors( bi->db_env,
+                                               dbh, sth, rc );
+
+                               if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                                       SQLFreeStmt( sth, SQL_DROP );
+                                       rs->sr_text = "SQL-backend error";
+                                       return rs->sr_err = LDAP_OTHER;
+                               }
+                       }
+                       SQLFreeStmt( sth, SQL_DROP );
+               }
+       }
+       backsql_FreeRow( &row );
+       SQLFreeStmt( asth, SQL_DROP );
+
+       return LDAP_SUCCESS;
+}
+
 int
 backsql_modify_internal(
        Operation               *op,
@@ -62,34 +232,38 @@ backsql_modify_internal(
        Debug( LDAP_DEBUG_TRACE, "==>backsql_modify_internal(): "
                "traversing modifications list\n", 0, 0, 0 );
 
-#ifndef BACKSQL_REALLOC_STMT
-       SQLAllocStmt( dbh, &sth );
-#endif /* BACKSQL_REALLOC_STMT */
-
        for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
                AttributeDescription    *ad;
+               int                     sm_op;
+               static char             *sm_ops[] = { "add", "delete", "replace", "increment", NULL };
+
+               BerVarray               sm_values;
+#if 0
+               /* NOTE: some time we'll have to pass 
+                * the normalized values as well */
+               BerVarray               nvalues;
+#endif
                backsql_at_map_rec      *at = NULL;
                struct berval           *at_val;
-               Modification            *c_mod;
                int                     i;
                /* first parameter no, parameter order */
                SQLUSMALLINT            pno, po;
                /* procedure return code */
                int                     prc;
                
-#ifdef BACKSQL_REALLOC_STMT
-               SQLAllocStmt( dbh, &sth );
-#endif /* BACKSQL_REALLOC_STMT */
-
-               c_mod = &ml->sml_mod;
-               ad = c_mod->sm_desc;
+               ad = ml->sml_mod.sm_desc;
+               sm_op = ( ml->sml_mod.sm_op & LDAP_MOD_OP );
+               sm_values = ml->sml_mod.sm_values;
+#if 0
+               sm_nvalues = ml->sml_mod.sm_nvalues;
+#endif
 
                Debug( LDAP_DEBUG_TRACE, "   backsql_modify_internal(): "
-                       "modifying attribute \"%s\" according to "
+                       "modifying attribute \"%s\" (%s) according to "
                        "mappings for objectClass \"%s\"\n",
-                       ad->ad_cname.bv_val, BACKSQL_OC_NAME( oc ), 0 );
+                       ad->ad_cname.bv_val, sm_ops[ sm_op ], BACKSQL_OC_NAME( oc ) );
 
-               if ( backsql_attr_skip( ad, c_mod->sm_values ) ) {
+               if ( backsql_attr_skip( ad, sm_values ) ) {
                        continue;
                }
 
@@ -98,7 +272,7 @@ backsql_modify_internal(
                        Debug( LDAP_DEBUG_TRACE, "   backsql_modify_internal(): "
                                "attribute \"%s\" is not registered "
                                "in objectClass \"%s\"\n",
-                               ad->ad_cname.bv_val, oc, 0 );
+                               ad->ad_cname.bv_val, BACKSQL_OC_NAME( oc ), 0 );
 
                        if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
                                rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
@@ -110,11 +284,8 @@ backsql_modify_internal(
                        continue;
                }
   
-               switch( c_mod->sm_op ) {
+               switch ( sm_op ) {
                case LDAP_MOD_REPLACE: {
-                       SQLHSTMT asth;
-                       BACKSQL_ROW_NTS row;
-                       
                        Debug( LDAP_DEBUG_TRACE, "   backsql_modify_internal(): "
                                "replacing values for attribute \"%s\"\n",
                                at->bam_ad->ad_cname.bv_val, 0, 0 );
@@ -162,137 +333,13 @@ backsql_modify_internal(
                        }
                        
 del_all:
-                       rc = backsql_Prepare( dbh, &asth, at->bam_query, 0 );
-                       if ( rc != SQL_SUCCESS ) {
-                               Debug( LDAP_DEBUG_TRACE,
-                                       "   backsql_modify_internal(): "
-                                       "error preparing query\n", 0, 0, 0 );
-                               backsql_PrintErrors( bi->db_env, dbh, 
-                                               asth, rc );
-
-                               if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
-                                       rs->sr_err = LDAP_OTHER;
-                                       rs->sr_text = "SQL-backend error";
-                                       goto done;
-                               }
-
-                               break;
-                       }
-
-#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 */
-                       if ( rc != SQL_SUCCESS ) {
-                               Debug( LDAP_DEBUG_TRACE,
-                                       "   backsql_modify_internal(): "
-                                       "error binding key value parameter\n",
-                                       0, 0, 0 );
-                               backsql_PrintErrors( bi->db_env, dbh, 
-                                               asth, rc );
-                               SQLFreeStmt( asth, SQL_DROP );
-
-                               if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
-                                       rs->sr_err = LDAP_OTHER;
-                                       rs->sr_text = "SQL-backend error";
-                                       goto done;
-                               }
-
-                               break;
-                       }
-                       
-                       rc = SQLExecute( asth );
-                       if ( !BACKSQL_SUCCESS( rc ) ) {
-                               Debug( LDAP_DEBUG_TRACE,
-                                       "   backsql_modify_internal(): "
-                                       "error executing attribute query\n",
-                                       0, 0, 0 );
-                               backsql_PrintErrors( bi->db_env, dbh, 
-                                               asth, rc );
-                               SQLFreeStmt( asth, SQL_DROP );
-
-                               if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
-                                       rs->sr_err = LDAP_OTHER;
-                                       rs->sr_text = "SQL-backend error";
-                                       goto done;
-                               }
-
-                               break;
-                       }
-
-                       backsql_BindRowAsStrings( asth, &row );
-                       rc = SQLFetch( asth );
-                       for ( ; BACKSQL_SUCCESS( rc ); rc = SQLFetch( asth ) ) {
-                               for ( i = 0; i < row.ncols; i++ ) {
-                                       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 );
-                                       } else {
-                                               pno = 0;
-                                       }
-                                       po = ( BACKSQL_IS_DEL( at->bam_param_order ) ) > 0;
-#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 );
-#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 );
-#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,
-                                               0, 0, row.cols[ i ],
-                                               strlen( row.cols[ i ] ), 0 );
-                        
-                                       Debug( LDAP_DEBUG_TRACE, 
-                                               "   backsql_modify_internal(): "
-                                               "executing \"%s\"\n",
-                                               at->bam_delete_proc, 0, 0 );
-                                       rc = SQLExecDirect( sth,
-                                               at->bam_delete_proc, SQL_NTS );
-                                       if ( rc != SQL_SUCCESS ) {
-                                               Debug( LDAP_DEBUG_TRACE,
-                                                       "   backsql_modify_internal(): "
-                                                       "delete_proc "
-                                                       "execution failed\n",
-                                                       0, 0, 0 );
-                                               backsql_PrintErrors( bi->db_env,
-                                                               dbh, sth, rc );
-
-                                               if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
-                                                       rs->sr_err = LDAP_OTHER;
-                                                       rs->sr_text = "SQL-backend error";
-                                                       goto done;
-                                               }
-                                       }
-#ifdef BACKSQL_REALLOC_STMT
-                                       SQLFreeStmt( sth, SQL_DROP );
-                                       SQLAllocStmt( dbh, &sth );
-#endif /* BACKSQL_REALLOC_STMT */
-                               }
+                       rs->sr_err = backsql_modify_delete_all_values( op, rs, dbh, e_id, at );
+                       if ( rs->sr_err != LDAP_SUCCESS ) {
+                               goto done;
                        }
-                       backsql_FreeRow( &row );
-                       SQLFreeStmt( asth, SQL_DROP );
 
                        /* LDAP_MOD_DELETE gets here if all values must be deleted */
-                       if ( c_mod->sm_op == LDAP_MOD_DELETE ) {
+                       if ( sm_op == LDAP_MOD_DELETE ) {
                                break;
                        }
                }
@@ -301,7 +348,7 @@ del_all:
                 * PASSTHROUGH - to add new attributes -- do NOT add break
                 */
                case LDAP_MOD_ADD:
-               case SLAP_MOD_SOFTADD:
+               /* case SLAP_MOD_SOFTADD: */
 add_only:;
                        if ( at->bam_add_proc == NULL ) {
                                Debug( LDAP_DEBUG_TRACE,
@@ -323,10 +370,10 @@ add_only:;
                        Debug( LDAP_DEBUG_TRACE, "   backsql_modify_internal(): "
                                "adding new values for attribute \"%s\"\n",
                                at->bam_ad->ad_cname.bv_val, 0, 0 );
-                       for ( i = 0, at_val = c_mod->sm_values;
-                                       at_val->bv_val != NULL
-                                       i++, at_val++ ) {
-
+                       for ( i = 0, at_val = sm_values;
+                                       !BER_BVISNULL( at_val )
+                                       i++, at_val++ )
+                       {
                                rc = backsql_Prepare( dbh, &sth, at->bam_add_proc, 0 );
                                if ( rc != SQL_SUCCESS ) {
                                        Debug( LDAP_DEBUG_TRACE,
@@ -386,15 +433,13 @@ add_only:;
                                                        dbh, sth, rc );
 
                                        if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                                               SQLFreeStmt( sth, SQL_DROP );
                                                rs->sr_err = LDAP_OTHER;
                                                rs->sr_text = "SQL-backend error";
                                                goto done;
                                        }
                                }
-#ifdef BACKSQL_REALLOC_STMT
                                SQLFreeStmt( sth, SQL_DROP );
-                               SQLAllocStmt( dbh, &sth );
-#endif /* BACKSQL_REALLOC_STMT */
                        }
                        break;
                        
@@ -416,7 +461,7 @@ add_only:;
                                break;
                        }
 
-                       if ( c_mod->sm_values == NULL ) {
+                       if ( sm_values == NULL ) {
                                Debug( LDAP_DEBUG_TRACE,
                                        "   backsql_modify_internal(): "
                                        "no values given to delete "
@@ -430,9 +475,23 @@ add_only:;
                                "deleting values for attribute \"%s\"\n",
                                at->bam_ad->ad_cname.bv_val, 0, 0 );
 
-                       for ( i = 0, at_val = c_mod->sm_values;
-                                       at_val->bv_val != NULL;
-                                       i++, at_val++ ) {
+                       for ( i = 0, at_val = sm_values;
+                                       !BER_BVISNULL( at_val );
+                                       i++, at_val++ )
+                       {
+                               rc = backsql_Prepare( dbh, &sth, at->bam_delete_proc, 0 );
+                               if ( rc != SQL_SUCCESS ) {
+                                       Debug( LDAP_DEBUG_TRACE,
+                                               "   backsql_modify_internal(): "
+                                               "error preparing delete query\n", 
+                                               0, 0, 0 );
+                                       backsql_PrintErrors( bi->db_env, dbh, sth, rc );
+
+                                       rs->sr_err = LDAP_OTHER;
+                                       rs->sr_text = "SQL-backend error";
+                                       goto done;
+                               }
+
                                if ( BACKSQL_IS_DEL( at->bam_expect_return ) ) {
                                        pno = 1;
                                        SQLBindParameter( sth, 1,
@@ -468,8 +527,7 @@ add_only:;
                                        "   backsql_modify_internal(): "
                                        "executing \"%s\"\n", 
                                        at->bam_delete_proc, 0, 0 );
-                               rc = SQLExecDirect( sth, at->bam_delete_proc,
-                                               SQL_NTS );
+                               rc = SQLExecute( sth );
                                if ( rc != SQL_SUCCESS ) {
                                        Debug( LDAP_DEBUG_TRACE,
                                                "   backsql_modify_internal(): "
@@ -479,33 +537,32 @@ add_only:;
                                                        dbh, sth, rc );
 
                                        if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                                               SQLFreeStmt( sth, SQL_DROP );
                                                rs->sr_err = LDAP_OTHER;
                                                rs->sr_text = "SQL-backend error";
                                                goto done;
                                        }
                                }
-#ifdef BACKSQL_REALLOC_STMT
                                SQLFreeStmt( sth, SQL_DROP );
-                               SQLAllocStmt( dbh, &sth );
-#endif /* BACKSQL_REALLOC_STMT */
+                       }
+                       break;
+
+               case LDAP_MOD_INCREMENT:
+                       Debug( LDAP_DEBUG_TRACE, "   backsql_modify_internal(): "
+                               "increment not supported yet\n", 0, 0, 0 );
+                       if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                               rs->sr_err = LDAP_OTHER;
+                               rs->sr_text = "SQL-backend error";
+                               goto done;
                        }
                        break;
                }
-#ifndef BACKSQL_REALLOC_STMT
-               SQLFreeStmt( sth, SQL_RESET_PARAMS );
-#else /* BACKSQL_REALLOC_STMT */
-               SQLFreeStmt( sth, SQL_DROP );
-#endif /* BACKSQL_REALLOC_STMT */
        }
 
 done:;
-       
-#ifndef BACKSQL_REALLOC_STMT
-       SQLFreeStmt( sth, SQL_DROP );
-#endif /* BACKSQL_REALLOC_STMT */
-
-       Debug( LDAP_DEBUG_TRACE, "<==backsql_modify_internal(): %d%d%s\n",
-               rs->sr_err, rs->sr_text ? ": " : "",
+       Debug( LDAP_DEBUG_TRACE, "<==backsql_modify_internal(): %d%s%s\n",
+               rs->sr_err,
+               rs->sr_text ? ": " : "",
                rs->sr_text ? rs->sr_text : "" );
 
        /*
@@ -519,7 +576,6 @@ backsql_add_attr(
        Operation               *op,
        SlapReply               *rs,
        SQLHDBC                 dbh,
-       SQLHSTMT                *sth,
        backsql_oc_map_rec      *oc,
        Attribute               *at,
        unsigned long           new_keyval )
@@ -534,11 +590,12 @@ backsql_add_attr(
        /* procedure return code */
        int                     prc;
        SQLUSMALLINT            currpos;
+       SQLHSTMT                sth;
 
        at_rec = backsql_ad2at( oc, at->a_desc ); 
   
        if ( at_rec == NULL ) {
-               Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): "
+               Debug( LDAP_DEBUG_TRACE, "   backsql_add_attr(\"%s\"): "
                        "attribute \"%s\" is not registered "
                        "in objectclass \"%s\"\n",
                        op->oq_add.rs_e->e_name.bv_val,
@@ -555,7 +612,7 @@ backsql_add_attr(
        }
        
        if ( at_rec->bam_add_proc == NULL ) {
-               Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): "
+               Debug( LDAP_DEBUG_TRACE, "   backsql_add_attr(\"%s\"): "
                        "add procedure is not defined "
                        "for attribute \"%s\" "
                        "of structuralObjectClass \"%s\"\n",
@@ -573,7 +630,7 @@ backsql_add_attr(
        }
 
        for ( i = 0, at_val = &at->a_vals[ i ];
-                       at_val->bv_val != NULL;
+                       !BER_BVISNULL( at_val );
                        i++, at_val = &at->a_vals[ i ] )
        {
                char logbuf[] = "val[18446744073709551615UL], id=18446744073709551615UL";
@@ -589,8 +646,7 @@ backsql_add_attr(
                        }
                }
 
-#ifdef BACKSQL_REALLOC_STMT
-               rc = backsql_Prepare( dbh, sth, at_rec->bam_add_proc, 0 );
+               rc = backsql_Prepare( dbh, &sth, at_rec->bam_add_proc, 0 );
                if ( rc != SQL_SUCCESS ) {
 
                        if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
@@ -600,11 +656,10 @@ backsql_add_attr(
 
                        return LDAP_SUCCESS;
                }
-#endif /* BACKSQL_REALLOC_STMT */
 
                if ( BACKSQL_IS_ADD( at_rec->bam_expect_return ) ) {
                        pno = 1;
-                       SQLBindParameter( *sth, 1, SQL_PARAM_OUTPUT,
+                       SQLBindParameter( sth, 1, SQL_PARAM_OUTPUT,
                                        SQL_C_ULONG, SQL_INTEGER,
                                        0, 0, &prc, 0, 0 );
                } else {
@@ -613,7 +668,7 @@ backsql_add_attr(
 
                po = ( BACKSQL_IS_ADD( at_rec->bam_param_order ) ) > 0;
                currpos = pno + 1 + po;
-               SQLBindParameter( *sth, currpos,
+               SQLBindParameter( sth, currpos,
                                SQL_PARAM_INPUT, SQL_C_ULONG,
                                SQL_INTEGER, 0, 0, &new_keyval, 0, 0 );
                currpos = pno + 2 - po;
@@ -623,39 +678,32 @@ backsql_add_attr(
                 * maybe need binary bind?
                 */
 
-               backsql_BindParamStr( *sth, currpos,
+               backsql_BindParamStr( sth, currpos,
                                at_val->bv_val, at_val->bv_len + 1 );
 
 #ifdef LDAP_DEBUG
-               snprintf( logbuf, sizeof( logbuf ), "val[%d], id=%ld",
+               snprintf( logbuf, sizeof( logbuf ), "val[%lu], id=%lu",
                                i, new_keyval );
-               Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): "
+               Debug( LDAP_DEBUG_TRACE, "   backsql_add_attr(\"%s\"): "
                        "executing \"%s\" %s\n", 
                        op->oq_add.rs_e->e_name.bv_val,
                        at_rec->bam_add_proc, logbuf );
 #endif
-#ifndef BACKSQL_REALLOC_STMT
-               rc = SQLExecDirect( *sth, at_rec->bam_add_proc, SQL_NTS );
-#else /* BACKSQL_REALLOC_STMT */
-               rc = SQLExecute( *sth );
-#endif /* BACKSQL_REALLOC_STMT */
+               rc = SQLExecute( sth );
                if ( rc != SQL_SUCCESS ) {
                        Debug( LDAP_DEBUG_TRACE,
-                               "   backsql_add(\"%s\"): "
+                               "   backsql_add_attr(\"%s\"): "
                                "add_proc execution failed\n", 
                                op->oq_add.rs_e->e_name.bv_val, 0, 0 );
-                       backsql_PrintErrors( bi->db_env, dbh, *sth, rc );
+                       backsql_PrintErrors( bi->db_env, dbh, sth, rc );
 
                        if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+                               SQLFreeStmt( sth, SQL_DROP );
                                rs->sr_text = "SQL-backend error";
                                return rs->sr_err = LDAP_OTHER;
                        }
                }
-#ifndef BACKSQL_REALLOC_STMT
-               SQLFreeStmt( *sth, SQL_RESET_PARAMS ); 
-#else /* BACKSQL_REALLOC_STMT */
-               SQLFreeStmt( *sth, SQL_DROP );
-#endif /* BACKSQL_REALLOC_STMT */
+               SQLFreeStmt( sth, SQL_DROP );
        }
 
        return LDAP_SUCCESS;
@@ -668,20 +716,13 @@ backsql_add( Operation *op, SlapReply *rs )
        SQLHDBC                 dbh;
        SQLHSTMT                sth;
        unsigned long           new_keyval = 0;
-       long                    i;
        RETCODE                 rc;
        backsql_oc_map_rec      *oc = NULL;
-       backsql_at_map_rec      *at_rec = NULL;
        backsql_entryID         parent_id = BACKSQL_ENTRYID_INIT;
        Entry                   p;
        Attribute               *at,
                                *at_objectClass = NULL;
-       struct berval           *at_val;
        struct berval           pdn;
-       /* first parameter #, parameter order */
-       SQLUSMALLINT            pno, po;
-       /* procedure return code */
-       int                     prc;
        struct berval           realdn = BER_BVNULL,
                                realpdn = BER_BVNULL;
 
@@ -787,6 +828,7 @@ backsql_add( Operation *op, SlapReply *rs )
         */
        if ( be_issuffix( op->o_bd, &op->oq_add.rs_e->e_nname ) ) {
                pdn = slap_empty_bv;
+
        } else {
                dnParent( &op->oq_add.rs_e->e_nname, &pdn );
        }
@@ -816,10 +858,10 @@ backsql_add( Operation *op, SlapReply *rs )
                 *  if not attempting to add entry at suffix or with parent ""
                 */
                if ( ( ( !be_isroot( op ) && !be_shadow_update( op ) )
-                       || pdn.bv_len > 0 ) && !is_entry_glue( op->oq_add.rs_e ) )
+                       || !BER_BVISEMPTY( &pdn ) ) && !is_entry_glue( op->oq_add.rs_e ) )
                {
                        Debug( LDAP_DEBUG_TRACE, "   backsql_add: %s denied\n",
-                               pdn.bv_len == 0 ? "suffix" : "entry at root",
+                               BER_BVISEMPTY( &pdn ) ? "suffix" : "entry at root",
                                0, 0 );
                        /*
                         * Look for matched
@@ -852,7 +894,7 @@ backsql_add( Operation *op, SlapReply *rs )
                                rs->sr_err = backsql_dn2id( bi, NULL, dbh, &realpdn );
                                switch ( rs->sr_err ) {
                                case LDAP_NO_SUCH_OBJECT:
-                                       if ( pdn.bv_len > 0 ) {
+                                       if ( !BER_BVISEMPTY( &pdn ) ) {
                                                break;
                                        }
                                        /* fail over to next case */
@@ -920,6 +962,7 @@ backsql_add( Operation *op, SlapReply *rs )
                rs->sr_text = "SQL-backend error";
                goto done;
        }
+
        if ( op->o_noop ) {
                SQLTransact( SQL_NULL_HENV, dbh, SQL_ROLLBACK );
        }
@@ -929,9 +972,6 @@ backsql_add( Operation *op, SlapReply *rs )
                SQLINTEGER      value_len;
 
                if ( BACKSQL_CREATE_NEEDS_SELECT( bi ) ) {
-#ifndef BACKSQL_REALLOC_STMT
-                       SQLFreeStmt( sth, SQL_RESET_PARAMS );
-#else /* BACKSQL_REALLOC_STMT */
                        SQLFreeStmt( sth, SQL_DROP );
                        rc = SQLAllocStmt( dbh, &sth );
                        if ( rc != SQL_SUCCESS ) {
@@ -939,7 +979,6 @@ backsql_add( Operation *op, SlapReply *rs )
                                rs->sr_text = "SQL-backend error";
                                goto done;
                        }
-#endif /* BACKSQL_REALLOC_STMT */
 
                        rc = SQLExecDirect( sth, oc->bom_create_keyval, SQL_NTS );
                        if ( rc != SQL_SUCCESS ) {
@@ -1012,19 +1051,13 @@ backsql_add( Operation *op, SlapReply *rs )
                }
        }
 
-#ifndef BACKSQL_REALLOC_STMT
-       SQLFreeStmt( sth, SQL_RESET_PARAMS );
-#else /* BACKSQL_REALLOC_STMT */
        SQLFreeStmt( sth, SQL_DROP );
-#endif /* BACKSQL_REALLOC_STMT */
 
        Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): "
                "create_proc returned keyval=%ld\n",
                op->oq_add.rs_e->e_name.bv_val, new_keyval, 0 );
 
        for ( at = op->oq_add.rs_e->e_attrs; at != NULL; at = at->a_next ) {
-               SQLUSMALLINT    currpos;
-
                Debug( LDAP_DEBUG_TRACE, "   backsql_add(): "
                        "adding attribute \"%s\"\n", 
                        at->a_desc->ad_cname.bv_val, 0, 0 );
@@ -1045,20 +1078,18 @@ backsql_add( Operation *op, SlapReply *rs )
                        continue;
                }
 
-               rs->sr_err = backsql_add_attr( op, rs, dbh, &sth, oc, at, new_keyval );
+               rs->sr_err = backsql_add_attr( op, rs, dbh, oc, at, new_keyval );
                if ( rs->sr_err != LDAP_SUCCESS ) {
                        goto done;
                }
        }
 
-#ifdef BACKSQL_REALLOC_STMT
        rc = backsql_Prepare( dbh, &sth, bi->insentry_query, 0 );
        if ( rc != SQL_SUCCESS ) {
                rs->sr_err = LDAP_OTHER;
                rs->sr_text = "SQL-backend error";
                goto done;
        }
-#endif /* BACKSQL_REALLOC_STMT */
        
        backsql_BindParamStr( sth, 1, realdn.bv_val, BACKSQL_MAX_DN_LEN );
        SQLBindParameter( sth, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
@@ -1084,11 +1115,7 @@ backsql_add( Operation *op, SlapReply *rs )
                        "parent_id=%ld, keyval=%ld\n",
                        oc->bom_id, parent_id.eid_id, new_keyval );
 #endif /* ! BACKSQL_ARBITRARY_KEY */
-#ifndef BACKSQL_REALLOC_STMT
-       rc = SQLExecDirect( sth, bi->insentry_query, SQL_NTS );
-#else /* BACKSQL_REALLOC_STMT */
        rc = SQLExecute( sth );
-#endif /* BACKSQL_REALLOC_STMT */
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): "
                        "could not insert ldap_entries record\n",
@@ -1106,7 +1133,7 @@ backsql_add( Operation *op, SlapReply *rs )
 
        /* FIXME: need ldap_entries.id of newly added entry */
        if ( at_objectClass ) {
-               rs->sr_err = backsql_add_attr( op, rs, dbh, &sth, oc, at_objectClass, new_keyval );
+               rs->sr_err = backsql_add_attr( op, rs, dbh, oc, at_objectClass, new_keyval );
                if ( rs->sr_err != LDAP_SUCCESS ) {
                        goto done;
                }
@@ -1120,9 +1147,9 @@ done:;
         */
        if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
                SQLTransact( SQL_NULL_HENV, dbh, SQL_COMMIT );
+
        } else {
                SQLTransact( SQL_NULL_HENV, dbh, SQL_ROLLBACK );
-
        }
 
        /*
index 04f69bb5f21c0f77398513e4332aa3c2dccde663..08370e7abeda60f5b35a98cc9f5a57b82ac2d7d7 100644 (file)
  */
 #undef BACKSQL_ARBITRARY_KEY
 
+/*
+ * define to the appropriate aliasing string
+ */
+#define BACKSQL_ALIASING       "AS "
+/* #define     BACKSQL_ALIASING        "" */
+
+/*
+ * define to the appropriate quoting char
+ */
+/* #define BACKSQL_ALIASING_QUOTE      '"' */
+/* #define BACKSQL_ALIASING_QUOTE      '\'' */
+
 /*
  * API
  */
index 00f42b22ace2130012db4e64b613b5e790ef5ec0..af6b6e12f2b4da426959d48fb703ced1724a0c30 100644 (file)
 #include "ldap_pvt.h"
 #include "proto-sql.h"
 
+typedef struct backsql_delete_attr_t {
+       Operation               *op;
+       SlapReply               *rs;
+       SQLHDBC                 dbh; 
+       backsql_entryID         *e_id;
+} backsql_delete_attr_t;
+
+#define        DELETE_ATTR_STOP        (-6)
+
+static int
+backsql_delete_attr_f( void *v_at, void *v_bda )
+{
+       backsql_at_map_rec      *at = (backsql_at_map_rec *)v_at;
+       backsql_delete_attr_t   *bda = (backsql_delete_attr_t *)v_bda;
+       int                     rc;
+
+       rc = backsql_modify_delete_all_values( bda->op,
+                       bda->rs, bda->dbh, bda->e_id, at );
+
+       if ( rc != LDAP_SUCCESS ) {
+               return BACKSQL_AVL_STOP;
+       }
+
+       return BACKSQL_AVL_CONTINUE;
+}
+
+static int
+backsql_delete_all_attrs(
+       Operation               *op,
+       SlapReply               *rs,
+       SQLHDBC                 dbh, 
+       backsql_entryID         *e_id,
+       backsql_oc_map_rec      *oc )
+{
+       backsql_delete_attr_t   bda;
+       int                     rc;
+
+       bda.op = op;
+       bda.rs = rs;
+       bda.dbh = dbh;
+       bda.e_id = e_id;
+       
+       rc = avl_apply( oc->bom_attrs, backsql_delete_attr_f, &bda,
+                       BACKSQL_AVL_STOP, AVL_INORDER );
+       if ( rc == BACKSQL_AVL_STOP ) {
+               return rs->sr_err;
+       }
+
+       return LDAP_SUCCESS;
+}
+
 int
 backsql_delete( Operation *op, SlapReply *rs )
 {
@@ -114,8 +165,6 @@ backsql_delete( Operation *op, SlapReply *rs )
                goto done;
        }
 
-       SQLAllocStmt( dbh, &sth );
-
        rc = backsql_Prepare( dbh, &sth, oc->bom_delete_proc, 0 );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE,
@@ -157,15 +206,15 @@ backsql_delete( Operation *op, SlapReply *rs )
                rs->sr_text = "SQL-backend error";
                goto done;
        }
-#ifndef BACKSQL_REALLOC_STMT
-       SQLFreeStmt( sth, SQL_RESET_PARAMS );
-#else /* BACKSQL_REALLOC_STMT */
        SQLFreeStmt( sth, SQL_DROP );
-       SQLAllocStmt( dbh, &sth );
-#endif /* BACKSQL_REALLOC_STMT */
 
-       /* we should do the same for ldap_entry_objclasses and ldap_referrals,
-        * for those RDBMSes that do not allow stored procedures... */
+       /* avl_apply ... */
+       rs->sr_err = backsql_delete_all_attrs( op, rs, dbh, &e_id, oc );
+       if ( rs->sr_err != LDAP_SUCCESS ) {
+               goto done;
+       }
+
+       /* delete "auxiliary" objectClasses, if any... */
        rc = backsql_Prepare( dbh, &sth, bi->delobjclasses_query, 0 );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE,
@@ -206,6 +255,7 @@ backsql_delete( Operation *op, SlapReply *rs )
        }
        SQLFreeStmt( sth, SQL_DROP );
 
+       /* delete referrals, if any... */
        rc = backsql_Prepare( dbh, &sth, bi->delreferrals_query, 0 );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE,
@@ -246,6 +296,7 @@ backsql_delete( Operation *op, SlapReply *rs )
        }
        SQLFreeStmt( sth, SQL_DROP );
 
+       /* delete entry... */
        rc = backsql_Prepare( dbh, &sth, bi->delentry_query, 0 );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE,
index b6cecd659e88096aa545998353580625291678c8..26c2165379e0e3934c7b2b4c33870c5ccaa149ab 100644 (file)
@@ -344,11 +344,11 @@ backsql_get_attr_vals( void *v_at, void *v_bsi )
 #ifdef BACKSQL_TRACE
 #ifdef BACKSQL_ARBITRARY_KEY
        Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_values(): "
-               "query=%s keyval=%s\n", at->bam_query,
+               "query=\"%s\" keyval=%s\n", at->bam_query,
                bsi->bsi_c_eid->eid_keyval.bv_val, 0 );
 #else /* !BACKSQL_ARBITRARY_KEY */
        Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_values(): "
-               "query=%s keyval=%d\n", at->bam_query,
+               "query=\"%s\" keyval=%d\n", at->bam_query,
                bsi->bsi_c_eid->eid_keyval, 0 );
 #endif /* ! BACKSQL_ARBITRARY_KEY */
 #endif /* BACKSQL_TRACE */
index ee05c7d8f1c8e6af3723524de65d696083f8fd77..c79d6cb5ce2f1e39238a051aa9a276ac4df9a853 100644 (file)
@@ -39,16 +39,17 @@ backsql_modrdn( Operation *op, SlapReply *rs )
        RETCODE                 rc;
        backsql_entryID         e_id = BACKSQL_ENTRYID_INIT,
                                pe_id = BACKSQL_ENTRYID_INIT,
-                               new_pid = BACKSQL_ENTRYID_INIT;
+                               new_pe_id = BACKSQL_ENTRYID_INIT;
        backsql_oc_map_rec      *oc = NULL;
-       struct berval           p_dn, p_ndn,
+       struct berval           p_dn = BER_BVNULL, p_ndn = BER_BVNULL,
                                *new_pdn = NULL, *new_npdn = NULL,
-                               new_dn, new_ndn;
+                               new_dn = BER_BVNULL, new_ndn = BER_BVNULL;
        LDAPRDN                 new_rdn = NULL;
        LDAPRDN                 old_rdn = NULL;
        Entry                   e;
-       Modifications           *mod;
+       Modifications           *mod = NULL;
        struct berval           *newSuperior = op->oq_modrdn.rs_newSup;
+       char                    *next;
  
        Debug( LDAP_DEBUG_TRACE, "==>backsql_modrdn() renaming entry \"%s\", "
                        "newrdn=\"%s\", newSuperior=\"%s\"\n",
@@ -174,9 +175,10 @@ backsql_modrdn( Operation *op, SlapReply *rs )
                goto modrdn_return;
        }
 
-       build_new_dn( &new_dn, new_pdn, &op->oq_modrdn.rs_newrdn, NULL );
+       build_new_dn( &new_dn, new_pdn, &op->oq_modrdn.rs_newrdn,
+                       op->o_tmpmemctx );
        rs->sr_err = dnNormalize( 0, NULL, NULL, &new_dn, &new_ndn,
-               op->o_tmpmemctx );
+                       op->o_tmpmemctx );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
                        "new dn is invalid (\"%s\") - aborting\n",
@@ -209,7 +211,7 @@ backsql_modrdn( Operation *op, SlapReply *rs )
 
        backsql_free_entryID( &pe_id, 0 );
 
-       rs->sr_err = backsql_dn2id( bi, &new_pid, dbh, new_npdn );
+       rs->sr_err = backsql_dn2id( bi, &new_pe_id, dbh, new_npdn );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
                        "could not lookup new parent entry id\n", 0, 0, 0 );
@@ -221,16 +223,29 @@ backsql_modrdn( Operation *op, SlapReply *rs )
 
 #ifdef BACKSQL_ARBITRARY_KEY
        Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
-               "new parent entry id=%s\n", new_pid.eid_id.bv_val, 0, 0 );
+               "new parent entry id=%s\n", new_pe_id.eid_id.bv_val, 0, 0 );
 #else /* ! BACKSQL_ARBITRARY_KEY */
        Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
-               "new parent entry id=%ld\n", new_pid.eid_id, 0, 0 );
+               "new parent entry id=%ld\n", new_pe_id.eid_id, 0, 0 );
 #endif /* ! BACKSQL_ARBITRARY_KEY */
 
  
        Debug(  LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
                "executing delentry_query\n", 0, 0, 0 );
-       SQLAllocStmt( dbh, &sth );
+
+       rc = backsql_Prepare( dbh, &sth, bi->delentry_query, 0 );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_modrdn(): "
+                       "error preparing delentry_query\n", 0, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                               sth, rc );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               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 );
@@ -238,54 +253,71 @@ backsql_modrdn( Operation *op, SlapReply *rs )
        SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER,
                        0, 0, &e_id.eid_id, 0, 0 );
 #endif /* ! BACKSQL_ARBITRARY_KEY */
-       rc = SQLExecDirect( sth, bi->delentry_query, SQL_NTS );
+       rc = SQLExecute( sth );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
                        "failed to delete record from ldap_entries\n",
                        0, 0, 0 );
                backsql_PrintErrors( bi->db_env, dbh, sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
                rs->sr_err = LDAP_OTHER;
                rs->sr_text = "SQL-backend error";
                send_ldap_result( op, rs );
-               goto modrdn_return;
+               goto done;
        }
 
-       SQLFreeStmt( sth, SQL_RESET_PARAMS );
+       SQLFreeStmt( sth, SQL_DROP );
 
        Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
                "executing insentry_query\n", 0, 0, 0 );
+
+       rc = backsql_Prepare( dbh, &sth, bi->insentry_query, 0 );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_modrdn(): "
+                       "error preparing insentry_query\n", 0, 0, 0 );
+               backsql_PrintErrors( bi->db_env, dbh, 
+                               sth, rc );
+
+               rs->sr_text = "SQL-backend error";
+               rs->sr_err = LDAP_OTHER;
+               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_pid.eid_id.bv_val, 0, 0 );
+                       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_pid.eid_id, 0, 0 );
+                       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 = SQLExecDirect( sth, bi->insentry_query, SQL_NTS );
+       rc = SQLExecute( sth );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
                        "could not insert ldap_entries record\n", 0, 0, 0 );
                backsql_PrintErrors( bi->db_env, dbh, sth, rc );
+               SQLFreeStmt( sth, SQL_DROP );
                rs->sr_err = LDAP_OTHER;
                rs->sr_text = "SQL-backend error";
                send_ldap_result( op, rs );
-               goto modrdn_return;
+               goto done;
        }
+       SQLFreeStmt( sth, SQL_DROP );
 
        /*
         * Get attribute type and attribute value of our new rdn,
         * we will need to add that to our new entry
         */
-       if ( ldap_bv2rdn( &op->oq_modrdn.rs_newrdn, &new_rdn,
-                               (char **)&rs->sr_text, 
-                               LDAP_DN_FORMAT_LDAP ) ) {
+       if ( ldap_bv2rdn( &op->oq_modrdn.rs_newrdn, &new_rdn, &next, 
+                               LDAP_DN_FORMAT_LDAP ) )
+       {
 #ifdef NEW_LOGGING
                LDAP_LOG ( OPERATION, ERR, 
                        "   backsql_modrdn: can't figure out "
@@ -298,7 +330,7 @@ backsql_modrdn( Operation *op, SlapReply *rs )
                        0, 0, 0 );
 #endif
                rs->sr_err = LDAP_INVALID_DN_SYNTAX;
-               goto modrdn_return;
+               goto done;
        }
 
 #ifdef NEW_LOGGING
@@ -316,9 +348,9 @@ backsql_modrdn( Operation *op, SlapReply *rs )
 #endif
 
        if ( op->oq_modrdn.rs_deleteoldrdn ) {
-               if ( ldap_bv2rdn( &op->o_req_dn, &old_rdn,
-                                       (char **)&rs->sr_text,
-                                       LDAP_DN_FORMAT_LDAP ) ) {
+               if ( ldap_bv2rdn( &op->o_req_dn, &old_rdn, &next,
+                                       LDAP_DN_FORMAT_LDAP ) )
+               {
 #ifdef NEW_LOGGING
                        LDAP_LOG ( OPERATION, ERR, 
                                "   backsql_modrdn: can't figure out "
@@ -331,7 +363,7 @@ backsql_modrdn( Operation *op, SlapReply *rs )
                                0, 0, 0 );
 #endif
                        rs->sr_err = LDAP_OTHER;
-                       goto modrdn_return;             
+                       goto done;              
                }
        }
 
@@ -350,24 +382,24 @@ backsql_modrdn( Operation *op, SlapReply *rs )
        oc = backsql_id2oc( bi, e_id.eid_oc_id );
        rs->sr_err = backsql_modify_internal( op, rs, dbh, oc, &e_id, mod );
 
-       if ( rs->sr_err == LDAP_SUCCESS ) {
+done:;
+       /*
+        * Commit only if all operations succeed
+        */
+       if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
+               SQLTransact( SQL_NULL_HENV, dbh, SQL_COMMIT );
 
-               /*
-                * Commit only if all operations succeed
-                */
-               SQLTransact( SQL_NULL_HENV, dbh,
-                               op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
+       } else {
+               SQLTransact( SQL_NULL_HENV, dbh, SQL_ROLLBACK );
        }
 
-modrdn_return:
-       SQLFreeStmt( sth, SQL_DROP );
-
-       if ( new_dn.bv_val ) {
-               ch_free( new_dn.bv_val );
+modrdn_return:;
+       if ( !BER_BVISNULL( &new_dn ) ) {
+               slap_sl_free( new_dn.bv_val, op->o_tmpmemctx );
        }
        
-       if ( new_ndn.bv_val ) {
-               ch_free( new_ndn.bv_val );
+       if ( !BER_BVISNULL( &new_ndn ) ) {
+               slap_sl_free( new_ndn.bv_val, op->o_tmpmemctx );
        }
        
        /* LDAP v2 supporting correct attribute handling. */
@@ -379,14 +411,14 @@ modrdn_return:
        }
        if ( mod != NULL ) {
                Modifications *tmp;
-               for (; mod; mod=tmp ) {
+               for (; mod; mod = tmp ) {
                        tmp = mod->sml_next;
                        free( mod );
                }
        }
 
-       if ( new_pid.eid_dn.bv_val ) {
-               backsql_free_entryID( &pe_id, 0 );
+       if ( new_pe_id.eid_dn.bv_val ) {
+               backsql_free_entryID( &new_pe_id, 0 );
        }
 
        send_ldap_result( op, rs );
index 63eb5ac9a41a587d07dc8efb4addf345c9f31790..8e3fbc3e9994801be5f7492e22bf2c500b378b17 100644 (file)
 /*
  * add.c
  */
+int backsql_modify_delete_all_values(
+       Operation               *op,
+       SlapReply               *rs,
+       SQLHDBC                 dbh, 
+       backsql_entryID         *e_id,
+       backsql_at_map_rec      *at );
+
 int backsql_modify_internal(
        Operation               *op,
        SlapReply               *rs,
index 7ce5bf79ebd49f20c8629556748503c64611b22c..33c509a13b1bbbbd35c9370071532560f9231b6a 100644 (file)
 --      delete_proc     a procedure to delete the entry; it takes "keytbl.keycol" of the row to be deleted
 --      expect_return   a bitmap that marks whether create_proc (1) and delete_proc (2) return a value or not
 insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,create_keyval,delete_proc,expect_return)
-values (1,'inetOrgPerson','persons','id','insert into persons (id,name,surname) values ((select max(id)+1 from persons),'''','''')',
-       'select max(id) from persons','delete from persons where id=?',0);
+values (1,'inetOrgPerson','persons','id','INSERT INTO persons (id,name,surname) VALUES ((SELECT max(id)+1 FROM persons),'''','''')',
+       'SELECT max(id) FROM persons','DELETE FROM persons WHERE id=?',0);
 
 insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,create_keyval,delete_proc,expect_return)
-values (2,'document','documents','id','insert into documents (id,title,abstract) values ((select max(id)+1 from documents),'''','''')',
-       'select max(id) from documents','delete from documents where id=?',0);
+values (2,'document','documents','id','INSERT INTO documents (id,title,abstract) VALUES ((SELECT max(id)+1 FROM documents),'''','''')',
+       'SELECT max(id) FROM documents','DELETE FROM documents WHERE id=?',0);
 
 insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,create_keyval,delete_proc,expect_return)
-values (3,'organization','institutes','id','insert into institutes (id,name) values ((select max(id)+1 from institutes),'''')',
-       'select max(id) from institutes','delete from institutes where id=?',0);
+values (3,'organization','institutes','id','INSERT INTO institutes (id,name) VALUES ((SELECT max(id)+1 FROM institutes),'''')',
+       'SELECT max(id) FROM institutes','DELETE FROM institutes WHERE id=?',0);
 
 -- attributeType mappings: describe how an attributeType for a certain objectClass maps to the SQL data.
 --      id              a unique number identifying the attribute       
@@ -37,18 +37,18 @@ values (1,1,'cn','persons.name||'' ''||persons.surname','persons',NULL,NULL,NULL
 
 insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return)
 values (2,1,'telephoneNumber','phones.phone','persons,phones',
-        'phones.pers_id=persons.id','insert into phones (id,phone,pers_id) values ((select max(id)+1 from phones),?,?)',
-       'delete from phones where phone=? and pers_id=?',3,0);
+        'phones.pers_id=persons.id','INSERT INTO phones (id,phone,pers_id) VALUES ((SELECT max(id)+1 FROM phones),?,?)',
+       'DELETE FROM phones WHERE phone=? AND pers_id=?',3,0);
 
 insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return)
-values (4,1,'givenName','persons.name','persons',NULL,'update persons set name=? where id=?',NULL,3,0);
+values (4,1,'givenName','persons.name','persons',NULL,'UPDATE persons SET name=? WHERE id=?',NULL,3,0);
 
 insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return)
-values (3,1,'sn','persons.surname','persons',NULL,'update persons set surname=? where id=?',NULL,3,0);
+values (3,1,'sn','persons.surname','persons',NULL,'UPDATE persons SET surname=? WHERE id=?',NULL,3,0);
 
 insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return)
-values (5,1,'userPassword','persons.password','persons','persons.password IS NOT NULL','update persons set password=? where id=?',
-       NULL,3,0);
+values (5,1,'userPassword','persons.password','persons','persons.password IS NOT NULL','UPDATE persons SET password=? WHERE id=?',
+       'UPDATE persons SET password=NULL WHERE password=? AND id=?',3,0);
 
 insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return)
 values (6,1,'seeAlso','seeAlso.dn','ldap_entries AS seeAlso,documents,authors_docs,persons',
@@ -56,22 +56,22 @@ values (6,1,'seeAlso','seeAlso.dn','ldap_entries AS seeAlso,documents,authors_do
        NULL,NULL,3,0);
 
 insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return)
-values (7,2,'description','documents.abstract','documents',NULL,'update documents set abstract=? where id=?',NULL,3,0);
+values (7,2,'description','documents.abstract','documents',NULL,'UPDATE documents SET abstract=? WHERE id=?',NULL,3,0);
 
 insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return)
-values (8,2,'documentTitle','documents.title','documents',NULL,'update documents set title=? where id=?',NULL,3,0);
+values (8,2,'documentTitle','documents.title','documents',NULL,'UPDATE documents SET title=? WHERE id=?',NULL,3,0);
 
 insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return)
 values (9,2,'documentAuthor','documentAuthor.dn','ldap_entries AS documentAuthor,documents,authors_docs,persons',
        'documentAuthor.keyval=persons.id AND documentAuthor.oc_map_id=1 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id',
-       'insert into authors_docs (pers_id,doc_id) values ((select keyval from ldap_entries where ucase(cast(? as varchar(255)))=ucase(dn)),?)',
-       'delete from authors_docs where pers_id = (select keyval from ldap_entries where ucase(cast(? as varchar(255))=ucase(dn)) AND doc_id=?',3,0);
+       'INSERT INTO authors_docs (pers_id,doc_id) VALUES ((SELECT keyval FROM ldap_entries WHERE ucase(cast(? AS VARCHAR(255)))=ucase(dn)),?)',
+       'DELETE FROM authors_docs WHERE pers_id=(SELECT keyval FROM ldap_entries WHERE ucase(cast(? AS VARCHAR(255))=ucase(dn)) AND doc_id=?',3,0);
 
 insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return)
-values (10,2,'documentIdentifier','''document ''||rtrim(cast(documents.id as char(16)))','documents',NULL,NULL,NULL,3,0);
+values (10,2,'documentIdentifier','''document ''||rtrim(cast(documents.id AS CHAR(16)))','documents',NULL,NULL,NULL,3,0);
 
 insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return)
-values (11,3,'o','institutes.name','institutes',NULL,'update institutes set name=? where id=?',NULL,3,0);
+values (11,3,'o','institutes.name','institutes',NULL,'UPDATE institutes SET name=? WHERE id=?',NULL,3,0);
 
 insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return)
 values (12,3,'dc','lcase(institutes.name)','institutes,ldap_entries AS dcObject,ldap_entry_objclasses as auxObjectClass',
@@ -114,4 +114,3 @@ insert into ldap_entry_objclasses (entry_id,oc_name) values (4,'referral');
 --      url             the URI of the referral
 insert into ldap_referrals (entry_id,url) values (4,'ldap://localhost/');
 
--- user-defined functions
index a290af2ce8b3d889271de698c26f9bf7900ce306..75ade75e504f4d265e6cb117eb079b0785e82f9f 100644 (file)
@@ -8,11 +8,11 @@
 --     create_proc     a procedure to create the entry
 --     delete_proc     a procedure to delete the entry; it takes "keytbl.keycol" of the row to be deleted
 --     expect_return   a bitmap that marks whether create_proc (1) and delete_proc (2) return a value or not
-insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) values (1,'inetOrgPerson','persons','id','select create_person()','select delete_person(?)',0);
+insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) values (1,'inetOrgPerson','persons','id','SELECT create_person()','DELETE FROM persons WHERE id=?',0);
 
-insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) values (2,'document','documents','id','select create_doc()','select delete_doc(?)',0);
+insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) values (2,'document','documents','id','SELECT create_doc()','DELETE FROM documents WHERE id=?',0);
 
-insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) values (3,'organization','institutes','id','select create_o()','select delete_o(?)',0);
+insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expect_return) values (3,'organization','institutes','id','SELECT create_o()','DELETE FROM institutes WHERE id=?',0);
 
 -- attributeType mappings: describe how an attributeType for a certain objectClass maps to the SQL data.
 --     id              a unique number identifying the attribute       
@@ -25,29 +25,29 @@ insert into ldap_oc_mappings (id,name,keytbl,keycol,create_proc,delete_proc,expe
 --     delete_proc     a procedure to delete the attribute; it takes the value of the attribute that is added, and the "keytbl.keycol" of the entry it is associated to
 --     param_order     a mask that marks if the "keytbl.keycol" value comes before or after the value in add_proc (1) and delete_proc (2)
 --     expect_return   a mask that marks whether add_proc (1) and delete_proc(2) are expected to return a value or not
-insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (1,1,'cn','text(persons.name||'' ''||persons.surname)','persons',NULL,'select update_person_cn(?,?)',NULL,3,0);
+insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (1,1,'cn','text(persons.name||'' ''||persons.surname)','persons',NULL,'SELECT update_person_cn(?,?)',NULL,3,0);
 
-insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (2,1,'telephoneNumber','phones.phone','persons,phones','phones.pers_id=persons.id','select add_phone(?,?)','select delete_phone(?,?)',3,0);
+insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (2,1,'telephoneNumber','phones.phone','persons,phones','phones.pers_id=persons.id','SELECT add_phone(?,?)','DELETE FROM phones WHERE phone=? AND pers_id=?',3,0);
 
-insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (3,1,'givenName','persons.name','persons',NULL,'update persons set name=? where id=?',NULL,3,0);
+insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (3,1,'givenName','persons.name','persons',NULL,'UPDATE persons SET name=? WHERE id=?',NULL,3,0);
 
-insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (4,1,'sn','persons.surname','persons',NULL,'update persons set surname=? where id=?',NULL,3,0);
+insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (4,1,'sn','persons.surname','persons',NULL,'UPDATE persons SET surname=? WHERE id=?',NULL,3,0);
 
-insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (5,1,'userPassword','persons.password','persons','persons.password IS NOT NULL','update persons set password=? where id=?',NULL,3,0);
+insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (5,1,'userPassword','persons.password','persons','persons.password IS NOT NULL','UPDATE persons SET password=? WHERE id=?','UPDATE persons SET password=NULL WHERE password=? AND id=?',3,0);
 
 insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (6,1,'seeAlso','seeAlso.dn','ldap_entries AS seeAlso,documents,authors_docs,persons','seeAlso.keyval=documents.id AND seeAlso.oc_map_id=2 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id',NULL,NULL,3,0);
 
-insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (7,2,'description','documents.abstract','documents',NULL,'update documents set abstract=? where id=?',NULL,3,0);
+insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (7,2,'description','documents.abstract','documents',NULL,'UPDATE documents SET abstract=? WHERE id=?',NULL,3,0);
 
-insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (8,2,'documentTitle','documents.title','documents',NULL,'update documents set title=? where id=?',NULL,3,0);
+insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (8,2,'documentTitle','documents.title','documents',NULL,'UPDATE documents SET title=? WHERE id=?',NULL,3,0);
 
-insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (9,2,'documentAuthor','documentAuthor.dn','ldap_entries AS documentAuthor,documents,authors_docs,persons','documentAuthor.keyval=persons.id AND documentAuthor.oc_map_id=1 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id','select add_doc_author(?,?)','select delete_doc_author(?,?)',3,0);
+insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (9,2,'documentAuthor','documentAuthor.dn','ldap_entries AS documentAuthor,documents,authors_docs,persons','documentAuthor.keyval=persons.id AND documentAuthor.oc_map_id=1 AND authors_docs.doc_id=documents.id AND authors_docs.pers_id=persons.id','INSERT INTO authors_docs (pers_id,doc_id) VALUES ((SELECT ldap_entries.keyval FROM ldap_entries WHERE upper(?)=upper(ldap_entries.dn)),?)','DELETE FROM authors_docs WHERE authors_docs.pers_id=(SELECT ldap_entries.keyval FROM ldap_entries WHERE upper(?)=upper(ldap_entries.dn)) AND authors_docs.doc_id=?',3,0);
 
 insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (10,2,'documentIdentifier','''document ''||text(documents.id)','documents',NULL,NULL,NULL,3,0);
 
-insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (11,3,'o','institutes.name','institutes',NULL,'update institutes set name=? where id=?',NULL,3,0);
+insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (11,3,'o','institutes.name','institutes',NULL,'UPDATE institutes SET name=? WHERE id=?',NULL,3,0);
 
-insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (12,3,'dc','lower(institutes.name)','institutes,ldap_entries AS dcObject,ldap_entry_objclasses as auxObjectClass','institutes.id=dcObject.keyval AND dcObject.oc_map_id=3 AND dcObject.id=auxObjectClass.entry_id AND auxObjectClass.oc_name=''dcObject''',NULL,NULL,3,0);
+insert into ldap_attr_mappings (id,oc_map_id,name,sel_expr,from_tbls,join_where,add_proc,delete_proc,param_order,expect_return) values (12,3,'dc','lower(institutes.name)','institutes,ldap_entries AS dcObject,ldap_entry_objclasses AS auxObjectClass','institutes.id=dcObject.keyval AND dcObject.oc_map_id=3 AND dcObject.id=auxObjectClass.entry_id AND auxObjectClass.oc_name=''dcObject''',NULL,NULL,3,0);
 
 
 -- entries mapping: each entry must appear in this table, with a unique DN rooted at the database naming context
@@ -107,14 +107,6 @@ as '
        select $2 as return
 ' language 'sql';
 
-create function delete_person (int) returns int
-as '
-       delete from phones where pers_id = $1;
-       delete from authors_docs where pers_id = $1;
-       delete from persons where id = $1;
-       select $1 as return
-' language 'sql';
-
 create function add_phone (varchar, int) returns int
 as '
        select setval (''phones_id_seq'', (select case when max(id) is null then 1 else max(id) end from phones));
@@ -123,12 +115,6 @@ as '
        select max(id) from phones
 ' language 'sql';
 
-create function delete_phone (varchar, int) returns int
-as '
-       delete from phones where phone = $1 and pers_id = $2;
-       select $2 as result
-' language 'sql';
-
 create function create_doc () returns int
 as '
        select setval (''documents_id_seq'', (select case when max(id) is null then 1 else max(id) end from documents));
@@ -137,12 +123,6 @@ as '
        select max(id) from documents
 ' language 'sql';
 
-create function delete_doc (int) returns int
-as '
-       delete from documents where id = $1;
-       select $1 as return
-' language 'sql';
-
 create function create_o () returns int
 as '
        select setval (''institutes_id_seq'', (select case when max(id) is null then 1 else max(id) end from institutes));
@@ -151,29 +131,3 @@ as '
        select max(id) from institutes
 ' language 'sql';
 
-create function delete_o (int) returns int
-as '
-       delete from institutes where id = $1;
-       select $1 as return
-' language 'sql';
-
-create function add_doc_author (varchar, int) returns int
-as '
-       insert into authors_docs (pers_id,doc_id) values ((
-               select ldap_entries.keyval
-                       from ldap_entries 
-                       where upper($1) = upper(ldap_entries.dn)
-       ),$2);
-       select $2 as return
-' language 'sql';
-
-create function delete_doc_author (varchar, int) returns int
-as '
-       delete from authors_docs where authors_docs.pers_id = (
-               select ldap_entries.keyval
-                       from ldap_entries 
-                       where upper($1) = upper(ldap_entries.dn)
-       ) and authors_docs.doc_id = $2;
-       select $2 as return
-' language 'sql';
-
index 29b1e06a0a6d2ed48259be68f24d699f3426ae35..d5bd51dafe7fcd237b7a857806b662547d4d3ed2 100644 (file)
@@ -106,10 +106,26 @@ backsql_make_attr_query(
 {
        struct berbuf   bb = BB_NULL;
 
+#ifdef BACKSQL_ALIASING_QUOTE
+       backsql_strfcat( &bb, "lblcbclblbcbl", 
+                       (ber_len_t)STRLENOF( "SELECT " ), "SELECT ", 
+                       &at_map->bam_sel_expr, 
+                       (ber_len_t)STRLENOF( " " BACKSQL_ALIASING ), " " BACKSQL_ALIASING, 
+                       BACKSQL_ALIASING_QUOTE,
+                       &at_map->bam_ad->ad_cname,
+                       BACKSQL_ALIASING_QUOTE,
+                       (ber_len_t)STRLENOF( " FROM " ), " FROM ", 
+                       &at_map->bam_from_tbls, 
+                       (ber_len_t)STRLENOF( " WHERE " ), " WHERE ", 
+                       &oc_map->bom_keytbl,
+                       '.', 
+                       &oc_map->bom_keycol,
+                       (ber_len_t)STRLENOF( "=?" ), "=?" );
+#else /* ! BACKSQL_ALIASING_QUOTE */
        backsql_strfcat( &bb, "lblblblbcbl", 
                        (ber_len_t)STRLENOF( "SELECT " ), "SELECT ", 
                        &at_map->bam_sel_expr, 
-                       (ber_len_t)STRLENOF( " AS " ), " AS "
+                       (ber_len_t)STRLENOF( " " BACKSQL_ALIASING ), " " BACKSQL_ALIASING
                        &at_map->bam_ad->ad_cname,
                        (ber_len_t)STRLENOF( " FROM " ), " FROM ", 
                        &at_map->bam_from_tbls, 
@@ -118,6 +134,7 @@ backsql_make_attr_query(
                        '.', 
                        &oc_map->bom_keycol,
                        (ber_len_t)STRLENOF( "=?" ), "=?" );
+#endif /* ! BACKSQL_ALIASING_QUOTE */
 
        if ( !BER_BVISNULL( &at_map->bam_join_where ) ) {
                backsql_strfcat( &bb, "lb",
index 7f9c4ab8abbaa5e8c2a3c618ba1810e7eba86f0a..757e8acd840a7985581edbe67be9a837190d578c 100644 (file)
@@ -1015,9 +1015,21 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
                                &bsi->bsi_oc->bom_oc->soc_cname,
                                '\'' );
        }
+#ifdef BACKSQL_ALIASING_QUOTE
+       backsql_strfcat( &bsi->bsi_sel, "lclcl",
+                       (ber_len_t)STRLENOF( " " BACKSQL_ALIASING ),
+                               " " BACKSQL_ALIASING,
+                       BACKSQL_ALIASING_QUOTE,
+                       (ber_len_t)STRLENOF( "objectClass" ),
+                               "objectClass",
+                       BACKSQL_ALIASING_QUOTE,
+                       (ber_len_t)STRLENOF( ",ldap_entries.dn " BACKSQL_ALIASING "dn" ),
+                               ",ldap_entries.dn " BACKSQL_ALIASING "dn" );
+#else /* ! BACKSQL_ALIASING_QUOTE */
        backsql_strfcat( &bsi->bsi_sel, "l",
-                       (ber_len_t)STRLENOF( " AS objectClass,ldap_entries.dn AS dn" ),
-                       " AS objectClass,ldap_entries.dn AS dn" );
+                       (ber_len_t)STRLENOF( " " BACKSQL_ALIASING "objectClass,ldap_entries.dn " BACKSQL_ALIASING "dn" ),
+                               " " BACKSQL_ALIASING "objectClass,ldap_entries.dn " BACKSQL_ALIASING "dn" );
+#endif /* ! BACKSQL_ALIASING_QUOTE */
 
        backsql_strfcat( &bsi->bsi_from, "lb",
                        (ber_len_t)STRLENOF( " FROM ldap_entries," ),
index 292c63c3ce87b2774a997490b72537ad844fad81..ff0fa3d94117c9c2d13462fed4eb1305045f46db 100644 (file)
@@ -32,8 +32,8 @@
 
 #define MAX_ATTR_LEN 16384
 
-typedef struct backsql_conn {
-       int             ldap_cid;
+typedef struct backsql_db_conn {
+       unsigned long   ldap_cid;
        SQLHDBC         dbh;
 } backsql_db_conn;
 
index bbbfed71f0c5b9a2b11fdfcd001b4b0abf4324bd..16084ef4ef414d0fd768e8094d50859edc5e5590 100644 (file)
@@ -318,18 +318,18 @@ backsql_get_table_spec( char **p )
        s = q;
 
        BACKSQL_NEXT_WORD;
-       if ( !strcasecmp( s, "as" ) ) {
+       if ( strcasecmp( s, "AS" ) == 0 ) {
                s = q;
                BACKSQL_NEXT_WORD;
        }
 
-#if 0
-       backsql_strcat( &res, " AS ", s, NULL );
-       /* oracle doesn't understand AS :( and other RDBMSes don't need it */
-#endif
-
-       /* table alias */
-       backsql_strfcat( &res, "cs", ' ', s );
+       /* oracle doesn't understand "AS" :( and other RDBMSes don't need it */
+#ifdef BACKSQL_ALIASING_QUOTE
+       backsql_strfcat( &res, "scsc", " " BACKSQL_ALIASING,
+                       BACKSQL_ALIASING_QUOTE, s, BACKSQL_ALIASING_QUOTE );
+#else /* ! BACKSQL_ALIASING */
+       backsql_strcat( &res, " " BACKSQL_ALIASING, s, NULL );
+#endif /* ! BACKSQL_ALIASING */
 
        return res.bb_val.bv_val;
 }
index 03aad0580acd1596c1cc9690edaf1507082a5722..5390cd42e53f111ffcf98a9d0215baa4c5626b86 100644 (file)
@@ -40,6 +40,7 @@ telephoneNumber: 545-4563
 
 # refldap://localhost/dc=example,dc=com??sub
 
+# Testing invalid filter...
 # Testing exact search...
 dn: cn=Mitya Kovalev,dc=example,dc=com
 objectClass: inetOrgPerson
@@ -237,7 +238,6 @@ telephoneNumber: 545-4563
 
 # refldap://localhost/dc=example,dc=com??sub
 
-# Testing NOT search on sn...
 # Testing attribute inheritance in filter...
 dn: dc=example,dc=com
 objectClass: organization
index 5fea109892766c38e15ee75e73ad5273676ca0eb..9afb5868fa884aaeb7abdfadbeb2508e17995176 100644 (file)
@@ -1,18 +1,18 @@
-dn: documentTitle=book2,dc=example,dc=com
-objectClass: document
-description: abstract2
-documentTitle: book2
-documentAuthor: cn=Mitya Kovalev,dc=example,dc=com
-documentAuthor: cn=Lev Tolstoij,dc=example,dc=com
-documentIdentifier: document 2
-
 dn: documentTitle=War and Peace,dc=example,dc=com
 objectClass: document
 description: Historical novel
 documentTitle: War and Peace
-documentAuthor: cn=Lev Tolstoij,dc=example,dc=com
+documentAuthor: cn=Lev Tolstoij,dc=subnet,dc=example,dc=com
 documentIdentifier: document 3
 
+dn: documentTitle=Renamed Book,dc=example,dc=com
+objectClass: document
+description: abstract2
+documentTitle: Renamed Book
+documentAuthor: cn=Mitya Kovalev,dc=example,dc=com
+documentAuthor: cn=Lev Tolstoij,dc=subnet,dc=example,dc=com
+documentIdentifier: document 2
+
 dn: dc=example,dc=com
 objectClass: organization
 objectClass: dcObject
@@ -25,30 +25,20 @@ objectClass: dcObject
 o: SubNet
 dc: subnet
 
-dn: o=Another Org,dc=example,dc=com
+dn: o=Renamed Org,dc=example,dc=com
 objectClass: organization
-o: Another Org
+o: Renamed Org
 
 dn: cn=Mitya Kovalev,dc=example,dc=com
 objectClass: inetOrgPerson
 cn: Mitya Kovalev
 sn: Kovalev
-seeAlso: documentTitle=book2,dc=example,dc=com
+seeAlso: documentTitle=Renamed Book,dc=example,dc=com
 givenName: Mitya
 telephoneNumber: 332-2334
 telephoneNumber: 222-3234
 telephoneNumber: +1 800 123 4567
 
-dn: cn=Lev Tolstoij,dc=example,dc=com
-objectClass: inetOrgPerson
-cn: Lev Tolstoij
-sn: Tolstoij
-seeAlso: documentTitle=book2,dc=example,dc=com
-seeAlso: documentTitle=War and Peace,dc=example,dc=com
-givenName: Lev
-telephoneNumber: +39 02 XXXX ZZZZ
-telephoneNumber: +39 333 ZZZ 1234
-
 dn: cn=Some One,dc=example,dc=com
 objectClass: inetOrgPerson
 objectClass: simpleSecurityObject
@@ -62,3 +52,13 @@ cn: SubNet User
 sn: User
 givenName: SubNet
 
+dn: cn=Lev Tolstoij,dc=subnet,dc=example,dc=com
+objectClass: inetOrgPerson
+cn: Lev Tolstoij
+sn: Tolstoij
+seeAlso: documentTitle=Renamed Book,dc=example,dc=com
+seeAlso: documentTitle=War and Peace,dc=example,dc=com
+givenName: Lev
+telephoneNumber: +39 02 XXXX ZZZZ
+telephoneNumber: +39 333 ZZZ 1234
+
index d9ea0b18c4d3829d0820ffc386afc0a65bfa8649..8d7c6e3bd0552ea8d16a5d0b0e082048a5e46c5c 100755 (executable)
@@ -88,6 +88,18 @@ if test $RC != 0 ; then
        exit $RC
 fi
 
+echo "Testing invalid filter..."
+echo "# Testing invalid filter..." >> $SEARCHOUT
+$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
+        "(foo=)" >> $SEARCHOUT 2>&1
+
+RC=$?
+if test $RC != 0 ; then
+       echo "ldapsearch failed ($RC)!"
+       test $KILLSERVERS != no && kill -HUP $KILLPIDS
+       exit $RC
+fi
+
 echo "Testing exact search..."
 echo "# Testing exact search..." >> $SEARCHOUT
 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
@@ -258,7 +270,7 @@ fi
 
 #### Needs work...
 echo "Testing NOT presence search... (disabled)"
-###echo "# Testing NOT search on sn..." >> $SEARCHOUT
+###echo "# Testing NOT presence search..." >> $SEARCHOUT
 ###$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
 ###     '(!(sn=*))' >> $SEARCHOUT 2>&1
 ###
index 0d1eee4c92e712260d3eb760a7b705972f6671b3..c225490f52f0323f4ba2999ecfd78c575e56c4dd 100755 (executable)
@@ -95,6 +95,7 @@ sn: Tolstoij
 givenName: Lev
 telephoneNumber: +39 02 XXXX YYYY
 telephoneNumber: +39 02 XXXX ZZZZ
+userPassword: tanja
 
 # Adding a person with an "auxiliary" objectClass...
 dn: cn=Some One,${BASEDN}
@@ -190,6 +191,10 @@ changetype: modify
 delete: objectClass
 objectClass: simpleSecurityObject
 -
+
+# Deleting userPasswords
+dn: cn=Lev Tolstoij,${BASEDN}
+changetype: modify
 delete: userPassword
 -
 
@@ -238,7 +243,20 @@ version: 1
 # Renaming an organization
 dn: o=An Org,${BASEDN}
 changetype: modrdn
-newrdn: o=Another Org
+newrdn: o=Renamed Org
+deleteoldrdn: 1
+
+# Renaming a person
+dn: cn=Lev Tolstoij,${BASEDN}
+changetype: modrdn
+newrdn: cn=Lev Tolstoij
+deleteoldrdn: 0
+newsuperior: dc=subnet,${BASEDN}
+
+# Renaming a book
+dn: documentTitle=book2,${BASEDN}
+changetype: modrdn
+newrdn: documentTitle=Renamed Book
 deleteoldrdn: 1
 
 EOMODS