various fixes and improvements

This commit is contained in:
Pierangelo Masarati 2002-09-02 19:39:31 +00:00
parent 857d08ea21
commit eb38db1be5
7 changed files with 192 additions and 172 deletions

View file

@ -164,22 +164,23 @@ backsql_dn2id(
} }
int int
backsql_has_children( backsql_count_children(
backsql_info *bi, backsql_info *bi,
SQLHDBC dbh, SQLHDBC dbh,
struct berval *dn ) struct berval *dn,
unsigned long *nchildren )
{ {
SQLHSTMT sth; SQLHSTMT sth;
BACKSQL_ROW_NTS row; BACKSQL_ROW_NTS row;
RETCODE rc; RETCODE rc;
int res; int res = LDAP_SUCCESS;
Debug( LDAP_DEBUG_TRACE, "==>backsql_has_children(): dn='%s'\n", Debug( LDAP_DEBUG_TRACE, "==>backsql_count_children(): dn='%s'\n",
dn->bv_val, 0, 0 ); dn->bv_val, 0, 0 );
if ( dn->bv_len > BACKSQL_MAX_DN_LEN ) { if ( dn->bv_len > BACKSQL_MAX_DN_LEN ) {
Debug( LDAP_DEBUG_TRACE, Debug( LDAP_DEBUG_TRACE,
"backsql_has_children(): DN \"%s\" (%ld bytes) " "backsql_count_children(): DN \"%s\" (%ld bytes) "
"exceeds max DN length (%d):\n", "exceeds max DN length (%d):\n",
dn->bv_val, dn->bv_len, BACKSQL_MAX_DN_LEN ); dn->bv_val, dn->bv_len, BACKSQL_MAX_DN_LEN );
return LDAP_OTHER; return LDAP_OTHER;
@ -192,7 +193,7 @@ backsql_has_children(
rc = backsql_Prepare( dbh, &sth, bi->has_children_query, 0 ); rc = backsql_Prepare( dbh, &sth, bi->has_children_query, 0 );
if ( rc != SQL_SUCCESS ) { if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, Debug( LDAP_DEBUG_TRACE,
"backsql_has_children(): error preparing SQL:\n%s", "backsql_count_children(): error preparing SQL:\n%s",
bi->has_children_query, 0, 0); bi->has_children_query, 0, 0);
backsql_PrintErrors( SQL_NULL_HENV, dbh, sth, rc ); backsql_PrintErrors( SQL_NULL_HENV, dbh, sth, rc );
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
@ -202,7 +203,7 @@ backsql_has_children(
rc = backsql_BindParamStr( sth, 1, dn->bv_val, BACKSQL_MAX_DN_LEN ); rc = backsql_BindParamStr( sth, 1, dn->bv_val, BACKSQL_MAX_DN_LEN );
if ( rc != SQL_SUCCESS) { if ( rc != SQL_SUCCESS) {
/* end TimesTen */ /* end TimesTen */
Debug( LDAP_DEBUG_TRACE, "backsql_has_children(): " Debug( LDAP_DEBUG_TRACE, "backsql_count_children(): "
"error binding dn=\"%s\" parameter:\n", "error binding dn=\"%s\" parameter:\n",
dn->bv_val, 0, 0 ); dn->bv_val, 0, 0 );
backsql_PrintErrors( SQL_NULL_HENV, dbh, sth, rc ); backsql_PrintErrors( SQL_NULL_HENV, dbh, sth, rc );
@ -212,7 +213,7 @@ backsql_has_children(
rc = SQLExecute( sth ); rc = SQLExecute( sth );
if ( rc != SQL_SUCCESS ) { if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_has_children(): " Debug( LDAP_DEBUG_TRACE, "backsql_count_children(): "
"error executing query (\"%s\", \"%s\"):\n", "error executing query (\"%s\", \"%s\"):\n",
bi->has_children_query, dn->bv_val, 0 ); bi->has_children_query, dn->bv_val, 0 );
backsql_PrintErrors( SQL_NULL_HENV, dbh, sth, rc ); backsql_PrintErrors( SQL_NULL_HENV, dbh, sth, rc );
@ -224,10 +225,11 @@ backsql_has_children(
rc = SQLFetch( sth ); rc = SQLFetch( sth );
if ( BACKSQL_SUCCESS( rc ) ) { if ( BACKSQL_SUCCESS( rc ) ) {
if ( strtol( row.cols[ 0 ], NULL, 0 ) > 0 ) { char *end;
res = LDAP_COMPARE_TRUE;
} else { *nchildren = strtol( row.cols[ 0 ], &end, 0 );
res = LDAP_COMPARE_FALSE; if ( end[ 0 ] != '\0' ) {
res = LDAP_OTHER;
} }
} else { } else {
@ -237,12 +239,30 @@ backsql_has_children(
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
Debug( LDAP_DEBUG_TRACE, "<==backsql_has_children(): %s\n", Debug( LDAP_DEBUG_TRACE, "<==backsql_count_children(): %lu\n",
res == LDAP_COMPARE_TRUE ? "yes" : "no", 0, 0 ); *nchildren, 0, 0 );
return res; return res;
} }
int
backsql_has_children(
backsql_info *bi,
SQLHDBC dbh,
struct berval *dn )
{
unsigned long nchildren;
int rc;
rc = backsql_count_children( bi, dbh, dn, &nchildren );
if ( rc == LDAP_SUCCESS ) {
return nchildren > 0 ? LDAP_COMPARE_TRUE : LDAP_COMPARE_FALSE;
}
return rc;
}
int int
backsql_get_attr_vals( backsql_at_map_rec *at, backsql_srch_info *bsi ) backsql_get_attr_vals( backsql_at_map_rec *at, backsql_srch_info *bsi )
{ {
@ -289,7 +309,7 @@ backsql_get_attr_vals( backsql_at_map_rec *at, backsql_srch_info *bsi )
rc = SQLFetch( sth ); rc = SQLFetch( sth );
for ( ; BACKSQL_SUCCESS( rc ); rc = SQLFetch( sth ) ) { for ( ; BACKSQL_SUCCESS( rc ); rc = SQLFetch( sth ) ) {
for ( i = 0; i < row.ncols; i++ ) { for ( i = 0; i < row.ncols; i++ ) {
if ( row.is_null[ i ] > 0 ) { if ( row.value_len[ i ] > 0 ) {
struct berval bv; struct berval bv;
bv.bv_val = row.cols[ i ]; bv.bv_val = row.cols[ i ];

View file

@ -21,8 +21,12 @@ typedef struct backsql_entryID {
int backsql_dn2id( backsql_info *bi, backsql_entryID *id, int backsql_dn2id( backsql_info *bi, backsql_entryID *id,
SQLHDBC dbh, struct berval *dn ); SQLHDBC dbh, struct berval *dn );
int backsql_count_children( backsql_info *bi, SQLHDBC dbh,
struct berval *dn, unsigned long *nchildren );
int backsql_has_children( backsql_info *bi, SQLHDBC dbh, struct berval *dn ); int backsql_has_children( backsql_info *bi, SQLHDBC dbh, struct berval *dn );
/* returns next */ /* returns next */
backsql_entryID *backsql_free_entryID( backsql_entryID *id, int freeit ); backsql_entryID *backsql_free_entryID( backsql_entryID *id, int freeit );

View file

@ -44,13 +44,16 @@
static int static int
backsql_modify_internal( backsql_modify_internal(
backsql_info *bi, BackendDB *be,
Connection *conn,
Operation *op,
SQLHDBC dbh, SQLHDBC dbh,
backsql_oc_map_rec *oc, backsql_oc_map_rec *oc,
backsql_entryID *e_id, backsql_entryID *e_id,
Modifications *modlist, Modifications *modlist,
const char **text ) const char **text )
{ {
backsql_info *bi = (backsql_info*)be->be_private;
RETCODE rc; RETCODE rc;
SQLHSTMT sth; SQLHSTMT sth;
Modifications *ml; Modifications *ml;
@ -490,7 +493,7 @@ backsql_modify(
* FIXME: we don't want to send back * FIXME: we don't want to send back
* excessively detailed messages * excessively detailed messages
*/ */
send_ldap_result( conn, op, res, "", send_ldap_result( conn, op, res, NULL,
res == LDAP_OTHER ? "SQL-backend error" : "", res == LDAP_OTHER ? "SQL-backend error" : "",
NULL, NULL ); NULL, NULL );
return 1; return 1;
@ -500,7 +503,7 @@ backsql_modify(
if ( res != LDAP_SUCCESS ) { if ( res != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_modify(): " Debug( LDAP_DEBUG_TRACE, "backsql_modify(): "
"could not lookup entry id\n", 0, 0, 0 ); "could not lookup entry id\n", 0, 0, 0 );
send_ldap_result( conn, op, res , "", send_ldap_result( conn, op, res , NULL,
res == LDAP_OTHER ? "SQL-backend error" : "", res == LDAP_OTHER ? "SQL-backend error" : "",
NULL, NULL ); NULL, NULL );
return 1; return 1;
@ -523,7 +526,7 @@ backsql_modify(
* FIXME: we don't want to send back * FIXME: we don't want to send back
* excessively detailed messages * excessively detailed messages
*/ */
send_ldap_result( conn, op, LDAP_OTHER, "", send_ldap_result( conn, op, LDAP_OTHER, NULL,
"SQL-backend error", NULL, NULL ); "SQL-backend error", NULL, NULL );
return 1; return 1;
} }
@ -535,19 +538,13 @@ backsql_modify(
res = LDAP_INSUFFICIENT_ACCESS; res = LDAP_INSUFFICIENT_ACCESS;
} else { } else {
res = backsql_modify_internal( bi, dbh, oc, &e_id, res = backsql_modify_internal( be, conn, op,
modlist, &text ); dbh, oc, &e_id, modlist, &text );
} }
if ( res == LDAP_SUCCESS ) { if ( res == LDAP_SUCCESS ) {
/* /*
* Commit only if all operations succeed * Commit only if all operations succeed
*
* FIXME: backsql_modify_internal() does not fail
* if add/delete operations are not available, or
* if a multiple value add actually results in a replace,
* or if a single operation on an attribute fails
* for any reason
*/ */
SQLTransact( SQL_NULL_HENV, dbh, SQLTransact( SQL_NULL_HENV, dbh,
op->o_noop ? SQL_ROLLBACK : SQL_COMMIT ); op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
@ -555,7 +552,7 @@ backsql_modify(
send_ldap_result( conn, op, res, NULL, text, NULL, NULL ); send_ldap_result( conn, op, res, NULL, text, NULL, NULL );
Debug( LDAP_DEBUG_TRACE, "<==backsql_modify()\n", 0, 0, 0 ); Debug( LDAP_DEBUG_TRACE, "<==backsql_modify()\n", 0, 0, 0 );
return 0; return op->o_noop;
} }
int int
@ -596,7 +593,7 @@ backsql_modrdn(
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): " Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
"could not get connection handle - exiting\n", "could not get connection handle - exiting\n",
0, 0, 0 ); 0, 0, 0 );
send_ldap_result( conn, op, res, "", send_ldap_result( conn, op, res, NULL,
res == LDAP_OTHER ? "SQL-backend error" : "", res == LDAP_OTHER ? "SQL-backend error" : "",
NULL, NULL ); NULL, NULL );
return 1; return 1;
@ -606,7 +603,7 @@ backsql_modrdn(
if ( res != LDAP_SUCCESS ) { if ( res != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): " Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
"could not lookup entry id\n", 0, 0, 0 ); "could not lookup entry id\n", 0, 0, 0 );
send_ldap_result( conn, op, res, "", send_ldap_result( conn, op, res, NULL,
res == LDAP_OTHER ? "SQL-backend error" : "", res == LDAP_OTHER ? "SQL-backend error" : "",
NULL, NULL ); NULL, NULL );
return 1; return 1;
@ -638,7 +635,7 @@ backsql_modrdn(
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): " Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
"parent is \"\" - aborting\n", 0, 0, 0 ); "parent is \"\" - aborting\n", 0, 0, 0 );
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
"", "not allowed within namingContext", NULL, "not allowed within namingContext",
NULL, NULL ); NULL, NULL );
goto modrdn_return; goto modrdn_return;
} }
@ -664,7 +661,8 @@ backsql_modrdn(
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): " Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
"newSuperior is \"\" - aborting\n", 0, 0, 0 ); "newSuperior is \"\" - aborting\n", 0, 0, 0 );
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
"", "not allowed within namingContext", NULL,
"not allowed within namingContext",
NULL, NULL ); NULL, NULL );
goto modrdn_return; goto modrdn_return;
} }
@ -703,8 +701,9 @@ backsql_modrdn(
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): " Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
"newSuperior is equal to entry being moved " "newSuperior is equal to entry being moved "
"- aborting\n", 0, 0, 0 ); "- aborting\n", 0, 0, 0 );
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
NULL, NULL, NULL ); NULL, "newSuperior is equal to old DN",
NULL, NULL );
goto modrdn_return; goto modrdn_return;
} }
@ -713,8 +712,8 @@ backsql_modrdn(
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): " Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
"new dn is invalid ('%s') - aborting\n", "new dn is invalid ('%s') - aborting\n",
new_dn.bv_val, 0, 0 ); new_dn.bv_val, 0, 0 );
send_ldap_result( conn, op, LDAP_INVALID_DN_SYNTAX, "", send_ldap_result( conn, op, LDAP_INVALID_DN_SYNTAX,
NULL, NULL, NULL ); NULL, "new DN is invalid", NULL, NULL );
goto modrdn_return; goto modrdn_return;
} }
@ -725,7 +724,7 @@ backsql_modrdn(
if ( res != LDAP_SUCCESS ) { if ( res != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): " Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
"could not lookup old parent entry id\n", 0, 0, 0 ); "could not lookup old parent entry id\n", 0, 0, 0 );
send_ldap_result( conn, op, res, "", send_ldap_result( conn, op, res, NULL,
res == LDAP_OTHER ? "SQL-backend error" : "", res == LDAP_OTHER ? "SQL-backend error" : "",
NULL, NULL ); NULL, NULL );
goto modrdn_return; goto modrdn_return;
@ -738,7 +737,7 @@ backsql_modrdn(
if ( res != LDAP_SUCCESS ) { if ( res != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): " Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
"could not lookup new parent entry id\n", 0, 0, 0 ); "could not lookup new parent entry id\n", 0, 0, 0 );
send_ldap_result( conn, op, res, "", send_ldap_result( conn, op, res, NULL,
res == LDAP_OTHER ? "SQL-backend error" : "", res == LDAP_OTHER ? "SQL-backend error" : "",
NULL, NULL ); NULL, NULL );
goto modrdn_return; goto modrdn_return;
@ -759,8 +758,8 @@ backsql_modrdn(
"failed to delete record from ldap_entries\n", "failed to delete record from ldap_entries\n",
0, 0, 0 ); 0, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc ); backsql_PrintErrors( bi->db_env, dbh, sth, rc );
send_ldap_result( conn, op, LDAP_OTHER, "", send_ldap_result( conn, op, LDAP_OTHER,
"SQL-backend error", NULL, NULL ); NULL, "SQL-backend error", NULL, NULL );
goto modrdn_return; goto modrdn_return;
} }
@ -780,8 +779,8 @@ backsql_modrdn(
Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): " Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
"could not insert ldap_entries record\n", 0, 0, 0 ); "could not insert ldap_entries record\n", 0, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc ); backsql_PrintErrors( bi->db_env, dbh, sth, rc );
send_ldap_result( conn, op, LDAP_OTHER, "", send_ldap_result( conn, op, LDAP_OTHER,
"SQL-backend error", NULL, NULL ); NULL, "SQL-backend error", NULL, NULL );
goto modrdn_return; goto modrdn_return;
} }
@ -853,18 +852,13 @@ backsql_modrdn(
} }
oc = backsql_id2oc( bi, e_id.oc_id ); oc = backsql_id2oc( bi, e_id.oc_id );
res = backsql_modify_internal( bi, dbh, oc, &e_id, mod, &text ); res = backsql_modify_internal( be, conn, op,
dbh, oc, &e_id, mod, &text );
if ( res == LDAP_SUCCESS ) { if ( res == LDAP_SUCCESS ) {
/* /*
* Commit only if all operations succeed * Commit only if all operations succeed
*
* FIXME: backsql_modify_internal() does not fail
* if add/delete operations are not available, or
* if a multiple value add actually results in a replace,
* or if a single operation on an attribute fails for any
* reason
*/ */
SQLTransact( SQL_NULL_HENV, dbh, SQLTransact( SQL_NULL_HENV, dbh,
op->o_noop ? SQL_ROLLBACK : SQL_COMMIT ); op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
@ -896,10 +890,10 @@ modrdn_return:
} }
} }
send_ldap_result( conn, op, res, "", text, NULL, NULL ); send_ldap_result( conn, op, res, NULL, text, NULL, NULL );
Debug( LDAP_DEBUG_TRACE, "<==backsql_modrdn()\n", 0, 0, 0 ); Debug( LDAP_DEBUG_TRACE, "<==backsql_modrdn()\n", 0, 0, 0 );
return 0; return op->o_noop;
} }
int int
@ -931,38 +925,44 @@ backsql_add(
Debug( LDAP_DEBUG_TRACE, "==>backsql_add(): adding entry '%s'\n", Debug( LDAP_DEBUG_TRACE, "==>backsql_add(): adding entry '%s'\n",
e->e_name.bv_val, 0, 0 ); e->e_name.bv_val, 0, 0 );
/* check schema */
if ( global_schemacheck ) {
const char *text = NULL;
char textbuf[ SLAP_TEXT_BUFLEN ] = { '\0' };
int rc;
rc = entry_schema_check( be, e, NULL,
&text, textbuf, sizeof( textbuf ) );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
"entry failed schema check -- aborting\n",
0, 0, 0 );
send_ldap_result( conn, op, rc, NULL,
"operation not permitted "
"within namingContext",
NULL, NULL );
return 1;
}
}
/* search structural objectClass */
for ( at = e->e_attrs; at != NULL; at = at->a_next ) { for ( at = e->e_attrs; at != NULL; at = at->a_next ) {
if ( at->a_desc == slap_schema.si_ad_objectClass ) { if ( at->a_desc == slap_schema.si_ad_structuralObjectClass ) {
if ( global_schemacheck ) {
const char *text = NULL;
char textbuf[ 1024 ];
size_t textlen = sizeof( textbuf );
struct berval soc;
int rc = structural_class( at->a_vals, &soc,
NULL, &text, textbuf, textlen );
if ( rc != LDAP_SUCCESS ) {
break;
}
oc = backsql_name2oc( bi, &soc );
} else {
/*
* FIXME: only the objectClass provided first
* is considered when creating a new entry
*/
oc = backsql_name2oc( bi, &at->a_vals[ 0 ] );
}
break; break;
} }
} }
/* there must exist */
assert( at != NULL );
/* I guess we should play with sub/supertypes to find a suitable oc */
oc = backsql_name2oc( bi, &at->a_vals[0] );
if ( oc == NULL ) { if ( oc == NULL ) {
Debug( LDAP_DEBUG_TRACE, "backsql_add(): " Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
"cannot determine objectclass of entry -- aborting\n", "cannot determine objectclass of entry -- aborting\n",
0, 0, 0 ); 0, 0, 0 );
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, "", send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
"operation not permitted within namingContext", "operation not permitted within namingContext",
NULL, NULL ); NULL, NULL );
return 1; return 1;
@ -972,7 +972,7 @@ backsql_add(
Debug( LDAP_DEBUG_TRACE, "backsql_add(): " Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
"create procedure is not defined for this objectclass " "create procedure is not defined for this objectclass "
"- aborting\n", 0, 0, 0 ); "- aborting\n", 0, 0, 0 );
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, "", send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
"operation not permitted within namingContext", "operation not permitted within namingContext",
NULL, NULL ); NULL, NULL );
return 1; return 1;
@ -980,9 +980,9 @@ backsql_add(
} else if ( BACKSQL_CREATE_NEEDS_SELECT( bi ) } else if ( BACKSQL_CREATE_NEEDS_SELECT( bi )
&& oc->create_keyval == NULL ) { && oc->create_keyval == NULL ) {
Debug( LDAP_DEBUG_TRACE, "backsql_add(): " Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
"create procedure needs select, but none is defined" "create procedure needs select procedure, "
"- aborting\n", 0, 0, 0 ); "but none is defined - aborting\n", 0, 0, 0 );
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, "", send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
"operation not permitted within namingContext", "operation not permitted within namingContext",
NULL, NULL ); NULL, NULL );
return 1; return 1;
@ -993,7 +993,7 @@ backsql_add(
Debug( LDAP_DEBUG_TRACE, "backsql_add(): " Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
"could not get connection handle - exiting\n", "could not get connection handle - exiting\n",
0, 0, 0 ); 0, 0, 0 );
send_ldap_result( conn, op, prc, "", send_ldap_result( conn, op, prc, NULL,
prc == LDAP_OTHER ? "SQL-backend error" : "", prc == LDAP_OTHER ? "SQL-backend error" : "",
NULL, NULL ); NULL, NULL );
return 1; return 1;
@ -1007,8 +1007,8 @@ backsql_add(
Debug( LDAP_DEBUG_TRACE, "backsql_add(): " Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
"entry '%s' exists\n", "entry '%s' exists\n",
e->e_name.bv_val, 0, 0 ); e->e_name.bv_val, 0, 0 );
send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, "", send_ldap_result( conn, op, LDAP_ALREADY_EXISTS,
NULL, NULL, NULL ); NULL, NULL, NULL, NULL );
return 1; return 1;
} }
@ -1027,7 +1027,8 @@ backsql_add(
pdn.bv_val, 0, 0 ); pdn.bv_val, 0, 0 );
if ( res != LDAP_NO_SUCH_OBJECT ) { if ( res != LDAP_NO_SUCH_OBJECT ) {
send_ldap_result( conn, op, res, "", NULL, NULL, NULL ); send_ldap_result( conn, op, res,
NULL, NULL, NULL, NULL );
return 1; return 1;
} }
@ -1036,7 +1037,7 @@ backsql_add(
*/ */
while ( 1 ) { while ( 1 ) {
struct berval dn; struct berval dn;
char *matched = ""; char *matched = NULL;
dn = pdn; dn = pdn;
dnParent( &dn, &pdn ); dnParent( &dn, &pdn );
@ -1057,8 +1058,8 @@ backsql_add(
/* fail over to next case */ /* fail over to next case */
default: default:
send_ldap_result( conn, op, res, matched, send_ldap_result( conn, op, res,
NULL, NULL, NULL ); matched, NULL, NULL, NULL );
return 1; return 1;
} }
} }
@ -1081,14 +1082,10 @@ backsql_add(
return 1; return 1;
} }
#ifndef BACKSQL_REALLOC_STMT
rc = SQLAllocStmt( dbh, &sth ); rc = SQLAllocStmt( dbh, &sth );
#else /* BACKSQL_REALLOC_STMT */
rc = backsql_Prepare( dbh, &sth, oc->create_proc, 0 );
#endif /* BACKSQL_REALLOC_STMT */
if ( rc != SQL_SUCCESS ) { if ( rc != SQL_SUCCESS ) {
send_ldap_result( conn, op, LDAP_OTHER, "", send_ldap_result( conn, op, LDAP_OTHER,
"SQL-backend error", NULL, NULL ); NULL, "SQL-backend error", NULL, NULL );
return 1; return 1;
} }
@ -1099,24 +1096,23 @@ backsql_add(
Debug( LDAP_DEBUG_TRACE, "backsql_add(): executing '%s'\n", Debug( LDAP_DEBUG_TRACE, "backsql_add(): executing '%s'\n",
oc->create_proc, 0, 0 ); oc->create_proc, 0, 0 );
#ifndef BACKSQL_REALLOC_STMT
rc = SQLExecDirect( sth, oc->create_proc, SQL_NTS ); rc = SQLExecDirect( sth, oc->create_proc, SQL_NTS );
#else /* BACKSQL_REALLOC_STMT */
rc = SQLExecute( sth );
#endif /* BACKSQL_REALLOC_STMT */
if ( rc != SQL_SUCCESS ) { if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_add(): " Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
"create_proc execution failed\n", 0, 0, 0 ); "create_proc execution failed\n", 0, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc); backsql_PrintErrors( bi->db_env, dbh, sth, rc);
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
send_ldap_result( conn, op, LDAP_OTHER, "", send_ldap_result( conn, op, LDAP_OTHER,
"SQL-backend error", NULL, NULL ); NULL, "SQL-backend error", NULL, NULL );
return 1; return 1;
} }
if ( op->o_noop ) {
SQLTransact( SQL_NULL_HENV, dbh, SQL_ROLLBACK );
}
if ( !BACKSQL_IS_ADD( oc->expect_return ) ) { if ( !BACKSQL_IS_ADD( oc->expect_return ) ) {
SWORD ncols; SWORD ncols;
SQLINTEGER is_null; SQLINTEGER value_len;
if ( BACKSQL_CREATE_NEEDS_SELECT( bi ) ) { if ( BACKSQL_CREATE_NEEDS_SELECT( bi ) ) {
#ifndef BACKSQL_REALLOC_STMT #ifndef BACKSQL_REALLOC_STMT
@ -1125,16 +1121,18 @@ backsql_add(
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
rc = SQLAllocStmt( dbh, &sth ); rc = SQLAllocStmt( dbh, &sth );
if ( rc != SQL_SUCCESS ) { if ( rc != SQL_SUCCESS ) {
send_ldap_result( conn, op, LDAP_OTHER, "", send_ldap_result( conn, op, LDAP_OTHER,
"SQL-backend error", NULL, NULL ); NULL, "SQL-backend error",
NULL, NULL );
return 1; return 1;
} }
#endif /* BACKSQL_REALLOC_STMT */ #endif /* BACKSQL_REALLOC_STMT */
rc = SQLExecDirect( sth, oc->create_keyval, SQL_NTS ); rc = SQLExecDirect( sth, oc->create_keyval, SQL_NTS );
if ( rc != SQL_SUCCESS ) { if ( rc != SQL_SUCCESS ) {
send_ldap_result( conn, op, LDAP_OTHER, "", send_ldap_result( conn, op, LDAP_OTHER,
"SQL-backend error", NULL, NULL ); NULL, "SQL-backend error",
NULL, NULL );
return 1; return 1;
} }
} }
@ -1150,8 +1148,8 @@ backsql_add(
0, 0, 0 ); 0, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc); backsql_PrintErrors( bi->db_env, dbh, sth, rc);
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
send_ldap_result( conn, op, LDAP_OTHER, "", send_ldap_result( conn, op, LDAP_OTHER,
"SQL-backend error", NULL, NULL ); NULL, "SQL-backend error", NULL, NULL );
return 1; return 1;
} else if ( ncols != 1 ) { } else if ( ncols != 1 ) {
@ -1160,8 +1158,8 @@ backsql_add(
ncols, 0, 0 ); ncols, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc); backsql_PrintErrors( bi->db_env, dbh, sth, rc);
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
send_ldap_result( conn, op, LDAP_OTHER, "", send_ldap_result( conn, op, LDAP_OTHER,
"SQL-backend error", NULL, NULL ); NULL, "SQL-backend error", NULL, NULL );
return 1; return 1;
} }
@ -1186,25 +1184,20 @@ backsql_add(
rc = SQLBindCol( sth, (SQLUSMALLINT)1, SQL_C_ULONG, rc = SQLBindCol( sth, (SQLUSMALLINT)1, SQL_C_ULONG,
(SQLPOINTER)&new_keyval, (SQLPOINTER)&new_keyval,
(SQLINTEGER)sizeof( new_keyval ), (SQLINTEGER)sizeof( new_keyval ),
&is_null ); &value_len );
rc = SQLFetch( sth ); rc = SQLFetch( sth );
#if 0 if ( value_len <= 0 ) {
/*
* FIXME: what does is_null mean?
*/
if ( is_null ) {
Debug( LDAP_DEBUG_TRACE, "backsql_add(): " Debug( LDAP_DEBUG_TRACE, "backsql_add(): "
"create_proc result is null\n", "create_proc result is empty?\n",
0, 0, 0 ); 0, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc); backsql_PrintErrors( bi->db_env, dbh, sth, rc);
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
send_ldap_result( conn, op, LDAP_OTHER, "", send_ldap_result( conn, op, LDAP_OTHER,
"SQL-backend error", NULL, NULL ); NULL, "SQL-backend error", NULL, NULL );
return 1; return 1;
} }
#endif
} }
#ifndef BACKSQL_REALLOC_STMT #ifndef BACKSQL_REALLOC_STMT
@ -1245,7 +1238,7 @@ backsql_add(
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) { if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
send_ldap_result( conn, op, send_ldap_result( conn, op,
LDAP_UNWILLING_TO_PERFORM, "", LDAP_UNWILLING_TO_PERFORM, NULL,
"operation not permitted " "operation not permitted "
"within namingContext", "within namingContext",
NULL, NULL ); NULL, NULL );
@ -1263,7 +1256,7 @@ backsql_add(
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) { if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
send_ldap_result( conn, op, send_ldap_result( conn, op,
LDAP_UNWILLING_TO_PERFORM, "", LDAP_UNWILLING_TO_PERFORM, NULL,
"operation not permitted " "operation not permitted "
"within namingContext", "within namingContext",
NULL, NULL ); NULL, NULL );
@ -1278,9 +1271,8 @@ backsql_add(
if ( rc != SQL_SUCCESS ) { if ( rc != SQL_SUCCESS ) {
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) { if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
send_ldap_result( conn, op, send_ldap_result( conn, op, LDAP_OTHER,
LDAP_OTHER, "", NULL, "SQL-backend error",
"SQL-backend error",
NULL, NULL ); NULL, NULL );
return 1; return 1;
} }
@ -1347,8 +1339,8 @@ backsql_add(
backsql_PrintErrors( bi->db_env, dbh, sth, rc ); backsql_PrintErrors( bi->db_env, dbh, sth, rc );
if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) { if ( BACKSQL_FAIL_IF_NO_MAPPING( bi ) ) {
send_ldap_result( conn, op, send_ldap_result( conn, op, LDAP_OTHER,
LDAP_OTHER, "", NULL,
"SQL-backend error", "SQL-backend error",
NULL, NULL ); NULL, NULL );
return 1; return 1;
@ -1365,8 +1357,8 @@ backsql_add(
#ifdef BACKSQL_REALLOC_STMT #ifdef BACKSQL_REALLOC_STMT
rc = backsql_Prepare( dbh, &sth, bi->insentry_query, 0 ); rc = backsql_Prepare( dbh, &sth, bi->insentry_query, 0 );
if ( rc != SQL_SUCCESS ) { if ( rc != SQL_SUCCESS ) {
send_ldap_result( conn, op, LDAP_OTHER, "", send_ldap_result( conn, op, LDAP_OTHER,
"SQL-backend error", NULL, NULL ); NULL, "SQL-backend error", NULL, NULL );
return 1; return 1;
} }
#endif /* BACKSQL_REALLOC_STMT */ #endif /* BACKSQL_REALLOC_STMT */
@ -1397,8 +1389,8 @@ backsql_add(
* execute delete_proc to delete data added !!! * execute delete_proc to delete data added !!!
*/ */
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
send_ldap_result( conn, op, LDAP_OTHER, "", send_ldap_result( conn, op, LDAP_OTHER,
"SQL-backend error", NULL, NULL ); NULL, "SQL-backend error", NULL, NULL );
return 1; return 1;
} }
@ -1406,19 +1398,18 @@ backsql_add(
/* /*
* Commit only if all operations succeed * Commit only if all operations succeed
*
* FIXME: backsql_add() does not fail if add operations
* are not available for some attributes, or if
* a multiple value add actually results in a replace,
* or if a single operation on an attribute fails
* for any reason
*/ */
SQLTransact( SQL_NULL_HENV, dbh, SQLTransact( SQL_NULL_HENV, dbh,
op->o_noop ? SQL_ROLLBACK : SQL_COMMIT ); op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
send_ldap_result( conn, op, LDAP_SUCCESS, "", /*
NULL, NULL, NULL ); * FIXME: NOOP does not work for add -- it works for all
return 0; * the other operations, and I don't get the reason :(
*/
send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL );
return op->o_noop;
} }
int int
@ -1454,7 +1445,7 @@ backsql_delete(
"no write access to parent\n", "no write access to parent\n",
0, 0, 0 ); 0, 0, 0 );
send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
"", NULL, NULL, NULL ); NULL, NULL, NULL, NULL );
return 1; return 1;
} }
@ -1464,7 +1455,7 @@ backsql_delete(
Debug( LDAP_DEBUG_TRACE, "backsql_delete(): " Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
"could not get connection handle - exiting\n", "could not get connection handle - exiting\n",
0, 0, 0 ); 0, 0, 0 );
send_ldap_result( conn, op, res, "", send_ldap_result( conn, op, res, NULL,
res == LDAP_OTHER ? "SQL-backend error" : "", res == LDAP_OTHER ? "SQL-backend error" : "",
NULL, NULL ); NULL, NULL );
return 1; return 1;
@ -1474,7 +1465,7 @@ backsql_delete(
if ( res != LDAP_SUCCESS ) { if ( res != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_delete(): " Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
"could not lookup entry id\n", 0, 0, 0 ); "could not lookup entry id\n", 0, 0, 0 );
send_ldap_result( conn, op, res, "", NULL, NULL, NULL ); send_ldap_result( conn, op, res, NULL, NULL, NULL, NULL );
return 1; return 1;
} }
@ -1499,9 +1490,9 @@ backsql_delete(
oc = backsql_id2oc( bi, e_id.oc_id ); oc = backsql_id2oc( bi, e_id.oc_id );
if ( oc == NULL ) { if ( oc == NULL ) {
Debug( LDAP_DEBUG_TRACE, "backsql_delete(): " Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
"cannot determine objectclass of entry " "cannot determine objectclass of entry -- aborting\n",
"-- aborting\n", 0, 0, 0 ); 0, 0, 0 );
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, "", send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
"operation not permitted within namingContext", "operation not permitted within namingContext",
NULL, NULL ); NULL, NULL );
return 1; return 1;
@ -1511,7 +1502,7 @@ backsql_delete(
Debug( LDAP_DEBUG_TRACE, "backsql_delete(): " Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
"delete procedure is not defined " "delete procedure is not defined "
"for this objectclass - aborting\n", 0, 0, 0 ); "for this objectclass - aborting\n", 0, 0, 0 );
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, "", send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
"operation not permitted within namingContext", "operation not permitted within namingContext",
NULL, NULL ); NULL, NULL );
return 1; return 1;
@ -1537,8 +1528,8 @@ backsql_delete(
"delete_proc execution failed\n", 0, 0, 0 ); "delete_proc execution failed\n", 0, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc ); backsql_PrintErrors( bi->db_env, dbh, sth, rc );
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
send_ldap_result( conn, op, LDAP_OTHER, "", send_ldap_result( conn, op, LDAP_OTHER,
"SQL-backend error", NULL, NULL ); NULL, "SQL-backend error", NULL, NULL );
return 1; return 1;
} }
#ifndef BACKSQL_REALLOC_STMT #ifndef BACKSQL_REALLOC_STMT
@ -1557,8 +1548,8 @@ backsql_delete(
0, 0, 0 ); 0, 0, 0 );
backsql_PrintErrors( bi->db_env, dbh, sth, rc ); backsql_PrintErrors( bi->db_env, dbh, sth, rc );
SQLFreeStmt( sth, SQL_DROP ); SQLFreeStmt( sth, SQL_DROP );
send_ldap_result( conn, op, LDAP_OTHER, "", send_ldap_result( conn, op, LDAP_OTHER,
"SQL-backend error", NULL, NULL ); NULL, "SQL-backend error", NULL, NULL );
return 1; return 1;
} }
@ -1574,11 +1565,11 @@ backsql_delete(
* for any reason * for any reason
*/ */
SQLTransact( SQL_NULL_HENV, dbh, SQLTransact( SQL_NULL_HENV, dbh,
op->o_noop ? SQL_ROLLBACK : SQL_COMMIT ); op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
send_ldap_result( conn, op, LDAP_SUCCESS, "", NULL, NULL, NULL ); send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL );
Debug( LDAP_DEBUG_TRACE, "<==backsql_delete()\n", 0, 0, 0 ); Debug( LDAP_DEBUG_TRACE, "<==backsql_delete()\n", 0, 0, 0 );
return 0; return op->o_noop;
} }
#endif /* SLAPD_SQL */ #endif /* SLAPD_SQL */

View file

@ -48,7 +48,7 @@ insert into ldap_entries (id,dn,oc_map_id,parent,keyval) values (6,'documentTitl
insert into ldap_entry_objclasses (entry_id,oc_name) values (4,'referral'); insert into ldap_entry_objclasses (entry_id,oc_name) values (4,'referral');
insert into ldap_referrals (entry_id,url) values (4,'http://localhost'); insert into ldap_referrals (entry_id,url) values (4,'ldap://localhost/');
-- procedures -- procedures

View file

@ -239,16 +239,16 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh )
ber_str2bv( oc_row.cols[ 2 ], 0, 1, &oc_map->keytbl ); ber_str2bv( oc_row.cols[ 2 ], 0, 1, &oc_map->keytbl );
ber_str2bv( oc_row.cols[ 3 ], 0, 1, &oc_map->keycol ); ber_str2bv( oc_row.cols[ 3 ], 0, 1, &oc_map->keycol );
oc_map->create_proc = ( oc_row.is_null[ 4 ] < 0 ) ? NULL oc_map->create_proc = ( oc_row.value_len[ 4 ] < 0 ) ? NULL
: ch_strdup( oc_row.cols[ 4 ] ); : ch_strdup( oc_row.cols[ 4 ] );
colnum = 5; colnum = 5;
if ( BACKSQL_CREATE_NEEDS_SELECT( si ) ) { if ( BACKSQL_CREATE_NEEDS_SELECT( si ) ) {
colnum = 6; colnum = 6;
oc_map->create_keyval = ( oc_row.is_null[ 5 ] < 0 ) oc_map->create_keyval = ( oc_row.value_len[ 5 ] < 0 )
? NULL : ch_strdup( oc_row.cols[ 5 ] ); ? NULL : ch_strdup( oc_row.cols[ 5 ] );
} }
oc_map->delete_proc = ( oc_row.is_null[ colnum ] < 0 ) ? NULL oc_map->delete_proc = ( oc_row.value_len[ colnum ] < 0 ) ? NULL
: ch_strdup( oc_row.cols[ colnum ] ); : ch_strdup( oc_row.cols[ colnum ] );
oc_map->expect_return = strtol( oc_row.cols[ colnum + 1 ], oc_map->expect_return = strtol( oc_row.cols[ colnum + 1 ],
NULL, 0 ); NULL, 0 );
@ -332,7 +332,7 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh )
} }
ber_str2bv( at_row.cols[ 1 ], 0, 1, &at_map->sel_expr ); ber_str2bv( at_row.cols[ 1 ], 0, 1, &at_map->sel_expr );
if ( at_row.is_null[ 8 ] < 0 ) { if ( at_row.value_len[ 8 ] < 0 ) {
at_map->sel_expr_u.bv_val = NULL; at_map->sel_expr_u.bv_val = NULL;
at_map->sel_expr_u.bv_len = 0; at_map->sel_expr_u.bv_len = 0;
} else { } else {
@ -343,17 +343,22 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh )
ber_str2bv( at_row.cols[ 2 ], 0, 0, &bv ); ber_str2bv( at_row.cols[ 2 ], 0, 0, &bv );
backsql_merge_from_clause( &at_map->from_tbls, backsql_merge_from_clause( &at_map->from_tbls,
&tmpslen, &bv ); &tmpslen, &bv );
if ( at_row.is_null[ 3 ] < 0 ) { if ( at_row.value_len[ 3 ] < 0 ) {
at_map->join_where.bv_val = NULL; at_map->join_where.bv_val = NULL;
at_map->join_where.bv_len = 0; at_map->join_where.bv_len = 0;
} else { } else {
ber_str2bv( at_row.cols[ 3 ], 0, 1, ber_str2bv( at_row.cols[ 3 ], 0, 1,
&at_map->join_where ); &at_map->join_where );
} }
at_map->add_proc = ( at_row.is_null[ 4 ] < 0 ) ? NULL at_map->add_proc = NULL;
: ch_strdup( at_row.cols[4] ); if ( at_row.value_len[ 4 ] > 0 ) {
at_map->delete_proc = ( at_row.is_null[ 5 ] < 0 ) ? NULL at_map->add_proc = ch_strdup( at_row.cols[4] );
: ch_strdup( at_row.cols[ 5 ] ); }
at_map->delete_proc = NULL;
if ( at_row.value_len[ 5 ] > 0 ) {
at_map->delete_proc
= ch_strdup( at_row.cols[ 5 ] );
}
at_map->param_order = strtol( at_row.cols[ 6 ], at_map->param_order = strtol( at_row.cols[ 6 ],
NULL, 0 ); NULL, 0 );
at_map->expect_return = strtol( at_row.cols[ 7 ], at_map->expect_return = strtol( at_row.cols[ 7 ],

View file

@ -18,7 +18,7 @@ typedef struct {
BerVarray col_names; BerVarray col_names;
UDWORD *col_prec; UDWORD *col_prec;
char **cols; char **cols;
SQLINTEGER *is_null; SQLINTEGER *value_len;
} BACKSQL_ROW_NTS; } BACKSQL_ROW_NTS;
#endif /* __BACKSQL_SQL_TYPES_H__ */ #endif /* __BACKSQL_SQL_TYPES_H__ */

View file

@ -65,13 +65,13 @@ backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout )
} }
#ifdef BACKSQL_TRACE #ifdef BACKSQL_TRACE
Debug( LDAP_DEBUG_TRACE, "==>_SQLPrepare()\n", 0, 0, 0 ); Debug( LDAP_DEBUG_TRACE, "==>backsql_Prepare()\n", 0, 0, 0 );
#endif /* BACKSQL_TRACE */ #endif /* BACKSQL_TRACE */
SQLGetInfo( dbh, SQL_DRIVER_NAME, drv_name, sizeof( drv_name ), &len ); SQLGetInfo( dbh, SQL_DRIVER_NAME, drv_name, sizeof( drv_name ), &len );
#ifdef BACKSQL_TRACE #ifdef BACKSQL_TRACE
Debug( LDAP_DEBUG_TRACE, "_SQLPrepare(): driver name='%s'\n", Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): driver name='%s'\n",
drv_name, 0, 0 ); drv_name, 0, 0 );
#endif /* BACKSQL_TRACE */ #endif /* BACKSQL_TRACE */
@ -89,7 +89,7 @@ backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout )
rc = SQLSetStmtOption( *sth, SQL_CONCURRENCY, rc = SQLSetStmtOption( *sth, SQL_CONCURRENCY,
SQL_CONCUR_ROWVER ); SQL_CONCUR_ROWVER );
if ( rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) { if ( rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) {
Debug( LDAP_DEBUG_TRACE, "_SQLPrepare(): " Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): "
"SQLSetStmtOption(SQL_CONCURRENCY," "SQLSetStmtOption(SQL_CONCURRENCY,"
"SQL_CONCUR_ROWVER) failed:\n", "SQL_CONCUR_ROWVER) failed:\n",
0, 0, 0 ); 0, 0, 0 );
@ -108,7 +108,7 @@ backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout )
} }
#ifdef BACKSQL_TRACE #ifdef BACKSQL_TRACE
Debug( LDAP_DEBUG_TRACE, "<==_SQLPrepare() calling SQLPrepare()\n", Debug( LDAP_DEBUG_TRACE, "<==backsql_Prepare() calling SQLPrepare()\n",
0, 0, 0 ); 0, 0, 0 );
#endif /* BACKSQL_TRACE */ #endif /* BACKSQL_TRACE */
@ -160,7 +160,7 @@ backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row )
rc = SQLNumResultCols( sth, &row->ncols ); rc = SQLNumResultCols( sth, &row->ncols );
if ( rc != SQL_SUCCESS ) { if ( rc != SQL_SUCCESS ) {
#ifdef BACKSQL_TRACE #ifdef BACKSQL_TRACE
Debug( LDAP_DEBUG_TRACE, "_SQLBindRowAsStrings(): " Debug( LDAP_DEBUG_TRACE, "backsql_BindRowAsStrings(): "
"SQLNumResultCols() failed:\n", 0, 0, 0 ); "SQLNumResultCols() failed:\n", 0, 0, 0 );
#endif /* BACKSQL_TRACE */ #endif /* BACKSQL_TRACE */
@ -177,7 +177,7 @@ backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row )
sizeof( char * ) ); sizeof( char * ) );
row->col_prec = (UDWORD *)ch_calloc( row->ncols, row->col_prec = (UDWORD *)ch_calloc( row->ncols,
sizeof( UDWORD ) ); sizeof( UDWORD ) );
row->is_null = (SQLINTEGER *)ch_calloc( row->ncols, row->value_len = (SQLINTEGER *)ch_calloc( row->ncols,
sizeof( SQLINTEGER ) ); sizeof( SQLINTEGER ) );
for ( i = 1; i <= row->ncols; i++ ) { for ( i = 1; i <= row->ncols; i++ ) {
rc = SQLDescribeCol( sth, (SQLSMALLINT)i, &colname[ 0 ], rc = SQLDescribeCol( sth, (SQLSMALLINT)i, &colname[ 0 ],
@ -213,7 +213,7 @@ backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row )
SQL_C_CHAR, SQL_C_CHAR,
(SQLPOINTER)row->cols[ i - 1 ], (SQLPOINTER)row->cols[ i - 1 ],
col_prec + 1, col_prec + 1,
&row->is_null[ i - 1 ] ); &row->value_len[ i - 1 ] );
} else { } else {
row->cols[ i - 1 ] = (char *)ch_calloc( col_prec + 1, sizeof( char ) ); row->cols[ i - 1 ] = (char *)ch_calloc( col_prec + 1, sizeof( char ) );
row->col_prec[ i - 1 ] = col_prec; row->col_prec[ i - 1 ] = col_prec;
@ -221,7 +221,7 @@ backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row )
SQL_C_CHAR, SQL_C_CHAR,
(SQLPOINTER)row->cols[ i - 1 ], (SQLPOINTER)row->cols[ i - 1 ],
col_prec + 1, col_prec + 1,
&row->is_null[ i - 1 ] ); &row->value_len[ i - 1 ] );
} }
} }
@ -247,7 +247,7 @@ backsql_FreeRow( BACKSQL_ROW_NTS *row )
ber_bvarray_free( row->col_names ); ber_bvarray_free( row->col_names );
ldap_charray_free( row->cols ); ldap_charray_free( row->cols );
free( row->col_prec ); free( row->col_prec );
free( row->is_null ); free( row->value_len );
return SQL_SUCCESS; return SQL_SUCCESS;
} }