]> git.sur5r.net Git - openldap/commitdiff
(blind) improvement of column name aliasing
authorPierangelo Masarati <ando@openldap.org>
Fri, 21 Jan 2005 17:27:27 +0000 (17:27 +0000)
committerPierangelo Masarati <ando@openldap.org>
Fri, 21 Jan 2005 17:27:27 +0000 (17:27 +0000)
servers/slapd/back-sql/back-sql.h
servers/slapd/back-sql/init.c
servers/slapd/back-sql/schema-map.c
servers/slapd/back-sql/search.c
servers/slapd/back-sql/sql-wrap.c
servers/slapd/back-sql/util.c

index 80794716864cf1707d6fd5f8f53958bc37657700..49af9ed694e9513f419c4d4c07013c31f9b54146 100644 (file)
@@ -245,8 +245,9 @@ typedef struct {
  * in quotes.  This is especially true for those that do not
  * allow keywords used as aliases.
  */
-/* #define BACKSQL_ALIASING_QUOTE      '"' */
-/* #define BACKSQL_ALIASING_QUOTE      '\'' */
+#define BACKSQL_ALIASING_QUOTE ""
+/* #define BACKSQL_ALIASING_QUOTE      "\"" */
+/* #define BACKSQL_ALIASING_QUOTE      "'" */
 
 /*
  * API
index 678d106d411753a4d9bcb677e747bad58a7629f0..69c72e85c70ed20574274acc6ca80e14388de1f0 100644 (file)
@@ -456,8 +456,9 @@ backsql_db_open(
        bb.bb_val.bv_len = 0;
        bb.bb_len = 0;
        backsql_strfcat( &bb, "sb",
-                       "SELECT COUNT(distinct subordinates.id) FROM ldap_entries,ldap_entries subordinates WHERE subordinates.parent=ldap_entries.id AND ",
-
+                       "SELECT COUNT(distinct subordinates.id) "
+                       "FROM ldap_entries,ldap_entries " BACKSQL_ALIASING "subordinates "
+                       "WHERE subordinates.parent=ldap_entries.id AND ",
                        &bi->sql_children_cond );
        bi->sql_has_children_query = bb.bb_val.bv_val;
  
index 7d7be83a8f311bff975ea17b8e430fee9640865a..9ce43498d3f40329746ebbcf0bc027e3cb2f4d55 100644 (file)
@@ -105,35 +105,20 @@ backsql_make_attr_query(
 {
        struct berbuf   bb = BB_NULL;
 
-#ifdef BACKSQL_ALIASING_QUOTE
-       backsql_strfcat( &bb, "lblcbclblbcbl", 
-                       (ber_len_t)STRLENOF( "SELECT " ), "SELECT ", 
-                       &at_map->bam_sel_expr, 
-                       (ber_len_t)STRLENOF( " " BACKSQL_ALIASING ), " " BACKSQL_ALIASING, 
-                       BACKSQL_ALIASING_QUOTE,
-                       &at_map->bam_ad->ad_cname,
-                       BACKSQL_ALIASING_QUOTE,
-                       (ber_len_t)STRLENOF( " FROM " ), " FROM ", 
-                       &at_map->bam_from_tbls, 
-                       (ber_len_t)STRLENOF( " WHERE " ), " WHERE ", 
-                       &oc_map->bom_keytbl,
-                       '.', 
-                       &oc_map->bom_keycol,
-                       (ber_len_t)STRLENOF( "=?" ), "=?" );
-#else /* ! BACKSQL_ALIASING_QUOTE */
        backsql_strfcat( &bb, "lblblblbcbl", 
                        (ber_len_t)STRLENOF( "SELECT " ), "SELECT ", 
                        &at_map->bam_sel_expr, 
-                       (ber_len_t)STRLENOF( " " BACKSQL_ALIASING ), " " BACKSQL_ALIASING, 
+                       (ber_len_t)STRLENOF( " " BACKSQL_ALIASING BACKSQL_ALIASING_QUOTE ),
+                               " " BACKSQL_ALIASING BACKSQL_ALIASING_QUOTE, 
                        &at_map->bam_ad->ad_cname,
-                       (ber_len_t)STRLENOF( " FROM " ), " FROM ", 
+                       (ber_len_t)STRLENOF( BACKSQL_ALIASING_QUOTE " FROM " ),
+                               BACKSQL_ALIASING_QUOTE " FROM ", 
                        &at_map->bam_from_tbls, 
                        (ber_len_t)STRLENOF( " WHERE " ), " WHERE ", 
                        &oc_map->bom_keytbl,
                        '.', 
                        &oc_map->bom_keycol,
                        (ber_len_t)STRLENOF( "=?" ), "=?" );
-#endif /* ! BACKSQL_ALIASING_QUOTE */
 
        if ( !BER_BVISNULL( &at_map->bam_join_where ) ) {
                backsql_strfcat( &bb, "lb",
@@ -141,17 +126,12 @@ backsql_make_attr_query(
                                &at_map->bam_join_where );
        }
 
-#ifdef BACKSQL_ALIASING_QUOTE
-       backsql_strfcat( &bb, "lcbc", 
-                       (ber_len_t)STRLENOF( " ORDER BY " ), " ORDER BY ",
-                       BACKSQL_ALIASING_QUOTE,
+       backsql_strfcat( &bb, "lbl", 
+                       (ber_len_t)STRLENOF( " ORDER BY " BACKSQL_ALIASING_QUOTE ),
+                               " ORDER BY " BACKSQL_ALIASING_QUOTE,
                        &at_map->bam_sel_expr,
-                       BACKSQL_ALIASING_QUOTE );
-#else /* ! BACKSQL_ALIASING_QUOTE */
-       backsql_strfcat( &bb, "lb", 
-                       (ber_len_t)STRLENOF( " ORDER BY " ), " ORDER BY ",
-                       &at_map->bam_sel_expr );
-#endif /* ! BACKSQL_ALIASING_QUOTE */
+                       (ber_len_t)STRLENOF( BACKSQL_ALIASING_QUOTE ),
+                               BACKSQL_ALIASING_QUOTE );
 
        at_map->bam_query = bb.bb_val.bv_val;
 
index e99842c67f9bbc6a3190cbc0de3c64f167d6514d..0381f6974f554bfc58e839e3b2e48f98d22ed49f 100644 (file)
@@ -1289,21 +1289,13 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
                                &bsi->bsi_oc->bom_oc->soc_cname,
                                '\'' );
        }
-#ifdef BACKSQL_ALIASING_QUOTE
-       backsql_strfcat( &bsi->bsi_sel, "lclcl",
-                       (ber_len_t)STRLENOF( " " BACKSQL_ALIASING ),
-                               " " BACKSQL_ALIASING,
-                       BACKSQL_ALIASING_QUOTE,
-                       (ber_len_t)STRLENOF( "objectClass" ),
-                               "objectClass",
-                       BACKSQL_ALIASING_QUOTE,
-                       (ber_len_t)STRLENOF( ",ldap_entries.dn " BACKSQL_ALIASING "dn" ),
-                               ",ldap_entries.dn " BACKSQL_ALIASING "dn" );
-#else /* ! BACKSQL_ALIASING_QUOTE */
        backsql_strfcat( &bsi->bsi_sel, "l",
-                       (ber_len_t)STRLENOF( " " BACKSQL_ALIASING "objectClass,ldap_entries.dn " BACKSQL_ALIASING "dn" ),
-                               " " BACKSQL_ALIASING "objectClass,ldap_entries.dn " BACKSQL_ALIASING "dn" );
-#endif /* ! BACKSQL_ALIASING_QUOTE */
+                       (ber_len_t)STRLENOF( " " BACKSQL_ALIASING 
+                                       BACKSQL_ALIASING_QUOTE "objectClass" BACKSQL_ALIASING_QUOTE 
+                                       ",ldap_entries.dn " BACKSQL_ALIASING BACKSQL_ALIASING_QUOTE "dn" BACKSQL_ALIASING_QUOTE ),
+                               " " BACKSQL_ALIASING 
+                                       BACKSQL_ALIASING_QUOTE "objectClass" BACKSQL_ALIASING_QUOTE
+                                       ",ldap_entries.dn " BACKSQL_ALIASING BACKSQL_ALIASING_QUOTE "dn" BACKSQL_ALIASING_QUOTE );
 
        backsql_strfcat( &bsi->bsi_from, "lb",
                        (ber_len_t)STRLENOF( " FROM ldap_entries," ),
index 13d715395ffc1b2f510270b1d3d9eef695fb1cee..61beb4f14a176808d4aafb595f1d440817c9e632 100644 (file)
@@ -126,7 +126,7 @@ backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout )
                        0, 0, 0 );
 #endif /* BACKSQL_TRACE */
 
-       return SQLPrepare( *sth, query, SQL_NTS );
+       return SQLPrepare( *sth, (SQLCHAR *)query, SQL_NTS );
 }
 
 RETCODE
@@ -174,7 +174,7 @@ backsql_BindRowAsStrings( SQLHSTMT sth, BACKSQL_ROW_NTS *row )
                                        (SQLUINTEGER)( sizeof( colname ) - 1 ),
                                        &name_len, &col_type,
                                        &col_prec, &col_scale, &col_null );
-                       ber_str2bv( colname, 0, 1, &row->col_names[ i - 1 ] );
+                       ber_str2bv( (char *)colname, 0, 1, &row->col_names[ i - 1 ] );
 #ifdef BACKSQL_TRACE
                        Debug( LDAP_DEBUG_TRACE, "backsql_BindRowAsStrings: "
                                "col_name=%s, col_prec[%d]=%d\n",
index 641abc7eb1829c74708d386396057164c981eda8..ab4042e9264ca79e6a4bcf400ba32c9299f63b3c 100644 (file)
@@ -312,12 +312,7 @@ backsql_get_table_spec( char **p )
        }
 
        /* oracle doesn't understand "AS" :( and other RDBMSes don't need it */
-#ifdef BACKSQL_ALIASING_QUOTE
-       backsql_strfcat( &res, "scsc", " " BACKSQL_ALIASING,
-                       BACKSQL_ALIASING_QUOTE, s, BACKSQL_ALIASING_QUOTE );
-#else /* ! BACKSQL_ALIASING */
-       backsql_strcat( &res, " " BACKSQL_ALIASING, s, NULL );
-#endif /* ! BACKSQL_ALIASING */
+       backsql_strcat( &res, " " BACKSQL_ALIASING BACKSQL_ALIASING_QUOTE, s, BACKSQL_ALIASING_QUOTE, NULL );
 
        return res.bb_val.bv_val;
 }