From 96fa1eda6466fe56e3cf2a12ec65caa695245890 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Fri, 21 Jan 2005 17:27:27 +0000 Subject: [PATCH] (blind) improvement of column name aliasing --- servers/slapd/back-sql/back-sql.h | 5 ++-- servers/slapd/back-sql/init.c | 5 ++-- servers/slapd/back-sql/schema-map.c | 38 +++++++---------------------- servers/slapd/back-sql/search.c | 20 +++++---------- servers/slapd/back-sql/sql-wrap.c | 4 +-- servers/slapd/back-sql/util.c | 7 +----- 6 files changed, 24 insertions(+), 55 deletions(-) diff --git a/servers/slapd/back-sql/back-sql.h b/servers/slapd/back-sql/back-sql.h index 8079471686..49af9ed694 100644 --- a/servers/slapd/back-sql/back-sql.h +++ b/servers/slapd/back-sql/back-sql.h @@ -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 diff --git a/servers/slapd/back-sql/init.c b/servers/slapd/back-sql/init.c index 678d106d41..69c72e85c7 100644 --- a/servers/slapd/back-sql/init.c +++ b/servers/slapd/back-sql/init.c @@ -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; diff --git a/servers/slapd/back-sql/schema-map.c b/servers/slapd/back-sql/schema-map.c index 7d7be83a8f..9ce43498d3 100644 --- a/servers/slapd/back-sql/schema-map.c +++ b/servers/slapd/back-sql/schema-map.c @@ -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; diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index e99842c67f..0381f6974f 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -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," ), diff --git a/servers/slapd/back-sql/sql-wrap.c b/servers/slapd/back-sql/sql-wrap.c index 13d715395f..61beb4f14a 100644 --- a/servers/slapd/back-sql/sql-wrap.c +++ b/servers/slapd/back-sql/sql-wrap.c @@ -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", diff --git a/servers/slapd/back-sql/util.c b/servers/slapd/back-sql/util.c index 641abc7eb1..ab4042e926 100644 --- a/servers/slapd/back-sql/util.c +++ b/servers/slapd/back-sql/util.c @@ -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; } -- 2.39.5