char *sql_insentry_stmt,
*sql_delentry_stmt,
*sql_renentry_stmt,
- *sql_delobjclasses_stmt,
- *sql_delreferrals_stmt;
+ *sql_delobjclasses_stmt;
char *sql_id_query;
char *sql_has_children_query;
Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
"delobjclasses_stmt=%s\n", bi->sql_delobjclasses_stmt, 0, 0 );
- } else if ( !strcasecmp( argv[ 0 ], "delreferrals_stmt" ) ||
- !strcasecmp( argv[ 0 ], "delreferrals_query" ) )
- {
- if ( argc < 2 ) {
- Debug( LDAP_DEBUG_TRACE,
- "<==backsql_db_config (%s line %d): "
- "missing SQL statement "
- "in \"delreferrals_stmt\" directive\n",
- fname, lineno, 0 );
- return 1;
- }
- bi->sql_delreferrals_stmt = ch_strdup( argv[ 1 ] );
- Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
- "delreferrals_stmt=%s\n", bi->sql_delreferrals_stmt, 0, 0 );
-
} else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru") ) {
if ( argc < 2 ) {
Debug( LDAP_DEBUG_TRACE,
}
SQLFreeStmt( sth, SQL_DROP );
- /* delete referrals, if any... */
- rc = backsql_Prepare( dbh, &sth, bi->sql_delreferrals_stmt, 0 );
- if ( rc != SQL_SUCCESS ) {
- Debug( LDAP_DEBUG_TRACE,
- " backsql_delete(): "
- "error preparing ldap_referrals delete query\n",
- 0, 0, 0 );
- backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
-
- rs->sr_err = LDAP_OTHER;
- rs->sr_text = "SQL-backend error";
- e = NULL;
- goto done;
- }
-
- rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT, &e_id.eid_id );
- if ( rc != SQL_SUCCESS ) {
- Debug( LDAP_DEBUG_TRACE,
- " backsql_delete(): "
- "error binding referrals entry ID parameter "
- "for objectClass %s\n",
- oc->bom_oc->soc_cname.bv_val, 0, 0 );
- backsql_PrintErrors( bi->sql_db_env, dbh,
- sth, rc );
- SQLFreeStmt( sth, SQL_DROP );
-
- rs->sr_text = "SQL-backend error";
- rs->sr_err = LDAP_OTHER;
- e = NULL;
- goto done;
- }
-
- 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->sql_db_env, dbh, sth, rc );
- SQLFreeStmt( sth, SQL_DROP );
- rs->sr_err = LDAP_OTHER;
- rs->sr_text = "SQL-backend error";
- e = NULL;
- goto done;
- }
- SQLFreeStmt( sth, SQL_DROP );
-
/* delete entry... */
rc = backsql_Prepare( dbh, &sth, bi->sql_delentry_stmt, 0 );
if ( rc != SQL_SUCCESS ) {
free( bi->sql_delentry_stmt );
free( bi->sql_renentry_stmt );
free( bi->sql_delobjclasses_stmt );
- free( bi->sql_delreferrals_stmt );
if ( bi->sql_anlist ) {
int i;
bi->sql_delobjclasses_stmt = ch_strdup( backsql_def_delobjclasses_stmt );
}
- if ( bi->sql_delreferrals_stmt == NULL ) {
- Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
- "referrals deletion SQL statement not specified "
- "(use \"delreferrals_stmt\" directive in slapd.conf)\n",
- 0, 0, 0 );
- Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
- "setting \"%s\" by default\n",
- backsql_def_delreferrals_stmt, 0, 0 );
- bi->sql_delreferrals_stmt = ch_strdup( backsql_def_delreferrals_stmt );
- }
-
op->o_hdr = (Opheader *)&op[ 1 ];
op->o_connid = (unsigned long)(-1);
op->o_bd = bd;
backsql_def_renentry_stmt[],
backsql_def_insentry_stmt[],
backsql_def_delobjclasses_stmt[],
- backsql_def_delreferrals_stmt[],
backsql_def_subtree_cond[],
backsql_def_upper_subtree_cond[],
backsql_id_query[],
dn
);
-drop table if exists ldap_referrals;
-create table ldap_referrals
- (
- entry_id integer not null references ldap_entries(id),
- url text not null
-);
-
drop table if exists ldap_entry_objclasses;
create table ldap_entry_objclasses
(
drop table if exists referrals;
CREATE TABLE referrals (
id int NOT NULL,
- name varchar(255) NOT NULL
+ name varchar(255) NOT NULL,
+ url varchar(255) NOT NULL
);
insert into authors_docs (pers_id,doc_id) values (1,2);
insert into authors_docs (pers_id,doc_id) values (2,1);
-insert into referrals (id,name) values (1,'Referral');
+insert into referrals (id,name,url) values (1,'Referral','ldap://localhost:9010/');
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 (13,4,'ou','referrals.name','referrals',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 (14,4,'ref','referrals.url','referrals',NULL,NULL,NULL,3,0);
+
-- entries mapping: each entry must appear in this table, with a unique DN rooted at the database naming context
-- id a unique number > 0 identifying the entry
-- dn the DN of the entry, in "pretty" form
insert into ldap_entry_objclasses (entry_id,oc_name)
values (7,'extensibleObject');
--- referrals mapping: entries that should be treated as referrals are stored here
--- entry_id the "ldap_entries.id" of the entry that should be treated as a referral
--- url the URI of the referral
-insert into ldap_referrals (entry_id,url)
-values (7,'ldap://localhost:9010/');
-
UNIQUE ( dn )
);
-drop table ldap_referrals;
-create table ldap_referrals
- (
- entry_id integer not null references ldap_entries(id),
- url text not null
-);
-
drop table ldap_entry_objclasses;
create table ldap_entry_objclasses
(
drop sequence referrals_id_seq;
create table referrals (
id serial not null primary key,
- name varchar(255) not null
+ name varchar(255) not null,
+ url varchar(255) not null
);
insert into authors_docs (pers_id,doc_id) values (1,2);
insert into authors_docs (pers_id,doc_id) values (2,1);
-insert into referrals (id,name) values (1,'Referral');
+insert into referrals (id,name,url) values (1,'Referral','ldap://localhost:9010/');
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 (13,4,'ou','referrals.name','referrals',NULL,'UPDATE referrals 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 (14,4,'ref','referrals.url','referrals',NULL,'UPDATE referrals SET url=? WHERE id=?',NULL,3,0);
+
-- entries mapping: each entry must appear in this table, with a unique DN rooted at the database naming context
-- id a unique number > 0 identifying the entry
-- dn the DN of the entry, in "pretty" form
insert into ldap_entry_objclasses (entry_id,oc_name) values (7,'extensibleObject');
--- referrals mapping: entries that should be treated as referrals are stored here
--- entry_id the "ldap_entries.id" of the entry that should be treated as a referral
--- url the URI of the referral
-insert into ldap_referrals (entry_id,url) values (7,'ldap://localhost:9010/');
-
-- procedures
-- these procedures are specific for this RDBMS and are used in mapping objectClass and attributeType creation/modify/deletion
create function create_person () returns int
create function create_referral () returns int
as '
select setval (''referrals_id_seq'', (select case when max(id) is null then 1 else max(id) end from referrals));
- insert into referrals (id,name,surname)
+ insert into referrals (id,name,url)
values ((select case when max(id) is null then 1 else nextval(''referrals_id_seq'') end from referrals),'''','''');
select max(id) from referrals
' language 'sql';
struct berbuf bb;
sbv.bv_val = s;
- snprintf( s, sizeof( s ), "%ld", oc_map->bom_id );
- sbv.bv_len = strlen( s );
+ sbv.bv_len = snprintf( s, sizeof( s ), "%ld", oc_map->bom_id );
/* extra objectClasses */
at_map = (backsql_at_map_rec *)ch_calloc(1,
&sbv );
at_map->bam_join_where = bb.bb_val;
- /* referral attribute */
- at_map = (backsql_at_map_rec *)ch_calloc( 1,
- sizeof( backsql_at_map_rec ) );
- at_map->bam_ad = slap_schema.si_ad_ref;
- ber_str2bv( "ldap_referrals.url", 0, 1, &at_map->bam_sel_expr );
- ber_str2bv( "ldap_referrals,ldap_entries", 0, 1, &at_map->bam_from_tbls );
-
- bb.bb_len = at_map->bam_from_tbls.bv_len + 1;
- bb.bb_val = at_map->bam_from_tbls;
- backsql_merge_from_clause( &bb, &oc_map->bom_keytbl );
- at_map->bam_from_tbls = bb.bb_val;
-
- BER_BVZERO( &bb.bb_val );
- bb.bb_len = 0;
- backsql_strfcat( &bb, "lbcblb",
- (ber_len_t)STRLENOF( "ldap_entries.id=ldap_referrals.entry_id AND ldap_entries.keyval=" ),
- "ldap_entries.id=ldap_referrals.entry_id AND ldap_entries.keyval=",
- &oc_map->bom_keytbl,
- '.',
- &oc_map->bom_keycol,
- (ber_len_t)STRLENOF( " AND ldap_entries.oc_map_id=" ),
- " AND ldap_entries.oc_map_id=",
- &sbv );
-
- at_map->bam_join_where = bb.bb_val;
-
- at_map->bam_oc = NULL;
-
- at_map->bam_add_proc = NULL;
- {
- char tmp[] =
- "INSERT INTO ldap_referrals "
- "(entry_id,url) VALUES "
- "((SELECT id FROM ldap_entries "
- "WHERE oc_map_id="
- "18446744073709551615UL " /* 64 bit ULONG */
- "AND keyval=?),?)";
- snprintf( tmp, sizeof(tmp),
- "INSERT INTO ldap_referrals "
- "(entry_id,url) VALUES "
- "((SELECT id FROM ldap_entries "
- "WHERE oc_map_id=%lu "
- "AND keyval=?),?)", oc_map->bom_id );
- at_map->bam_add_proc = ch_strdup( tmp );
- }
-
- at_map->bam_delete_proc = NULL;
- {
- char tmp[] =
- "DELETE FROM ldap_referrals "
- "WHERE entry_id=(SELECT id FROM ldap_entries "
- "WHERE oc_map_id="
- "18446744073709551615UL " /* 64 bit ULONG */
- "AND keyval=?) and url=?";
- snprintf( tmp, sizeof(tmp),
- "DELETE FROM ldap_referrals "
- "WHERE entry_id=(SELECT id FROM ldap_entries "
- "WHERE oc_map_id=%lu"
- "AND keyval=?) and url=?",
- oc_map->bom_id );
- at_map->bam_delete_proc = ch_strdup( tmp );
- }
-
- at_map->bam_param_order = 0;
- at_map->bam_expect_return = 0;
- at_map->bam_next = NULL;
-
- backsql_make_attr_query( oc_map, at_map );
- if ( avl_insert( &oc_map->bom_attrs, at_map, backsql_cmp_attr, backsql_dup_attr ) == BACKSQL_DUPLICATE ) {
- Debug( LDAP_DEBUG_TRACE, "backsql_add_sysmaps(): "
- "duplicate attribute \"%s\" in objectClass \"%s\" map\n",
- at_map->bam_ad->ad_cname.bv_val,
- oc_map->bom_oc->soc_cname.bv_val, 0 );
- }
-
return 1;
}
"VALUES (?,?,?,?)";
char backsql_def_delobjclasses_stmt[] = "DELETE FROM ldap_entry_objclasses "
"WHERE entry_id=?";
-char backsql_def_delreferrals_stmt[] = "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,dn FROM ldap_entries WHERE ";