Skip to Content.
Sympa Menu

freetds - Re: [freetds] connecting to two databases with the same name but on different servers

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Chris Brookes" <cbrookes AT gmail.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Cc: chris AT txrx.org
  • Subject: Re: [freetds] connecting to two databases with the same name but on different servers
  • Date: Fri, 20 Jul 2007 20:32:54 -0500

On 20/07/07, James K. Lowden <jklowden AT freetds.org> wrote:

project over 5 years now, and I don't remember another query like yours.)
That said, I'd happily apply a patch.

I wrote a quick patch. I only write C when I have to so you might want
to look closely at what I've done. It doesn't actually amount to much.
It's also against 0.64 where as it should probably be against CVS, so
my apologies for that. I'd wrote it before I thought of checking for
something more current than stable.

Sybase server and Microsoft's Express product. If you don't mind my
asking, why do you use ASA instead?

It is embedded in to the Ciscoworks product, so there's not really
much choice in the matter. Thanks for the pointer on where to look in
the code.

Chris
diff -Naur freetds-0.64/include/tds.h freetds-0.64-patched/include/tds.h
--- freetds-0.64/include/tds.h 2006-06-29 16:38:12.000000000 -0500
+++ freetds-0.64-patched/include/tds.h 2007-07-20 19:26:54.997845000 -0500
@@ -689,6 +689,7 @@
#define TDS_STR_DEBUGFLAGS "debug flags"
#define TDS_STR_TIMEOUT "timeout"
#define TDS_STR_QUERY_TIMEOUT "query timeout"
+#define TDS_STR_ASADB_NAME "asadb name"
#define TDS_STR_CONNTIMEOUT "connect timeout"
#define TDS_STR_HOSTNAME "hostname"
#define TDS_STR_HOST "host"
@@ -716,6 +717,7 @@
typedef struct tds_login
{
DSTR server_name;
+ DSTR asadb_name;
DSTR server_addr;
int port;
TDS_TINYINT major_version; /* TDS version */
@@ -743,6 +745,7 @@
{
/* first part of structure is the same of login one */
DSTR server_name; /**< server name (in freetds.conf) */
+ DSTR asadb_name; /**< server name (in freetds.conf) */
int port; /**< port of database service */
TDS_TINYINT major_version;
TDS_TINYINT minor_version;
diff -Naur freetds-0.64/src/server/login.c
freetds-0.64-patched/src/server/login.c
--- freetds-0.64/src/server/login.c 2006-02-24 15:14:28.000000000 -0600
+++ freetds-0.64-patched/src/server/login.c 2007-07-20 17:39:18.187119000
-0500
@@ -126,6 +126,7 @@
tds_get_n(tds, NULL, 16); /* magic */
tds_read_string(tds, &login->app_name, 30);
tds_read_string(tds, &login->server_name, 30);
+ tds_read_string(tds, &login->asadb_name, 30);
tds_get_n(tds, NULL, 256); /* secondary passwd...encryption? */
login->major_version = tds_get_byte(tds);
login->minor_version = tds_get_byte(tds);
diff -Naur freetds-0.64/src/tds/config.c freetds-0.64-patched/src/tds/config.c
--- freetds-0.64/src/tds/config.c 2006-02-24 15:14:28.000000000 -0600
+++ freetds-0.64-patched/src/tds/config.c 2007-07-20 19:40:59.415029000
-0500
@@ -461,6 +461,8 @@
tds_g_append_mode = tds_config_boolean(value);
} else if (!strcmp(option, TDS_STR_INSTANCE)) {
tds_dstr_copy(&connection->instance_name, value);
+ } else if (!strcmp(option, TDS_STR_ASADB_NAME)) {
+ tds_dstr_copy(&connection->asadb_name, value);
} else {
tdsdump_log(TDS_DBG_INFO1, "UNRECOGNIZED option
'%s'...ignoring.\n", option);
}
@@ -487,6 +489,9 @@
tdsdump_log(TDS_DBG_INFO1, "tds_config_login: %s is %s.\n",
"client_charset",
tds_dstr_cstr(&connection->client_charset));
}
+ if (!tds_dstr_isempty(&login->asadb_name)) {
+ tds_dstr_copy(&connection->asadb_name,
tds_dstr_cstr(&login->asadb_name));
+ }
if (!tds_dstr_isempty(&login->host_name)) {
tds_dstr_copy(&connection->host_name,
tds_dstr_cstr(&login->host_name));
/*
@@ -533,6 +538,7 @@
}
if (login->connect_timeout)
connection->connect_timeout = login->connect_timeout;
+

if (login->query_timeout)
connection->query_timeout = login->query_timeout;
diff -Naur freetds-0.64/src/tds/login.c freetds-0.64-patched/src/tds/login.c
--- freetds-0.64/src/tds/login.c 2006-02-24 15:14:28.000000000 -0600
+++ freetds-0.64-patched/src/tds/login.c 2007-07-20 20:02:43.751040000
-0500
@@ -381,7 +381,12 @@
}
tds_put_n(tds, magic3, 3);
tds_put_login_string(tds, tds_dstr_cstr(&connection->app_name),
TDS_MAX_LOGIN_STR_SZ);
- tds_put_login_string(tds, tds_dstr_cstr(&connection->server_name),
TDS_MAX_LOGIN_STR_SZ);
+ if (!tds_dstr_isempty(&connection->asadb_name)) {
+ tdsdump_log(TDS_DBG_INFO1, "Config specified an ASA database,
over-riding default database name\n");
+ tds_put_login_string(tds,
tds_dstr_cstr(&connection->asadb_name), TDS_MAX_LOGIN_STR_SZ);
+ } else {
+ tds_put_login_string(tds,
tds_dstr_cstr(&connection->server_name), TDS_MAX_LOGIN_STR_SZ);
+ }
if (IS_TDS42(tds)) {
tds_put_login_string(tds,
tds_dstr_cstr(&connection->password), 255);
} else {
@@ -447,7 +452,6 @@
tds_put_smallint(tds, TDS_MAX_CAPABILITY);
tds_put_n(tds, tds->capabilities, TDS_MAX_CAPABILITY);
}
-
return tds_flush_packet(tds);
}

diff -Naur freetds-0.64/src/tds/mem.c freetds-0.64-patched/src/tds/mem.c
--- freetds-0.64/src/tds/mem.c 2006-06-29 16:38:14.000000000 -0500
+++ freetds-0.64-patched/src/tds/mem.c 2007-07-20 17:03:55.617583000 -0500
@@ -592,6 +592,7 @@
TEST_MALLOC(connection, TDSCONNECTION);
memset(connection, '\0', sizeof(TDSCONNECTION));
tds_dstr_init(&connection->server_name);
+ tds_dstr_init(&connection->asadb_name);
tds_dstr_init(&connection->language);
tds_dstr_init(&connection->server_charset);
tds_dstr_init(&connection->host_name);
@@ -754,6 +755,7 @@
return NULL;
memset(tds_login, '\0', sizeof(TDSLOGIN));
tds_dstr_init(&tds_login->server_name);
+ tds_dstr_init(&tds_login->asadb_name);
tds_dstr_init(&tds_login->server_addr);
tds_dstr_init(&tds_login->language);
tds_dstr_init(&tds_login->server_charset);
@@ -775,6 +777,7 @@
tds_dstr_zero(&login->password);
tds_dstr_free(&login->password);
tds_dstr_free(&login->server_name);
+ tds_dstr_free(&login->asadb_name);
tds_dstr_free(&login->server_addr);
tds_dstr_free(&login->language);
tds_dstr_free(&login->server_charset);
@@ -883,6 +886,7 @@
tds_free_connection(TDSCONNECTION * connection)
{
tds_dstr_free(&connection->server_name);
+ tds_dstr_free(&connection->asadb_name);
tds_dstr_free(&connection->host_name);
tds_dstr_free(&connection->language);
tds_dstr_free(&connection->server_charset);



Archive powered by MHonArc 2.6.24.

Top of Page