Re: Support Host/Port In DBLIB

Frediano Ziglio <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
2011/4/14 Ken Collins <[email protected]>:
>
>>> If we want to add many attributes even in dblib I think we should
>>> think about a standard way to add these. For this reason and cause the
>>> patch is about adding feature I personally won't put it in rc version.
>>
>> Agreed.  Except all this name decorating (:port, \instance) is ad hoc
>> and not well supported.  Environment variables are the way to go.
>>
>> --jkl
>
> Currently the host and port are not working on Windows and sometimes unix'y platforms. I am debugging and plan on reporting back soon with my finding and hopefully a patch or at the least a clear understanding with how to make this work across the board and where things have broken down.
>
> More to come...
>

Hi Ken,
  how this patch works for you ??

Frediano

_______________________________________________
FreeTDS mailing list
[email protected]
http://lists.ibiblio.org/mailman/listinfo/freetds
default.diff (application/octet-stream, 1.8 KB)
Index: src/tds/config.c
===================================================================
RCS file: /cvs/freetds/freetds/src/tds/config.c,v
retrieving revision 1.164
diff -u -1 -0 -p -r1.164 config.c
--- src/tds/config.c	14 Apr 2011 02:47:08 -0000	1.164
+++ src/tds/config.c	14 Apr 2011 09:12:31 -0000
@@ -183,24 +183,31 @@ tds_read_config_info(TDSSOCKET * tds, TD
 	}
 
 	tdsdump_log(TDS_DBG_INFO1, "Getting connection information for [%s].\n", 
 			    tds_dstr_cstr(&login->server_name));	/* (The server name is set in login.c.) */
 
 	/* Read the config files. */
 	tdsdump_log(TDS_DBG_INFO1, "Attempting to read conf files.\n");
 	found = tds_read_conf_file(connection, tds_dstr_cstr(&login->server_name));
 	if (!found) {
 		if (parse_server_name_for_port(connection, login)) {
+			char ip_addr[256];
+
 			found = tds_read_conf_file(connection, tds_dstr_cstr(&connection->server_name));
 			/* do it again to really override what found in freetds.conf */
-			if (found)
+			if (found) {
 				parse_server_name_for_port(connection, login);
+			} else if (tds_lookup_host(tds_dstr_cstr(&connection->server_name), ip_addr) == TDS_SUCCEED) {
+				tds_dstr_dup(&connection->server_host_name, &connection->server_name);
+				tds_dstr_copy(&connection->ip_addr, ip_addr);
+				found = 1;
+			}
 		}
 	}
 	if (!found) {
 		/* fallback to interfaces file */
 		tdsdump_log(TDS_DBG_INFO1, "Failed in reading conf file.  Trying interface files.\n");
 		if (!tds_read_interfaces(tds_dstr_cstr(&login->server_name), connection)) {
 			tdsdump_log(TDS_DBG_INFO1, "Failed to find [%s] in configuration files; trying '%s' instead.\n", 
 						   tds_dstr_cstr(&login->server_name), tds_dstr_cstr(&connection->server_name));
 			if (tds_dstr_isempty(&connection->ip_addr))
 				tdserror(tds->tds_ctx, tds, TDSEINTF, 0);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.