]> git.sur5r.net Git - openldap/commitdiff
(blind) support for long long keys (ITS#6617; needs ITS#6622 patch)
authorPierangelo Masarati <ando@openldap.org>
Thu, 12 Aug 2010 23:33:54 +0000 (23:33 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 12 Aug 2010 23:33:54 +0000 (23:33 +0000)
servers/slapd/back-sql/add.c
servers/slapd/back-sql/back-sql.h
servers/slapd/back-sql/entry-id.c
servers/slapd/back-sql/proto-sql.h
servers/slapd/back-sql/schema-map.c
servers/slapd/back-sql/search.c

index 0bc7fb5d716d7aeb80bd55331cf900cbf07dc691..94d00732fe1691285586fa16eeb44912517c40e6 100644 (file)
@@ -724,7 +724,7 @@ backsql_add_attr(
        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;
@@ -820,7 +820,7 @@ backsql_add_attr(
 
                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,
@@ -857,12 +857,14 @@ backsql_add_attr(
                }
 
 #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 ) {
@@ -902,7 +904,7 @@ backsql_add( Operation *op, SlapReply *rs )
        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 };
@@ -1155,7 +1157,7 @@ backsql_add( Operation *op, SlapReply *rs )
 
        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 "
@@ -1306,7 +1308,7 @@ backsql_add( Operation *op, SlapReply *rs )
        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 );
@@ -1333,7 +1335,7 @@ backsql_add( Operation *op, SlapReply *rs )
                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 "
@@ -1367,7 +1369,7 @@ backsql_add( Operation *op, SlapReply *rs )
                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 "
@@ -1388,7 +1390,7 @@ backsql_add( Operation *op, SlapReply *rs )
                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 );
index 7c3004676951ff676bffb33e9b31d3047af5d39c..b6b02f5c0cd2d109df05ab2067a2d72615d5c0b9 100644 (file)
@@ -223,6 +223,22 @@ typedef struct {
  */
 #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
  */
@@ -289,7 +305,7 @@ typedef struct backsql_oc_map_rec {
        /* 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;
@@ -381,11 +397,11 @@ typedef struct backsql_entryID {
 #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;
@@ -603,7 +619,7 @@ typedef struct backsql_info {
 #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 */
 
index 6cef98dde6566cc71368941aa9a0d13f4cc1ad3b..926d5bef45138322bc0694df9c46bbb31d3c4c87 100644 (file)
@@ -288,16 +288,16 @@ backsql_dn2id(
                        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;
                        }
@@ -933,7 +933,7 @@ backsql_id2entry( backsql_srch_info *bsi, backsql_entryID *eid )
                        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;
index ba8fd4ecbe818ae85d70bf42700819530369888b..ac4ae5baa13863a3fbc2f3d033814b7470a31090 100644 (file)
@@ -204,12 +204,17 @@ RETCODE backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, const char* query, int time
                        (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 );
index 87a069ba56b31844e14fd35e14e5d42a6dfa2701..9c8d771a9d58f7235fa6f8d35f5cc4e060b906a1 100644 (file)
@@ -199,7 +199,7 @@ backsql_add_sysmaps( backsql_info *bi, backsql_oc_map_rec *oc_map )
        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, 
@@ -242,7 +242,7 @@ backsql_add_sysmaps( backsql_info *bi, backsql_oc_map_rec *oc_map )
                        "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 );
        }
@@ -256,7 +256,7 @@ backsql_add_sysmaps( backsql_info *bi, backsql_oc_map_rec *oc_map )
                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 );
@@ -297,7 +297,7 @@ struct backsql_attr_schema_info {
        backsql_info    *bas_bi;
        SQLHDBC         bas_dbh;
        SQLHSTMT        bas_sth;
-       unsigned long   *bas_oc_id;
+       backsql_key_t   *bas_oc_id;
        int             bas_rc;
 };
 
@@ -317,7 +317,7 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas )
                "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 );
@@ -328,7 +328,7 @@ backsql_oc_get_attr_mapping( void *v_oc, void *v_bas )
                        "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 );
@@ -503,7 +503,7 @@ backsql_load_schema_map( backsql_info *bi, SQLHDBC dbh )
        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;
 
@@ -569,11 +569,13 @@ backsql_load_schema_map( backsql_info *bi, SQLHDBC dbh )
                                { 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,
@@ -614,7 +616,7 @@ backsql_load_schema_map( backsql_info *bi, SQLHDBC dbh )
                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 );
@@ -730,7 +732,7 @@ backsql_load_schema_map( backsql_info *bi, SQLHDBC dbh )
                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 );
index 21adfed7ee0a3f48316b219961cecd6584f8904b..8ab839d177fe6cb2893eb96cf50b70954af54a27 100644 (file)
@@ -1746,9 +1746,10 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi )
                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(): "
@@ -1940,10 +1941,10 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi )
                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 */
@@ -2237,7 +2238,7 @@ backsql_search( Operation *op, SlapReply *rs )
                }
 
                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) );