From: Pierangelo Masarati Date: Tue, 24 Aug 2004 17:08:30 +0000 (+0000) Subject: write test is almost working for ibmdb2 as well... X-Git-Tag: OPENLDAP_REL_ENG_2_3_0ALPHA~652 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=752bffb16cb5b206cd76c8e448bc951eb2a47f90;p=openldap write test is almost working for ibmdb2 as well... --- diff --git a/servers/slapd/back-sql/back-sql.h b/servers/slapd/back-sql/back-sql.h index 6bfedc643c..04f69bb5f2 100644 --- a/servers/slapd/back-sql/back-sql.h +++ b/servers/slapd/back-sql/back-sql.h @@ -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; diff --git a/servers/slapd/back-sql/config.c b/servers/slapd/back-sql/config.c index bce6198045..02795c64ef 100644 --- a/servers/slapd/back-sql/config.c +++ b/servers/slapd/back-sql/config.c @@ -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, diff --git a/servers/slapd/back-sql/delete.c b/servers/slapd/back-sql/delete.c index 3f4cfb99a4..00f42b22ac 100644 --- a/servers/slapd/back-sql/delete.c +++ b/servers/slapd/back-sql/delete.c @@ -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 diff --git a/servers/slapd/back-sql/init.c b/servers/slapd/back-sql/init.c index f92406278b..9924349930 100644 --- a/servers/slapd/back-sql/init.c +++ b/servers/slapd/back-sql/init.c @@ -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 ) { diff --git a/servers/slapd/back-sql/proto-sql.h b/servers/slapd/back-sql/proto-sql.h index a239e7b5c5..63eb5ac9a4 100644 --- a/servers/slapd/back-sql/proto-sql.h +++ b/servers/slapd/back-sql/proto-sql.h @@ -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[], diff --git a/servers/slapd/back-sql/rdbms_depend/ibmdb2/testdb_metadata.sql b/servers/slapd/back-sql/rdbms_depend/ibmdb2/testdb_metadata.sql index ad6708d782..7ce5bf79eb 100644 --- a/servers/slapd/back-sql/rdbms_depend/ibmdb2/testdb_metadata.sql +++ b/servers/slapd/back-sql/rdbms_depend/ibmdb2/testdb_metadata.sql @@ -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 diff --git a/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql b/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql index cf2ffa452f..a290af2ce8 100644 --- a/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql +++ b/servers/slapd/back-sql/rdbms_depend/pgsql/testdb_metadata.sql @@ -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'; diff --git a/servers/slapd/back-sql/util.c b/servers/slapd/back-sql/util.c index f3de6685e7..bbbfed71f0 100644 --- a/servers/slapd/back-sql/util.c +++ b/servers/slapd/back-sql/util.c @@ -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 ";