Re: Using DBLIB With Azure

Ken Collins <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
Success!!

> DBSETLDBNAME() is the most natural way to extend db-lib to include the database name in the login packet.  It will require modifying TDSLOGIN to hold the name, and tds_config_login() to copy it to the TDSCONNECTION.  

Attached is a diff/patch that I am able to confirm works for me and allows me to connection with TinyTDS. This means any db-lib can not use DBSETLDBNAME to do the same. In case the attachment for the patch does not come thru, here it is in a gist. https://gist.github.com/889190

James, can this small function make it into the release?


 - Ken

_______________________________________________
FreeTDS mailing list
[email protected]
http://lists.ibiblio.org/mailman/listinfo/freetds
patch-defaultdb.diff (application/octet-stream, 2.9 KB)
--- include/sybdb.h
+++ include/sybdb.h
@@ -1165,6 +1165,8 @@ RETCODE dbsetlversion (LOGINREC * login, BYTE version);
 #define DBSETLABELED		13
 #define DBSETLLABELED(x,y)	dbsetlbool((x), (y), DBSETLABELED)
 #define BCP_SETLABELED(x,y)	dbsetlbool((x), (y), DBSETLABELED)
+#define DBSETDBNAME		14
+#define DBSETLDBNAME(x,y)	dbsetlname((x), (y), DBSETDBNAME)
 #define DBSETLVERSION(login, version) dbsetlversion((login), (version))
 
 RETCODE bcp_init(DBPROCESS * dbproc, const char *tblname, const char *hfile, const char *errfile, int direction);
--- include/tds.h
+++ include/tds.h
@@ -844,6 +844,7 @@ typedef struct tds_login
 	TDS_INT query_timeout;
 	unsigned char capabilities[TDS_MAX_CAPABILITY];
 	DSTR client_charset;
+	DSTR database;
 	unsigned int bulk_copy:1;
 	unsigned int suppress_language:1;
 } TDSLOGIN;
@@ -1468,6 +1469,7 @@ void tds_set_library(TDSLOGIN * tds_login, const char *library);
 void tds_set_server(TDSLOGIN * tds_login, const char *server);
 void tds_set_client_charset(TDSLOGIN * tds_login, const char *charset);
 void tds_set_language(TDSLOGIN * tds_login, const char *language);
+void tds_set_database_name(TDSLOGIN * tds_login, const char *dbname);
 void tds_set_version(TDSLOGIN * tds_login, TDS_TINYINT major_ver, TDS_TINYINT minor_ver);
 void tds_set_capabilities(TDSLOGIN * tds_login, unsigned char *capabilities, int size);
 int tds_connect_and_login(TDSSOCKET * tds, TDSCONNECTION * connection);
--- src/dblib/dblib.c
+++ src/dblib/dblib.c
@@ -780,6 +780,10 @@ dbsetlname(LOGINREC * login, const char *value, int which)
 		tds_set_language(login->tds_login, value);
 		return SUCCEED;
 		break;
+	case DBSETDBNAME:
+	  tds_set_database_name(login->tds_login, value ? value : "");
+		return SUCCEED;
+		break;
 	default:
 		dbperror(NULL, SYBEASUL, 0); /* Attempt to set unknown LOGINREC field */
 		return FAIL;
--- src/tds/config.c
+++ src/tds/config.c
@@ -640,6 +640,11 @@ tds_config_login(TDSCONNECTION * connection, TDSLOGIN * login)
 		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->database)) {
+		tds_dstr_dup(&connection->database, &login->database);
+		tdsdump_log(TDS_DBG_INFO1, "tds_config_login: %s is %s.\n", "database_name",
+			    tds_dstr_cstr(&connection->database));
+	}
 	if (!tds_dstr_isempty(&login->client_host_name)) {
 		tds_dstr_dup(&connection->client_host_name, &login->client_host_name);
 	}
--- src/tds/login.c
+++ src/tds/login.c
@@ -163,6 +163,12 @@ tds_set_language(TDSLOGIN * tds_login, const char *language)
 }
 
 void
+tds_set_database_name(TDSLOGIN * tds_login, const char *dbname)
+{
+	tds_dstr_copy(&tds_login->database, dbname);
+}
+
+void
 tds_set_capabilities(TDSLOGIN * tds_login, unsigned char *capabilities, int size)
 {
 	memcpy(tds_login->capabilities, capabilities, size > TDS_MAX_CAPABILITY ? TDS_MAX_CAPABILITY : size);
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.