[freetds] Column aliasing not working

Josh Samuelson josamue1 at wsc.edu
Thu May 6 17:48:13 EDT 2010


It was brought to my attention by our web developers that column aliasing
stopped working on ODBC connections when we migrated our development
environment from Debian Etch (old stable) to Debian Lenny.

SELECT SomeColumn AS AliasColumn FROM SomeTable;

would return the column name as SomeColumn rather than AliasColumn.

We use FreeTDS in the following chain:

    PHP ODBC (version 5.2.6)  ->
    unixODBC (version 2.2.11) ->
    FreeTDS  (version 0.82)   ->
    MS SQL Server Enterprise Edition (version 9.00.4053.00).

The version of FreeTDS jumped from 0.63 to 0.82 with the Debian upgrade.

I've spent the last couple of days trying to figure out what may be
at fault.  I found that lowering "tds verions = 8.0" to "tds version = 4.2"
for the database section of the configuration would bring column aliasing
back.  I also found that recompiling the ODBC module of PHP without the
HAVE_SQL_EXTENDED_FETCH define would do the same.  Comparing FreeTDS's
dump file output between the various working and not working settings
I closed in on what I think may be a bug, but I'll defer that call
to the developers.  Please see the attached patch against Revision 1.531
of src/odbc/odbc.c  With this patch applied aliasing works again.

Perhaps what we are seeing is related to Message-ID: <4A649194.6BF3.0066.0 at scc-fl.edu>?

Josh Samuelson
Network Specialist/UNIX Administrator
Network and Technology Services
Wayne State College
Wayne, NE
-------------- next part --------------
diff -Nru a/src/odbc/odbc.c b/src/odbc/odbc.c
--- a/src/odbc/odbc.c	2010-03-22 09:42:16.000000000 -0500
+++ b/src/odbc/odbc.c	2010-05-06 16:00:00.000000000 -0500
@@ -2873,12 +2873,9 @@
 		odbc_set_sql_type_info(col, drec, stmt->dbc->env->attr.odbc_version);
-		if (!col->table_column_name) {
-			if (!tds_dstr_copyn(&drec->sql_desc_name, col->column_name, col->column_namelen))
-				return SQL_ERROR;
-		} else {
-			if (!tds_dstr_copy(&drec->sql_desc_name, col->table_column_name))
-				return SQL_ERROR;
+		if (!tds_dstr_copyn(&drec->sql_desc_name, col->column_name, col->column_namelen))
+			return SQL_ERROR;
+		if (col->table_column_name) {
 			if (!tds_dstr_copy(&drec->sql_desc_base_column_name, col->table_column_name))
 				return SQL_ERROR;

More information about the FreeTDS mailing list