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;
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,
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,
rs->sr_text = "SQL-backend error";
goto done;
}
+ SQLFreeStmt( sth, SQL_DROP );
/*
* Commit only if all operations succeed
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 );
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 ) {
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[],
-- 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),'''','''')',
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);
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);
-- url the URI of the referral
insert into ldap_referrals (entry_id,url) values (4,'ldap://localhost/');
+-- user-defined functions
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';
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';
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';
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 ";