From: Pierangelo Masarati Date: Mon, 25 Jul 2005 22:11:09 +0000 (+0000) Subject: use operation slab for column binding X-Git-Tag: OPENLDAP_AC_BP~194 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a6d9e7d933aac7817a45e5affba8fe6d3090e0f7;p=openldap use operation slab for column binding --- diff --git a/servers/slapd/back-sql/add.c b/servers/slapd/back-sql/add.c index 19a15021ab..38b6f64fa1 100644 --- a/servers/slapd/back-sql/add.c +++ b/servers/slapd/back-sql/add.c @@ -124,7 +124,7 @@ backsql_modify_delete_all_values( return rs->sr_err = LDAP_OTHER; } - backsql_BindRowAsStrings( asth, &row ); + backsql_BindRowAsStrings_x( asth, &row, op->o_tmpmemctx ); for ( rc = SQLFetch( asth ); BACKSQL_SUCCESS( rc ); rc = SQLFetch( asth ) ) @@ -151,7 +151,8 @@ backsql_modify_delete_all_values( sth, rc ); rs->sr_text = "SQL-backend error"; - return rs->sr_err = LDAP_OTHER; + rs->sr_err = LDAP_OTHER; + goto done; } if ( BACKSQL_IS_DEL( at->bam_expect_return ) ) { @@ -168,7 +169,8 @@ backsql_modify_delete_all_values( SQLFreeStmt( sth, SQL_DROP ); rs->sr_text = "SQL-backend error"; - return rs->sr_err = LDAP_OTHER; + rs->sr_err = LDAP_OTHER; + goto done; } } else { @@ -187,7 +189,8 @@ backsql_modify_delete_all_values( SQLFreeStmt( sth, SQL_DROP ); rs->sr_text = "SQL-backend error"; - return rs->sr_err = LDAP_OTHER; + rs->sr_err = LDAP_OTHER; + goto done; } #ifdef BACKSQL_ARBITRARY_KEY Debug( LDAP_DEBUG_TRACE, @@ -218,7 +221,8 @@ backsql_modify_delete_all_values( SQLFreeStmt( sth, SQL_DROP ); rs->sr_text = "SQL-backend error"; - return rs->sr_err = LDAP_OTHER; + rs->sr_err = LDAP_OTHER; + goto done; } Debug( LDAP_DEBUG_TRACE, @@ -248,15 +252,19 @@ backsql_modify_delete_all_values( } rs->sr_text = op->o_req_dn.bv_val; SQLFreeStmt( sth, SQL_DROP ); - return rs->sr_err; + goto done; } SQLFreeStmt( sth, SQL_DROP ); } } - backsql_FreeRow( &row ); + + rs->sr_err = LDAP_SUCCESS; + +done:; + backsql_FreeRow_x( &row, op->o_tmpmemctx ); SQLFreeStmt( asth, SQL_DROP ); - return LDAP_SUCCESS; + return rs->sr_err; } int diff --git a/servers/slapd/back-sql/delete.c b/servers/slapd/back-sql/delete.c index e8bf7142c6..d0d1ad064f 100644 --- a/servers/slapd/back-sql/delete.c +++ b/servers/slapd/back-sql/delete.c @@ -172,7 +172,7 @@ backsql_delete( Operation *op, SlapReply *rs ) goto done; } - rs->sr_err = backsql_has_children( bi, dbh, &op->o_req_ndn ); + rs->sr_err = backsql_has_children( op, dbh, &op->o_req_ndn ); switch ( rs->sr_err ) { case LDAP_COMPARE_FALSE: rs->sr_err = LDAP_SUCCESS; diff --git a/servers/slapd/back-sql/entry-id.c b/servers/slapd/back-sql/entry-id.c index 35f793cde2..9690774a09 100644 --- a/servers/slapd/back-sql/entry-id.c +++ b/servers/slapd/back-sql/entry-id.c @@ -231,7 +231,7 @@ backsql_dn2id( goto done; } - backsql_BindRowAsStrings( sth, &row ); + backsql_BindRowAsStrings_x( sth, &row, op->o_tmpmemctx ); rc = SQLFetch( sth ); if ( BACKSQL_SUCCESS( rc ) ) { char buf[ SLAP_TEXT_BUFLEN ]; @@ -324,9 +324,10 @@ backsql_dn2id( } } } - backsql_FreeRow( &row ); done:; + backsql_FreeRow_x( &row, op->o_tmpmemctx ); + Debug( LDAP_DEBUG_TRACE, "<==backsql_dn2id(\"%s\"): err=%d\n", ndn->bv_val, res, 0 ); @@ -343,11 +344,12 @@ done:; int backsql_count_children( - backsql_info *bi, + Operation *op, SQLHDBC dbh, struct berval *dn, unsigned long *nchildren ) { + backsql_info *bi = (backsql_info *)op->o_bd->be_private; SQLHSTMT sth = SQL_NULL_HSTMT; BACKSQL_ROW_NTS row; RETCODE rc; @@ -399,7 +401,7 @@ backsql_count_children( return LDAP_OTHER; } - backsql_BindRowAsStrings( sth, &row ); + backsql_BindRowAsStrings_x( sth, &row, op->o_tmpmemctx ); rc = SQLFetch( sth ); if ( BACKSQL_SUCCESS( rc ) ) { @@ -416,7 +418,7 @@ backsql_count_children( } else { res = LDAP_OTHER; } - backsql_FreeRow( &row ); + backsql_FreeRow_x( &row, op->o_tmpmemctx ); SQLFreeStmt( sth, SQL_DROP ); @@ -428,14 +430,14 @@ backsql_count_children( int backsql_has_children( - backsql_info *bi, + Operation *op, SQLHDBC dbh, struct berval *dn ) { unsigned long nchildren; int rc; - rc = backsql_count_children( bi, dbh, dn, &nchildren ); + rc = backsql_count_children( op, dbh, dn, &nchildren ); if ( rc == LDAP_SUCCESS ) { return nchildren > 0 ? LDAP_COMPARE_TRUE : LDAP_COMPARE_FALSE; @@ -455,7 +457,8 @@ backsql_get_attr_vals( void *v_at, void *v_bsi ) BACKSQL_ROW_NTS row; unsigned long i, k = 0, - oldcount = 0; + oldcount = 0, + res = 0; #ifdef BACKSQL_COUNTQUERY unsigned long count, countsize = sizeof( count ), @@ -651,7 +654,7 @@ backsql_get_attr_vals( void *v_at, void *v_bsi ) return 1; } - backsql_BindRowAsStrings( sth, &row ); + backsql_BindRowAsStrings_x( sth, &row, bsi->bsi_op->o_tmpmemctx ); #ifdef BACKSQL_COUNTQUERY j = oldcount; #endif /* BACKSQL_COUNTQUERY */ @@ -676,7 +679,8 @@ backsql_get_attr_vals( void *v_at, void *v_bsi ) "in schema (%d)\n", bsi->bsi_e->e_name.bv_val, row.col_names[ i ].bv_val, retval ); - return 1; + res = 1; + goto done; } if ( ad != at->bam_ad ) { @@ -687,7 +691,8 @@ backsql_get_attr_vals( void *v_at, void *v_bsi ) bsi->bsi_e->e_name.bv_val, ad->ad_cname.bv_val, at->bam_ad->ad_cname.bv_val ); - return 1; + res = 1; + goto done; } #endif /* BACKSQL_TRACE */ @@ -815,15 +820,21 @@ backsql_get_attr_vals( void *v_at, void *v_bsi ) } #endif /* BACKSQL_COUNTQUERY */ - backsql_FreeRow( &row ); SQLFreeStmt( sth, SQL_DROP ); Debug( LDAP_DEBUG_TRACE, "<==backsql_get_attr_vals()\n", 0, 0, 0 ); if ( at->bam_next ) { - return backsql_get_attr_vals( at->bam_next, v_bsi ); + res = backsql_get_attr_vals( at->bam_next, v_bsi ); + } else { + res = 1; } - return 1; +#ifdef BACKSQL_TRACE +done:; +#endif /* BACKSQL_TRACE */ + backsql_FreeRow_x( &row, bsi->bsi_op->o_tmpmemctx ); + + return res; } int diff --git a/servers/slapd/back-sql/modrdn.c b/servers/slapd/back-sql/modrdn.c index ce904498e2..4ad518e3bd 100644 --- a/servers/slapd/back-sql/modrdn.c +++ b/servers/slapd/back-sql/modrdn.c @@ -129,7 +129,7 @@ backsql_modrdn( Operation *op, SlapReply *rs ) goto done; } - if ( backsql_has_children( bi, dbh, &op->o_req_ndn ) == LDAP_COMPARE_TRUE ) { + if ( backsql_has_children( op, dbh, &op->o_req_ndn ) == LDAP_COMPARE_TRUE ) { Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): " "entry \"%s\" has children\n", op->o_req_dn.bv_val, 0, 0 ); diff --git a/servers/slapd/back-sql/operational.c b/servers/slapd/back-sql/operational.c index bb8eac5535..2fc2ac0855 100644 --- a/servers/slapd/back-sql/operational.c +++ b/servers/slapd/back-sql/operational.c @@ -158,7 +158,7 @@ backsql_operational( && !got[ BACKSQL_OP_HASSUBORDINATES ] && attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_hasSubordinates ) == NULL ) { - rc = backsql_has_children( bi, dbh, &rs->sr_entry->e_nname ); + rc = backsql_has_children( op, dbh, &rs->sr_entry->e_nname ); switch( rc ) { case LDAP_COMPARE_TRUE: diff --git a/servers/slapd/back-sql/proto-sql.h b/servers/slapd/back-sql/proto-sql.h index 3a5bd3e2d9..7300b3008a 100644 --- a/servers/slapd/back-sql/proto-sql.h +++ b/servers/slapd/back-sql/proto-sql.h @@ -116,12 +116,12 @@ int backsql_dn2id( Operation *op, SlapReply *rs, SQLHDBC dbh, int matched, int muck ); /* stores in *nchildren the count of children for an entry */ -int backsql_count_children( backsql_info *bi, SQLHDBC dbh, +int backsql_count_children( Operation *op, SQLHDBC dbh, struct berval *dn, unsigned long *nchildren ); /* returns LDAP_COMPARE_TRUE/LDAP_COMPARE_FALSE if the entry corresponding * to DN has/has not children */ -int backsql_has_children( backsql_info *bi, SQLHDBC dbh, struct berval *dn ); +int backsql_has_children( Operation *op, SQLHDBC dbh, struct berval *dn ); /* frees *id and returns next in list */ backsql_entryID *backsql_free_entryID( Operation *op, backsql_entryID *id, @@ -203,8 +203,12 @@ RETCODE backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char* query, int timeout ); backsql_BindParamInt( (sth), (par_ind), (io), (id) ) #endif /* ! BACKSQL_ARBITRARY_KEY */ +RETCODE backsql_BindRowAsStrings_x( SQLHSTMT sth, BACKSQL_ROW_NTS *row, void *ctx ); + RETCODE backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row ); +RETCODE backsql_FreeRow_x( BACKSQL_ROW_NTS *row, void *ctx ); + RETCODE backsql_FreeRow( BACKSQL_ROW_NTS *row ); void backsql_PrintErrors( SQLHENV henv, SQLHDBC hdbc, SQLHSTMT sth, int rc ); diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index 96f5c3a814..f6837cca04 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -1695,7 +1695,7 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) return BACKSQL_AVL_CONTINUE; } - backsql_BindRowAsStrings( sth, &row ); + backsql_BindRowAsStrings_x( sth, &row, bsi->bsi_op->o_tmpmemctx ); rc = SQLFetch( sth ); for ( ; BACKSQL_SUCCESS( rc ); rc = SQLFetch( sth ) ) { struct berval dn, pdn, ndn; @@ -1761,7 +1761,7 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) break; } } - backsql_FreeRow( &row ); + backsql_FreeRow_x( &row, bsi->bsi_op->o_tmpmemctx ); SQLFreeStmt( sth, SQL_DROP ); Debug( LDAP_DEBUG_TRACE, "<==backsql_oc_get_candidates(): %d\n", @@ -2131,7 +2131,7 @@ backsql_search( Operation *op, SlapReply *rs ) * filter_has_subordinates() */ if ( bsi.bsi_flags & BSQL_SF_FILTER_HASSUBORDINATE ) { - rc = backsql_has_children( bi, dbh, &e->e_nname ); + rc = backsql_has_children( op, dbh, &e->e_nname ); switch ( rc ) { case LDAP_COMPARE_TRUE: diff --git a/servers/slapd/back-sql/sql-wrap.c b/servers/slapd/back-sql/sql-wrap.c index e97bb06095..79738eb929 100644 --- a/servers/slapd/back-sql/sql-wrap.c +++ b/servers/slapd/back-sql/sql-wrap.c @@ -130,7 +130,7 @@ backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout ) } RETCODE -backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row ) +backsql_BindRowAsStrings_x( SQLHSTMT sth, BACKSQL_ROW_NTS *row, void *ctx ) { RETCODE rc; SQLCHAR colname[ 64 ]; @@ -161,62 +161,45 @@ backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row ) "ncols=%d\n", (int)row->ncols, 0, 0 ); #endif /* BACKSQL_TRACE */ - row->col_names = (BerVarray)ch_calloc( row->ncols + 1, - sizeof( struct berval ) ); - row->cols = (char **)ch_calloc( row->ncols + 1, - sizeof( char * ) ); - row->col_prec = (UDWORD *)ch_calloc( row->ncols, - sizeof( UDWORD ) ); - row->value_len = (SQLINTEGER *)ch_calloc( row->ncols, - sizeof( SQLINTEGER ) ); + row->col_names = (BerVarray)ber_memcalloc_x( row->ncols + 1, + sizeof( struct berval ), ctx ); + row->cols = (char **)ber_memcalloc_x( row->ncols + 1, + sizeof( char * ), ctx ); + row->col_prec = (UDWORD *)ber_memcalloc_x( row->ncols, + sizeof( UDWORD ), ctx ); + row->value_len = (SQLINTEGER *)ber_memcalloc_x( row->ncols, + sizeof( SQLINTEGER ), ctx ); for ( i = 1; i <= row->ncols; i++ ) { rc = SQLDescribeCol( sth, (SQLSMALLINT)i, &colname[ 0 ], (SQLUINTEGER)( sizeof( colname ) - 1 ), &name_len, &col_type, &col_prec, &col_scale, &col_null ); - ber_str2bv( (char *)colname, 0, 1, &row->col_names[ i - 1 ] ); + /* FIXME: test rc? */ + + ber_str2bv_x( (char *)colname, 0, 1, + &row->col_names[ i - 1 ], ctx ); #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "backsql_BindRowAsStrings: " "col_name=%s, col_prec[%d]=%d\n", colname, (int)i, (int)col_prec ); #endif /* BACKSQL_TRACE */ - if ( col_type == SQL_LONGVARCHAR - || col_type == SQL_LONGVARBINARY) { -#if 0 - row->cols[ i - 1 ] = NULL; - row->col_prec[ i - 1 ] = -1; - - /* - * such fields must be handled - * in some other way since they return 2G - * as their precision (at least it does so - * with MS SQL Server w/native driver) - * for now, we just set fixed precision - * for such fields - dirty hack, but... - * no time to deal with SQLGetData() - */ -#endif + if ( col_type != SQL_CHAR && col_type != SQL_VARCHAR ) + { col_prec = MAX_ATTR_LEN; - row->cols[ i - 1 ] = (char *)ch_calloc( col_prec + 1, sizeof( char ) ); - row->col_prec[ i - 1 ] = col_prec; - rc = SQLBindCol( sth, (SQLUSMALLINT)i, - SQL_C_CHAR, - (SQLPOINTER)row->cols[ i - 1 ], - col_prec + 1, - &row->value_len[ i - 1 ] ); - } else { - row->cols[ i - 1 ] = (char *)ch_calloc( col_prec + 1, sizeof( char ) ); - row->col_prec[ i - 1 ] = col_prec; - rc = SQLBindCol( sth, (SQLUSMALLINT)i, - SQL_C_CHAR, - (SQLPOINTER)row->cols[ i - 1 ], - col_prec + 1, - &row->value_len[ i - 1 ] ); } + + row->cols[ i - 1 ] = (char *)ber_memcalloc_x( col_prec + 1, + sizeof( char ), ctx ); + row->col_prec[ i - 1 ] = col_prec; + rc = SQLBindCol( sth, (SQLUSMALLINT)i, + SQL_C_CHAR, + (SQLPOINTER)row->cols[ i - 1 ], + col_prec + 1, + &row->value_len[ i - 1 ] ); + /* FIXME: test rc? */ } - row->col_names[ i - 1 ].bv_val = NULL; - row->col_names[ i - 1 ].bv_len = 0; + BER_BVZERO( &row->col_names[ i - 1 ] ); row->cols[ i - 1 ] = NULL; } @@ -228,20 +211,33 @@ backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row ) } RETCODE -backsql_FreeRow( BACKSQL_ROW_NTS *row ) +backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row ) +{ + return backsql_BindRowAsStrings_x( sth, row, NULL ); +} + +RETCODE +backsql_FreeRow_x( BACKSQL_ROW_NTS *row, void *ctx ) { if ( row->cols == NULL ) { return SQL_ERROR; } - ber_bvarray_free( row->col_names ); - ldap_charray_free( row->cols ); - free( row->col_prec ); - free( row->value_len ); + ber_bvarray_free_x( row->col_names, ctx ); + ber_memvfree_x( (void **)row->cols, ctx ); + ber_memfree_x( row->col_prec, ctx ); + ber_memfree_x( row->value_len, ctx ); return SQL_SUCCESS; } + +RETCODE +backsql_FreeRow( BACKSQL_ROW_NTS *row ) +{ + return backsql_FreeRow_x( row, NULL ); +} + static int backsql_cmp_connid( const void *v_c1, const void *v_c2 ) {