/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1999-2005 The OpenLDAP Foundation.
+ * Copyright 1999-2007 The OpenLDAP Foundation.
* Portions Copyright 1999 Dmitry Kovalev.
* Portions Copyright 2002 Pierangelo Masarati.
* Portions Copyright 2004 Mark Adamson.
Debug( LDAP_DEBUG_TRACE, "Return code: %d\n", rc, 0, 0 );
for ( ; rc = SQLError( henv, hdbc, sth, state, &iSqlCode, msg,
- SQL_MAX_MESSAGE_LENGTH - 1, &len ), BACKSQL_SUCCESS( rc ); ) {
+ SQL_MAX_MESSAGE_LENGTH - 1, &len ), BACKSQL_SUCCESS( rc ); )
+ {
Debug( LDAP_DEBUG_TRACE,
- " Native error code: %d\n"
- " SQL engine state: %s\n"
- " Message: %s\n",
- (int)iSqlCode, state, msg );
+ " nativeErrCode=%d SQLengineState=%s msg=\"%s\"\n",
+ (int)iSqlCode, state, msg );
}
}
row->col_names = (BerVarray)ber_memcalloc_x( row->ncols + 1,
sizeof( struct berval ), ctx );
+ if ( !row->col_names ) goto nomem3;
row->cols = (char **)ber_memcalloc_x( row->ncols + 1,
sizeof( char * ), ctx );
+ if ( !row->cols ) goto nomem2;
row->col_prec = (UDWORD *)ber_memcalloc_x( row->ncols,
sizeof( UDWORD ), ctx );
+ if ( !row->col_prec ) goto nomem1;
row->value_len = (SQLINTEGER *)ber_memcalloc_x( row->ncols,
sizeof( SQLINTEGER ), ctx );
+ if ( !row->value_len ) {
+ ber_memfree_x( row->col_prec, ctx );
+ row->col_prec = NULL;
+nomem1: ber_memfree_x( row->cols, ctx );
+ row->cols = NULL;
+nomem2: ber_memfree_x( row->col_names, ctx );
+ row->col_names = NULL;
+nomem3: Debug( LDAP_DEBUG_ANY, "backsql_BindRowAsStrings: "
+ "out of memory\n", 0, 0, 0 );
+ return LDAP_NO_MEMORY;
+ }
for ( i = 1; i <= row->ncols; i++ ) {
rc = SQLDescribeCol( sth, (SQLSMALLINT)i, &colname[ 0 ],
(SQLUINTEGER)( sizeof( colname ) - 1 ),
return 0;
}
-static int
-backsql_close_db_conn( backsql_db_conn *conn )
+static void
+backsql_close_db_conn( void *v_conn )
{
- Debug( LDAP_DEBUG_TRACE, "==>backsql_close_db_conn()\n", 0, 0, 0 );
+ backsql_db_conn *conn = (backsql_db_conn *)v_conn;
+ unsigned long cid = conn->ldap_cid;
+
+ Debug( LDAP_DEBUG_TRACE, "==>backsql_close_db_conn(%lu)\n",
+ cid, 0, 0 );
/*
* Default transact is SQL_ROLLBACK; commit is required only
SQLTransact( SQL_NULL_HENV, conn->dbh, SQL_ROLLBACK );
SQLDisconnect( conn->dbh );
SQLFreeConnect( conn->dbh );
- Debug( LDAP_DEBUG_TRACE, "<==backsql_close_db_conn()\n", 0, 0, 0 );
- return 1;
+ ch_free( conn );
+
+ Debug( LDAP_DEBUG_TRACE, "<==backsql_close_db_conn(%lu)\n",
+ cid, 0, 0 );
+}
+
+int
+backsql_conn_destroy(
+ backsql_info *bi )
+{
+ avl_free( bi->sql_db_conns, backsql_close_db_conn );
+
+ return 0;
}
int
int ret = SQL_SUCCESS;
Debug( LDAP_DEBUG_TRACE, "==>backsql_init_db_env()\n", 0, 0, 0 );
+
rc = SQLAllocEnv( &bi->sql_db_env );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "init_db_env: SQLAllocEnv failed:\n",
SQL_NULL_HENV, rc );
ret = SQL_ERROR;
}
+
Debug( LDAP_DEBUG_TRACE, "<==backsql_init_db_env()=%d\n", ret, 0, 0 );
+
return ret;
}
{
Debug( LDAP_DEBUG_TRACE, "==>backsql_free_db_env()\n", 0, 0, 0 );
-#ifdef BACKSQL_TRACE
- Debug( LDAP_DEBUG_TRACE, "free_db_env(): delete AVL tree here!!!\n",
- 0, 0, 0 );
-#endif /* BACKSQL_TRACE */
+ (void)SQLFreeEnv( bi->sql_db_env );
+ bi->sql_db_env = SQL_NULL_HENV;
/*
* stop, if frontend waits for all threads to shutdown
* everything is already deleted...
*/
Debug( LDAP_DEBUG_TRACE, "<==backsql_free_db_env()\n", 0, 0, 0 );
+
return SQL_SUCCESS;
}
assert( pdbc != NULL );
*pdbc = NULL;
- Debug( LDAP_DEBUG_TRACE, "==>backsql_open_db_conn()\n", 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "==>backsql_open_db_conn(%lu)\n",
+ ldap_cid, 0, 0 );
+
dbc = (backsql_db_conn *)ch_calloc( 1, sizeof( backsql_db_conn ) );
dbc->ldap_cid = ldap_cid;
rc = SQLAllocConnect( bi->sql_db_env, &dbc->dbh );
if ( !BACKSQL_SUCCESS( rc ) ) {
- Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn: "
- "SQLAllocConnect() failed:\n", 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn(%lu): "
+ "SQLAllocConnect() failed:\n", ldap_cid, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, SQL_NULL_HDBC,
SQL_NULL_HENV, rc );
return LDAP_UNAVAILABLE;
(SQLCHAR*)bi->sql_dbuser, SQL_NTS,
(SQLCHAR*)bi->sql_dbpasswd, SQL_NTS );
if ( rc != SQL_SUCCESS ) {
- Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn: "
- "SQLConnect() to database \"%s\" as user \"%s\" "
- "%s:\n", bi->sql_dbname, bi->sql_dbuser,
+ Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn(%lu): "
+ "SQLConnect() to database \"%s\" %s.\n",
+ ldap_cid, bi->sql_dbname,
rc == SQL_SUCCESS_WITH_INFO ?
"succeeded with info" : "failed" );
backsql_PrintErrors( bi->sql_db_env, dbc->dbh, SQL_NULL_HENV, rc );
if ( rc == SQL_SUCCESS ) {
if ( strcmp( DBMSName, "TimesTen" ) == 0 ||
strcmp( DBMSName, "Front-Tier" ) == 0 ) {
- Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn: "
- "TimesTen database!\n", 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn(%lu): "
+ "TimesTen database!\n", ldap_cid, 0, 0 );
bi->sql_flags |= BSQLF_USE_REVERSE_DN;
}
} else {
- Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn: "
- "SQLGetInfo() failed:\n", 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn(%lu): "
+ "SQLGetInfo() failed.\n", ldap_cid, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, dbc->dbh, SQL_NULL_HENV, rc );
return rc;
}
/* end TimesTen */
- Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn(): "
- "connected, adding to tree\n", 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn(%lu): "
+ "connected, adding to tree.\n", ldap_cid, 0, 0 );
ldap_pvt_thread_mutex_lock( &bi->sql_dbconn_mutex );
if ( avl_insert( &bi->sql_db_conns, dbc, backsql_cmp_connid, avl_dup_error ) ) {
- Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn: "
- "duplicate connection ID\n", 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn(%lu): "
+ "duplicate connection ID.\n", ldap_cid, 0, 0 );
return LDAP_OTHER;
}
ldap_pvt_thread_mutex_unlock( &bi->sql_dbconn_mutex );
- Debug( LDAP_DEBUG_TRACE, "<==backsql_open_db_conn()\n", 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "<==backsql_open_db_conn(%lu)\n", ldap_cid, 0, 0 );
*pdbc = dbc;
*/
if ( conn != NULL ) {
Debug( LDAP_DEBUG_TRACE, "backsql_free_db_conn(): "
- "closing db connection\n", 0, 0, 0 );
- backsql_close_db_conn( conn );
+ "closing db connection %lu (%p)\n",
+ op->o_connid, (void *)conn, 0 );
+ backsql_close_db_conn( (void *)conn );
}
+
Debug( LDAP_DEBUG_TRACE, "<==backsql_free_db_conn()\n", 0, 0, 0 );
- return SQL_SUCCESS;
+
+ return conn ? SQL_SUCCESS : SQL_ERROR;
}
int