]> git.sur5r.net Git - openldap/commitdiff
write test is almost working for ibmdb2 as well...
authorPierangelo Masarati <ando@openldap.org>
Tue, 24 Aug 2004 17:08:30 +0000 (17:08 +0000)
committerPierangelo Masarati <ando@openldap.org>
Tue, 24 Aug 2004 17:08:30 +0000 (17:08 +0000)
servers/slapd/back-sql/back-sql.h
servers/slapd/back-sql/config.c
servers/slapd/back-sql/delete.c
servers/slapd/back-sql/init.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/util.c

index 6bfedc643cb0bdf2ea7474cfd9df2f08ea46076f..04f69bb5f21c0f77398513e4332aa3c2dccde663 100644 (file)
@@ -285,7 +285,10 @@ typedef struct {
        struct berval   subtree_cond;
        struct berval   children_cond;
        char            *oc_query, *at_query;
-       char            *insentry_query,*delentry_query;
+       char            *insentry_query,
+                       *delentry_query,
+                       *delobjclasses_query,
+                       *delreferrals_query;
        char            *id_query;
        char            *has_children_query;
 
index bce61980450cbfb0cb1c489b3d2e0e4017225a92..02795c64ef7287c44610e9ba8170bb85e7ae90dc 100644 (file)
@@ -274,6 +274,32 @@ backsql_db_config(
                Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
                        "delentry_query=%s\n", si->delentry_query, 0, 0 );
 
+       } else if ( !strcasecmp( argv[ 0 ], "delobjclasses_query" ) ) {
+               if ( argc < 2 ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "<==backsql_db_config (%s line %d): "
+                               "missing SQL statement "
+                               "in \"delobjclasses_query\" directive\n",
+                               fname, lineno, 0 );
+                       return 1;
+               }
+               si->delobjclasses_query = ch_strdup( argv[ 1 ] );
+               Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
+                       "delobjclasses_query=%s\n", si->delobjclasses_query, 0, 0 );
+
+       } else if ( !strcasecmp( argv[ 0 ], "delreferrals_query" ) ) {
+               if ( argc < 2 ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "<==backsql_db_config (%s line %d): "
+                               "missing SQL statement "
+                               "in \"delreferrals_query\" directive\n",
+                               fname, lineno, 0 );
+                       return 1;
+               }
+               si->delreferrals_query = ch_strdup( argv[ 1 ] );
+               Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
+                       "delreferrals_query=%s\n", si->delreferrals_query, 0, 0 );
+
        } else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru") ) {
                if ( argc < 2 ) {
                        Debug( LDAP_DEBUG_TRACE,
index 3f4cfb99a44f3b331720d3e3e1a028ddbceccc89..00f42b22ace2130012db4e64b613b5e790ef5ec0 100644 (file)
@@ -164,6 +164,88 @@ backsql_delete( Operation *op, SlapReply *rs )
        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... */
+       rc = backsql_Prepare( dbh, &sth, bi->delobjclasses_query, 0 );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_delete(): "
+                       "error preparing ldap_entry_objclasses 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;
+       }
+
+#ifdef BACKSQL_ARBITRARY_KEY
+       SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
+                       0, 0, e_id.eid_id.bv_val, 0, 0 );
+#else /* ! BACKSQL_ARBITRARY_KEY */
+       SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER,
+                       0, 0, &e_id.eid_id, 0, 0 );
+#endif /* ! BACKSQL_ARBITRARY_KEY */
+       rc = SQLExecute( sth );
+       switch ( rc ) {
+       case SQL_NO_DATA:
+               /* apparently there were no "auxiliary" objectClasses
+                * for this entry... */
+       case SQL_SUCCESS:
+               break;
+
+       default:
+               Debug( LDAP_DEBUG_TRACE, "   backsql_delete(): "
+                       "failed to delete record from ldap_entry_objclasses\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";
+               goto done;
+       }
+       SQLFreeStmt( sth, SQL_DROP );
+
+       rc = backsql_Prepare( dbh, &sth, bi->delreferrals_query, 0 );
+       if ( rc != SQL_SUCCESS ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "   backsql_delete(): "
+                       "error preparing ldap_referrals 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;
+       }
+
+#ifdef BACKSQL_ARBITRARY_KEY
+       SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
+                       0, 0, e_id.eid_id.bv_val, 0, 0 );
+#else /* ! BACKSQL_ARBITRARY_KEY */
+       SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER,
+                       0, 0, &e_id.eid_id, 0, 0 );
+#endif /* ! BACKSQL_ARBITRARY_KEY */
+       rc = SQLExecute( sth );
+       switch ( rc ) {
+       case SQL_NO_DATA:
+               /* apparently there were no referrals
+                * for this entry... */
+       case SQL_SUCCESS:
+               break;
+
+       default:
+               Debug( LDAP_DEBUG_TRACE, "   backsql_delete(): "
+                       "failed to delete record from ldap_referrals\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";
+               goto done;
+       }
+       SQLFreeStmt( sth, SQL_DROP );
+
        rc = backsql_Prepare( dbh, &sth, bi->delentry_query, 0 );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE,
@@ -195,6 +277,7 @@ backsql_delete( Operation *op, SlapReply *rs )
                rs->sr_text = "SQL-backend error";
                goto done;
        }
+       SQLFreeStmt( sth, SQL_DROP );
 
        /*
         * Commit only if all operations succeed
index f92406278bc5f14fb46cda497d73bed67accde0f..9924349930d8736a505569c13ca3eccdb5ce1218 100644 (file)
@@ -162,6 +162,8 @@ backsql_db_destroy(
        free( si->at_query );
        free( si->insentry_query );
        free( si->delentry_query );
+       free( si->delobjclasses_query );
+       free( si->delreferrals_query );
        free( si );
        
        Debug( LDAP_DEBUG_TRACE, "<==backsql_db_destroy()\n", 0, 0, 0 );
@@ -383,6 +385,28 @@ backsql_db_open(
                si->delentry_query = ch_strdup( backsql_def_delentry_query );
        }
 
+       if ( si->delobjclasses_query == NULL ) {
+               Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
+                       "objclasses deletion SQL statement not specified "
+                       "(use \"delobjclasses_query\" directive in slapd.conf)\n",
+                       0, 0, 0 );
+               Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
+                       "setting \"%s\" by default\n",
+                       backsql_def_delobjclasses_query, 0, 0 );
+               si->delobjclasses_query = ch_strdup( backsql_def_delobjclasses_query );
+       }
+
+       if ( si->delreferrals_query == NULL ) {
+               Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
+                       "referrals deletion SQL statement not specified "
+                       "(use \"delreferrals_query\" directive in slapd.conf)\n",
+                       0, 0, 0 );
+               Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
+                       "setting \"%s\" by default\n",
+                       backsql_def_delreferrals_query, 0, 0 );
+               si->delreferrals_query = ch_strdup( backsql_def_delreferrals_query );
+       }
+
        otmp.o_connid = (unsigned long)(-1);
        otmp.o_bd = bd;
        if ( backsql_get_db_conn( &otmp, &dbh ) != LDAP_SUCCESS ) {
index a239e7b5c59ad2ff075c540daf11b7ef0358a909..63eb5ac9a41a587d07dc8efb4addf345c9f31790 100644 (file)
@@ -189,6 +189,8 @@ extern char
        backsql_def_at_query[],
        backsql_def_delentry_query[],
        backsql_def_insentry_query[],
+       backsql_def_delobjclasses_query[],
+       backsql_def_delreferrals_query[],
        backsql_def_subtree_cond[],
        backsql_def_upper_subtree_cond[],
        backsql_id_query[],
index ad6708d7825051b63533df9a8959f098efb9ba35..7ce5bf79ebd49f20c8629556748503c64611b22c 100644 (file)
@@ -11,8 +11,7 @@
 --      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);
+       '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),'''','''')',
@@ -39,7 +38,7 @@ 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 pers_id=? AND phone=?',3,0);
+       '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);
@@ -65,8 +64,8 @@ values (8,2,'documentTitle','documents.title','documents',NULL,'update documents
 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(?)=ucase(dn)),?)',
-       'delete from authors_docs where pers_id = (select keyval from ldap_entries where ucase(?)=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);
@@ -115,3 +114,4 @@ 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 cf2ffa452fd4aa75056ee94f11e8819b8f226981..a290af2ce8b3d889271de698c26f9bf7900ce306 100644 (file)
@@ -112,8 +112,6 @@ as '
        delete from phones where pers_id = $1;
        delete from authors_docs where pers_id = $1;
        delete from persons where id = $1;
-       delete from ldap_entry_objclasses where entry_id=(select id from ldap_entries where oc_map_id=1 and keyval = $1);
-       delete from ldap_referrals where entry_id=(select id from ldap_entries where oc_map_id=1 and keyval = $1);
        select $1 as return
 ' language 'sql';
 
@@ -142,8 +140,6 @@ as '
 create function delete_doc (int) returns int
 as '
        delete from documents where id = $1;
-       delete from ldap_entry_objclasses where entry_id=(select id from ldap_entries where oc_map_id=2 and keyval = $1);
-       delete from ldap_referrals where entry_id=(select id from ldap_entries where oc_map_id=2 and keyval = $1);
        select $1 as return
 ' language 'sql';
 
@@ -158,8 +154,6 @@ as '
 create function delete_o (int) returns int
 as '
        delete from institutes where id = $1;
-       delete from ldap_entry_objclasses where entry_id=(select id from ldap_entries where oc_map_id=3 and keyval = $1);
-       delete from ldap_referrals where entry_id=(select id from ldap_entries where oc_map_id=3 and keyval = $1);
        select $1 as return
 ' language 'sql';
 
index f3de6685e707c0cd65e6f0587edcec0fd4a3c470..bbbfed71f0c5b9a2b11fdfcd001b4b0abf4324bd 100644 (file)
@@ -52,6 +52,10 @@ char backsql_def_delentry_query[] = "DELETE FROM ldap_entries WHERE id=?";
 char backsql_def_insentry_query[] = 
        "INSERT INTO ldap_entries (dn,oc_map_id,parent,keyval) "
        "VALUES (?,?,?,?)";
+char backsql_def_delobjclasses_query[] = "DELETE FROM ldap_entry_objclasses "
+       "WHERE entry_id=?";
+char backsql_def_delreferrals_query[] = "DELETE FROM ldap_referrals "
+       "WHERE entry_id=?";
 char backsql_def_subtree_cond[] = "ldap_entries.dn LIKE CONCAT('%',?)";
 char backsql_def_upper_subtree_cond[] = "(ldap_entries.dn) LIKE CONCAT('%',?)";
 char backsql_id_query[] = "SELECT id,keyval,oc_map_id FROM ldap_entries WHERE ";