Subject | RE: [ib-support] Questions about Firebird's API |
---|---|
Author | C R Zamana |
Post date | 2002-03-14T17:37:04Z |
On Thu, 2002-03-14 at 14:04, Ann W. Harrison wrote:
and password and it works fine. Feel free :-)
---- Code ------------------------------------------------------------
#include "rdd_api.h"
ISC_LONG api_connect( char *db, char *user, char *pass, isc_db_handle
*dbhandle ) {
char *dpb;
char *dpb_buffer;
char *p;
short dpb_length;
ISC_STATUS status_vector[20];
dpb_buffer = (char *)malloc(USERNAME_SIZE+PASSWORD_SIZE+3);
if ( dpb_buffer == NULL ) {
return(-1);
}
dpb_length = 0;
dpb = dpb_buffer;
/* Do not use isc_expand_dpb()!!!
*
*/
/*
isc_expand_dpb( &dpb, &dpb_length, isc_dpb_user_name, user,
isc_dpb_password, pass, NULL );
*/
/* manually building the dpb */
*dpb++ = isc_dpb_version1;
*dpb++ = isc_dpb_user_name;
*dpb++ = strlen(user);
for( p = user; *p; )
*dpb++ = *p++;
*dpb++ = isc_dpb_password;
*dpb++ = strlen(pass);
for( p = pass; *p; )
*dpb++ = *p++;
dpb_length = dpb - dpb_buffer;
isc_attach_database( status_vector, 0, db, dbhandle, dpb_length,
dpb_buffer );
if ( status_vector[0] == 1 && status_vector[1] ) {
isc_print_status(status_vector);
}
free(dpb_buffer);
return( isc_sqlcode(status_vector) );
}
--------- Code ------------------------------------------------------
> At 03:12 AM 3/14/2002 -0800, Tony Mays wrote:I use this approach to connect with database passing username
>
> >Any guidance on isc_free() is more than welcome because I can see some
> >obvious uses for isc_expand_dpb().
>
> Don't use isc_expand_dpb. Despite the API Guide, it's not a
> reliable way to build parameter blocks.
>
and password and it works fine. Feel free :-)
---- Code ------------------------------------------------------------
#include "rdd_api.h"
ISC_LONG api_connect( char *db, char *user, char *pass, isc_db_handle
*dbhandle ) {
char *dpb;
char *dpb_buffer;
char *p;
short dpb_length;
ISC_STATUS status_vector[20];
dpb_buffer = (char *)malloc(USERNAME_SIZE+PASSWORD_SIZE+3);
if ( dpb_buffer == NULL ) {
return(-1);
}
dpb_length = 0;
dpb = dpb_buffer;
/* Do not use isc_expand_dpb()!!!
*
*/
/*
isc_expand_dpb( &dpb, &dpb_length, isc_dpb_user_name, user,
isc_dpb_password, pass, NULL );
*/
/* manually building the dpb */
*dpb++ = isc_dpb_version1;
*dpb++ = isc_dpb_user_name;
*dpb++ = strlen(user);
for( p = user; *p; )
*dpb++ = *p++;
*dpb++ = isc_dpb_password;
*dpb++ = strlen(pass);
for( p = pass; *p; )
*dpb++ = *p++;
dpb_length = dpb - dpb_buffer;
isc_attach_database( status_vector, 0, db, dbhandle, dpb_length,
dpb_buffer );
if ( status_vector[0] == 1 && status_vector[1] ) {
isc_print_status(status_vector);
}
free(dpb_buffer);
return( isc_sqlcode(status_vector) );
}
--------- Code ------------------------------------------------------