SQLHSTMT asth;
BACKSQL_ROW_NTS row;
+ assert( at );
+ if ( at->bam_delete_proc == NULL ) {
+ Debug( LDAP_DEBUG_TRACE,
+ " backsql_modify_delete_all_values(): "
+ "missing attribute value delete procedure "
+ "for attr \"%s\"\n",
+ at->bam_ad->ad_cname.bv_val, 0, 0 );
+ if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
+ rs->sr_text = "SQL-backend error";
+ return rs->sr_err = LDAP_OTHER;
+ }
+
+ return LDAP_SUCCESS;
+ }
+
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 );
+ "error preparing attribute value select query "
+ "\"%s\"\n",
+ at->bam_query, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh,
asth, rc );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
" backsql_modify_delete_all_values(): "
- "error binding key value parameter\n",
+ "error binding key value parameter "
+ "to attribute value select query\n",
0, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh,
asth, rc );
if ( !BACKSQL_SUCCESS( rc ) ) {
Debug( LDAP_DEBUG_TRACE,
" backsql_modify_delete_all_values(): "
- "error executing attribute query\n",
+ "error executing attribute value select query\n",
0, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh,
asth, rc );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
" backsql_modify_delete_all_values(): "
- "error preparing query %s\n",
+ "error preparing attribute value "
+ "delete procedure "
+ "\"%s\"\n",
at->bam_delete_proc, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh,
sth, rc );
goto done;
}
- rs->sr_err = backsql_dn2id( bi, NULL, dbh, &realndn );
+ rs->sr_err = backsql_dn2id( op, rs, NULL, dbh, &realndn );
if ( rs->sr_err == LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"entry exists\n",
goto done;
}
- rs->sr_err = backsql_dn2id( bi, &parent_id, dbh, &realpdn );
+ rs->sr_err = backsql_dn2id( op, rs, &parent_id, dbh, &realpdn );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"could not lookup parent entry for new record \"%s\"\n",
goto done;
}
- rs->sr_err = backsql_dn2id( bi, NULL, dbh, &realpdn );
+ rs->sr_err = backsql_dn2id( op, rs, NULL, dbh, &realpdn );
switch ( rs->sr_err ) {
case LDAP_NO_SUCH_OBJECT:
if ( !BER_BVISEMPTY( &pdn ) ) {
for ( ba2 = backsqlapi; ba2; ba2 = ba2->ba_next ) {
if ( strcasecmp( ba->ba_name, ba2->ba_name ) == 0 ) {
fprintf( stderr, "API module \"%s\" already defined\n", ba->ba_name );
- exit(EXIT_FAILURE);
+ exit( EXIT_FAILURE );
}
}
}
/* FIXME: API... */
- rs->sr_err = backsql_dn2id( bi, &e_id, dbh, &op->o_req_ndn );
+ rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_delete(): "
"could not lookup entry id\n", 0, 0, 0 );
*/
int
backsql_dn2id(
- backsql_info *bi,
+ Operation *op,
+ SlapReply *rs,
backsql_entryID *id,
SQLHDBC dbh,
struct berval *ndn )
{
+ backsql_info *bi = op->o_bd->be_private;
SQLHSTMT sth;
BACKSQL_ROW_NTS row;
RETCODE rc;
ber_str2bv( row.cols[ 3 ], 0, 0, &dn );
- res = dnPrettyNormal( NULL, &dn, &id->eid_dn, &id->eid_ndn, NULL );
- if ( res != LDAP_SUCCESS ) {
- Debug( LDAP_DEBUG_TRACE,
- "<==backsql_dn2id(\"%s\"): "
- "dnPrettyNormal failed (%d: %s)\n",
- ndn->bv_val, res,
- ldap_err2string( res ) );
+ if ( backsql_api_odbc2dn( op, rs, &dn ) ) {
+ res = LDAP_OTHER;
- /* cleanup... */
- (void)backsql_free_entryID( id, 0 );
+ } else {
+ res = dnPrettyNormal( NULL, &dn, &id->eid_dn, &id->eid_ndn, NULL );
+ if ( res != LDAP_SUCCESS ) {
+ Debug( LDAP_DEBUG_TRACE,
+ "<==backsql_dn2id(\"%s\"): "
+ "dnPrettyNormal failed (%d: %s)\n",
+ ndn->bv_val, res,
+ ldap_err2string( res ) );
+
+ /* cleanup... */
+ (void)backsql_free_entryID( id, 0 );
+ }
+
+ if ( dn.bv_val != row.cols[ 3 ] ) {
+ free( dn.bv_val );
+ }
}
id->eid_next = NULL;
}
/* FIXME: API... */
- rs->sr_err = backsql_dn2id( bi, &e_id, dbh, &op->o_req_ndn );
+ rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
"could not lookup entry id\n", 0, 0, 0 );
}
/* FIXME: API... */
- rs->sr_err = backsql_dn2id( bi, &e_id, dbh, &op->o_req_ndn );
+ rs->sr_err = backsql_dn2id( op, rs, &e_id, dbh, &op->o_req_ndn );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
"could not lookup entry id (%d)\n",
new_dn.bv_val, 0, 0 );
/* FIXME: API... */
- rs->sr_err = backsql_dn2id( bi, &pe_id, dbh, &p_ndn );
+ rs->sr_err = backsql_dn2id( op, rs, &pe_id, dbh, &p_ndn );
if ( rs->sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
"could not lookup old parent entry id\n", 0, 0, 0 );
(void)backsql_free_entryID( &pe_id, 0 );
/* FIXME: API... */
- rs->sr_err = backsql_dn2id( bi, &new_pe_id, dbh, new_npdn );
+ rs->sr_err = backsql_dn2id( op, rs, &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 );
#endif /* BACKSQL_ARBITRARY_KEY */
/* stores in *id the ID in table ldap_entries corresponding to DN, if any */
-int backsql_dn2id( backsql_info *bi, backsql_entryID *id,
+int backsql_dn2id( Operation *op, SlapReply *rs, backsql_entryID *id,
SQLHDBC dbh, struct berval *dn );
/* stores in *nchildren the count of children for an entry */
if ( at->bam_delete_proc != NULL ) {
ch_free( at->bam_delete_proc );
}
- if ( at->bam_query ) {
+ if ( at->bam_query != NULL ) {
ch_free( at->bam_query );
}
if ( ad == NULL ) {
ch_free( bsi->bsi_attrs );
bsi->bsi_attrs = NULL;
+ bsi->bsi_flags |= BSQL_SF_ALL_ATTRS;
return 1;
}
if ( get_base_id ) {
assert( op->o_bd->be_private );
- rc = backsql_dn2id( (backsql_info *)op->o_bd->be_private,
- &bsi->bsi_base_id, dbh, nbase );
+ rc = backsql_dn2id( op, rs, &bsi->bsi_base_id, dbh, nbase );
}
return ( bsi->bsi_status = rc );