SQLHDBC dbh,
backsql_oc_map_rec *oc,
Attribute *at,
- unsigned long new_keyval )
+ backsql_key_t new_keyval )
{
backsql_info *bi = (backsql_info*)op->o_bd->be_private;
backsql_at_map_rec *at_rec = NULL;
po = ( BACKSQL_IS_ADD( at_rec->bam_param_order ) ) > 0;
currpos = pno + 1 + po;
- rc = backsql_BindParamInt( sth, currpos,
+ rc = backsql_BindParamNumID( sth, currpos,
SQL_PARAM_INPUT, &new_keyval );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
}
#ifdef LDAP_DEBUG
- snprintf( logbuf, sizeof( logbuf ), "val[%lu], id=%lu",
- i, new_keyval );
- Debug( LDAP_DEBUG_TRACE, " backsql_add_attr(\"%s\"): "
- "executing \"%s\" %s\n",
- op->ora_e->e_name.bv_val,
- at_rec->bam_add_proc, logbuf );
+ if ( LogTest( LDAP_DEBUG_TRACE ) ) {
+ snprintf( logbuf, sizeof( logbuf ), "val[%lu], id=" BACKSQL_IDNUMFMT,
+ i, new_keyval );
+ Debug( LDAP_DEBUG_TRACE, " backsql_add_attr(\"%s\"): "
+ "executing \"%s\" %s\n",
+ op->ora_e->e_name.bv_val,
+ at_rec->bam_add_proc, logbuf );
+ }
#endif
rc = SQLExecute( sth );
if ( rc == SQL_SUCCESS && prc == LDAP_SUCCESS ) {
backsql_info *bi = (backsql_info*)op->o_bd->be_private;
SQLHDBC dbh = SQL_NULL_HDBC;
SQLHSTMT sth = SQL_NULL_HSTMT;
- unsigned long new_keyval = 0;
+ backsql_key_t new_keyval = 0;
RETCODE rc;
backsql_oc_map_rec *oc = NULL;
backsql_srch_info bsi = { 0 };
colnum = 1;
if ( BACKSQL_IS_ADD( oc->bom_expect_return ) ) {
- rc = backsql_BindParamInt( sth, 1, SQL_PARAM_OUTPUT, &new_keyval );
+ rc = backsql_BindParamNumID( sth, 1, SQL_PARAM_OUTPUT, &new_keyval );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"error binding keyval parameter "
SQLFreeStmt( sth, SQL_DROP );
Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
- "create_proc returned keyval=%ld\n",
+ "create_proc returned keyval=" BACKSQL_IDNUMFMT "\n",
op->ora_e->e_name.bv_val, new_keyval, 0 );
rc = backsql_Prepare( dbh, &sth, bi->sql_insentry_stmt, 0 );
goto done;
}
- rc = backsql_BindParamInt( sth, 2, SQL_PARAM_INPUT, &oc->bom_id );
+ rc = backsql_BindParamNumID( sth, 2, SQL_PARAM_INPUT, &oc->bom_id );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"error binding objectClass ID parameter "
goto done;
}
- rc = backsql_BindParamInt( sth, 4, SQL_PARAM_INPUT, &new_keyval );
+ rc = backsql_BindParamNumID( sth, 4, SQL_PARAM_INPUT, &new_keyval );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_add(\"%s\"): "
"error binding entry ID parameter "
char buf[ SLAP_TEXT_BUFLEN ];
snprintf( buf, sizeof(buf),
- "executing \"%s\" for dn=\"%s\" oc_map_id=%ld p_id=" BACKSQL_IDFMT " keyval=%ld",
+ "executing \"%s\" for dn=\"%s\" oc_map_id=" BACKSQL_IDNUMFMT " p_id=" BACKSQL_IDFMT " keyval=" BACKSQL_IDNUMFMT,
bi->sql_insentry_stmt, op->ora_e->e_name.bv_val,
oc->bom_id, BACKSQL_IDARG(bsi.bsi_base_id.eid_id),
new_keyval );
*/
#undef BACKSQL_ARBITRARY_KEY
+/*
+ * type used for keys
+ */
+#if defined(HAVE_LONG_LONG) && defined(SQL_C_UBIGINT) && \
+ ( defined(HAVE_STRTOULL) || defined(HAVE_STRTOUQ) )
+typedef unsigned long long backsql_key_t;
+#define BACKSQL_C_NUMID SQL_C_UBIGINT
+#define BACKSQL_IDNUMFMT "%llu"
+#define BACKSQL_STR2ID lutil_atoullx
+#else /* ! HAVE_LONG_LONG || ! SQL_C_UBIGINT */
+typedef unsigned long backsql_key_t;
+#define BACKSQL_C_NUMID SQL_C_ULONG
+#define BACKSQL_IDNUMFMT "%lu"
+#define BACKSQL_STR2ID lutil_atoulx
+#endif /* ! HAVE_LONG_LONG */
+
/*
* define to enable support for syncprov overlay
*/
/* flags whether delete_proc is a function (whether back-sql
* should bind first parameter as output for return code) */
int bom_expect_return;
- unsigned long bom_id;
+ backsql_key_t bom_id;
Avlnode *bom_attrs;
AttributeDescription *bom_create_hint;
} backsql_oc_map_rec;
#define BACKSQL_MAX_KEY_LEN 64
#else /* ! BACKSQL_ARBITRARY_KEY */
/* The original numeric key is maintained as default. */
- unsigned long eid_id;
- unsigned long eid_keyval;
+ backsql_key_t eid_id;
+ backsql_key_t eid_keyval;
#endif /* ! BACKSQL_ARBITRARY_KEY */
- unsigned long eid_oc_id;
+ backsql_key_t eid_oc_id;
backsql_oc_map_rec *eid_oc;
struct berval eid_dn;
struct berval eid_ndn;
#define BACKSQL_IDFMT "%s"
#define BACKSQL_IDARG(arg) ((arg).bv_val)
#else /* ! BACKSQL_ARBITRARY_KEY */
-#define BACKSQL_IDFMT "%lu"
+#define BACKSQL_IDFMT BACKSQL_IDNUMFMT
#define BACKSQL_IDARG(arg) (arg)
#endif /* ! BACKSQL_ARBITRARY_KEY */
ber_str2bv_x( row.cols[ 1 ], 0, 1, &id->eid_keyval,
op->o_tmpmemctx );
#else /* ! BACKSQL_ARBITRARY_KEY */
- if ( lutil_atoulx( &id->eid_id, row.cols[ 0 ], 0 ) != 0 ) {
+ if ( BACKSQL_STR2ID( &id->eid_id, row.cols[ 0 ], 0 ) != 0 ) {
res = LDAP_OTHER;
goto done;
}
- if ( lutil_atoulx( &id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) {
+ if ( BACKSQL_STR2ID( &id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) {
res = LDAP_OTHER;
goto done;
}
#endif /* ! BACKSQL_ARBITRARY_KEY */
- if ( lutil_atoulx( &id->eid_oc_id, row.cols[ 2 ], 0 ) != 0 ) {
+ if ( BACKSQL_STR2ID( &id->eid_oc_id, row.cols[ 2 ], 0 ) != 0 ) {
res = LDAP_OTHER;
goto done;
}
eid->eid_oc_id );
if ( eid->eid_oc == NULL ) {
Debug( LDAP_DEBUG_TRACE,
- "backsql_id2entry(): unable to fetch objectClass with id=%lu for entry id=" BACKSQL_IDFMT " dn=\"%s\"\n",
+ "backsql_id2entry(): unable to fetch objectClass with id=" BACKSQL_IDNUMFMT " for entry id=" BACKSQL_IDFMT " dn=\"%s\"\n",
eid->eid_oc_id, BACKSQL_IDARG(eid->eid_id),
eid->eid_dn.bv_val );
return LDAP_OTHER;
(io), SQL_C_ULONG, SQL_INTEGER, \
0, 0, (SQLPOINTER)(val), 0, (SQLINTEGER*)NULL )
+#define backsql_BindParamNumID( sth, par_ind, io, val ) \
+ SQLBindParameter( (sth), (SQLUSMALLINT)(par_ind), \
+ (io), BACKSQL_C_NUMID, SQL_INTEGER, \
+ 0, 0, (SQLPOINTER)(val), 0, (SQLINTEGER*)NULL )
+
#ifdef BACKSQL_ARBITRARY_KEY
#define backsql_BindParamID( sth, par_ind, io, id ) \
backsql_BindParamBerVal( (sth), (par_ind), (io), (id) )
#else /* ! BACKSQL_ARBITRARY_KEY */
#define backsql_BindParamID( sth, par_ind, io, id ) \
- backsql_BindParamInt( (sth), (par_ind), (io), (id) )
+ backsql_BindParamNumID( (sth), (par_ind), (io), (id) )
#endif /* ! BACKSQL_ARBITRARY_KEY */
RETCODE backsql_BindRowAsStrings_x( SQLHSTMT sth, BACKSQL_ROW_NTS *row, void *ctx );
struct berbuf bb;
sbv.bv_val = s;
- sbv.bv_len = snprintf( s, sizeof( s ), "%ld", oc_map->bom_id );
+ sbv.bv_len = snprintf( s, sizeof( s ), BACKSQL_IDNUMFMT, oc_map->bom_id );
/* extra objectClasses */
at_map = (backsql_at_map_rec *)ch_calloc(1,
"INSERT INTO ldap_entry_objclasses "
"(entry_id,oc_name) VALUES "
"((SELECT id FROM ldap_entries "
- "WHERE oc_map_id=%lu "
+ "WHERE oc_map_id=" BACKSQL_IDNUMFMT " "
"AND keyval=?),?)", oc_map->bom_id );
at_map->bam_add_proc = ch_strdup( tmp );
}
snprintf( tmp, sizeof(tmp),
"DELETE FROM ldap_entry_objclasses "
"WHERE entry_id=(SELECT id FROM ldap_entries "
- "WHERE oc_map_id=%lu "
+ "WHERE oc_map_id=" BACKSQL_IDNUMFMT " "
"AND keyval=?) AND oc_name=?",
oc_map->bom_id );
at_map->bam_delete_proc = ch_strdup( tmp );
backsql_info *bas_bi;
SQLHDBC bas_dbh;
SQLHSTMT bas_sth;
- unsigned long *bas_oc_id;
+ backsql_key_t *bas_oc_id;
int bas_rc;
};
"executing at_query\n"
" \"%s\"\n"
" for objectClass \"%s\"\n"
- " with param oc_id=\"%lu\"\n",
+ " with param oc_id=" BACKSQL_IDNUMFMT "\n",
bas->bas_bi->sql_at_query,
BACKSQL_OC_NAME( oc_map ),
*bas->bas_oc_id );
"error executing at_query\n"
" \"%s\"\n"
" for objectClass \"%s\"\n"
- " with param oc_id=\"%lu\"\n",
+ " with param oc_id=" BACKSQL_IDNUMFMT "\n",
bas->bas_bi->sql_at_query,
BACKSQL_OC_NAME( oc_map ),
*bas->bas_oc_id );
SQLHSTMT sth = SQL_NULL_HSTMT;
RETCODE rc;
BACKSQL_ROW_NTS oc_row;
- unsigned long oc_id;
+ backsql_key_t oc_id;
backsql_oc_map_rec *oc_map;
struct backsql_attr_schema_info bas;
{ 1, "name" },
{ 2, "keytbl" },
{ 3, "keycol" },
- { delete_proc_idx + 1, "expect_return" },
+ { -1, "expect_return" },
{ -1, NULL },
};
int i;
+ required[4].idx = delete_proc_idx + 1;
+
for ( i = 0; required[ i ].name != NULL; i++ ) {
if ( oc_row.value_len[ required[ i ].idx ] <= 0 ) {
Debug( LDAP_DEBUG_ANY,
oc_map = (backsql_oc_map_rec *)ch_calloc( 1,
sizeof( backsql_oc_map_rec ) );
- if ( lutil_atoulx( &oc_map->bom_id, oc_row.cols[ 0 ], 0 ) != 0 ) {
+ if ( BACKSQL_STR2ID( &oc_map->bom_id, oc_row.cols[ 0 ], 0 ) != 0 ) {
Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
"unable to parse id=\"%s\"\n",
oc_row.cols[ 0 ], 0, 0 );
return LDAP_OTHER;
}
- rc = backsql_BindParamInt( sth, 1, SQL_PARAM_INPUT, &oc_id );
+ rc = backsql_BindParamNumID( sth, 1, SQL_PARAM_INPUT, &oc_id );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): "
"error binding param \"oc_id\" for at_query\n", 0, 0, 0 );
return BACKSQL_AVL_CONTINUE;
}
- Debug( LDAP_DEBUG_TRACE, "id: '%ld'\n", bsi->bsi_oc->bom_id, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "id: '" BACKSQL_IDNUMFMT "'\n",
+ bsi->bsi_oc->bom_id, 0, 0 );
- rc = backsql_BindParamInt( sth, 1, SQL_PARAM_INPUT,
+ rc = backsql_BindParamNumID( sth, 1, SQL_PARAM_INPUT,
&bsi->bsi_oc->bom_id );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
ber_str2bv_x( row.cols[ 1 ], 0, 1, &c_id->eid_keyval,
op->o_tmpmemctx );
#else /* ! BACKSQL_ARBITRARY_KEY */
- if ( lutil_atoulx( &c_id->eid_id, row.cols[ 0 ], 0 ) != 0 ) {
+ if ( BACKSQL_STR2ID( &c_id->eid_id, row.cols[ 0 ], 0 ) != 0 ) {
goto cleanup;
}
- if ( lutil_atoulx( &c_id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) {
+ if ( BACKSQL_STR2ID( &c_id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) {
goto cleanup;
}
#endif /* ! BACKSQL_ARBITRARY_KEY */
}
Debug(LDAP_DEBUG_TRACE, "backsql_search(): loading data "
- "for entry id=" BACKSQL_IDFMT " oc_id=%ld, keyval=" BACKSQL_IDFMT "\n",
+ "for entry id=" BACKSQL_IDFMT " oc_id=" BACKSQL_IDNUMFMT ", keyval=" BACKSQL_IDFMT "\n",
BACKSQL_IDARG(eid->eid_id),
eid->eid_oc_id,
BACKSQL_IDARG(eid->eid_keyval) );