changeset 1525:695e2b5cd616

upgrade package freetds to cvs
author Mark Brand <mabrand@mabrand.nl>
date Sat, 01 Jan 2011 19:20:54 +0100
parents 5208c579581a
children 7e8f36740d45
files src/freetds-1-fastforward.patch
diffstat 1 files changed, 3351 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/freetds-1-fastforward.patch	Thu Dec 23 20:55:19 2010 +1100
+++ b/src/freetds-1-fastforward.patch	Sat Jan 01 19:20:54 2011 +0100
@@ -47,6 +47,7 @@
   doc/htdoc/support.html \
   doc/README.releasing \
   doc/txt2man \
+  misc/bounce.c \
   misc/freetds_autobuild \
   misc/test-dist.sh \
   misc/test-auto.sh \
@@ -4257,6 +4258,443 @@
 +stamp-h1
 +tds_sysdep_public.h
 +freetds_sysconfdir.h
+diff --git b/misc/bounce.c a/misc/bounce.c
+new file mode 100644
+index 0000000..93e9c5c
+--- /dev/null
++++ a/misc/bounce.c
+@@ -0,0 +1,431 @@
++#include <stdio.h>
++#include <stdlib.h>
++#include <errno.h>
++#include <sys/types.h>
++#include <sys/socket.h>
++#include <netinet/in.h>
++#include <arpa/inet.h>
++#include <string.h>
++#include <unistd.h>
++#include <gnutls/gnutls.h>
++
++/* $Id: bounce.c,v 1.1 2007/10/23 10:08:52 freddy77 Exp $ */
++
++/* This small application make man-in-the-middle with a crypted SQL Server
++ * to be able to see decrypted login
++ * It's just a small utility, at end of login it close connection and don't
++ * handle a lot of cases. Works only with mssql2k or later
++ * Based on GnuTLS echo example
++ * compile with:
++ *    gcc -O2 -Wall -o bounce bounce.c -lgnutls
++ */
++
++/* path to certificate, can be created with 
++ * openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
++ */
++#define CERTFILE "mycert.pem"
++
++/* port to listen to, you should connect to this port */
++#define LISTEN_PORT 1433
++/* server and port to connect to, the real server you want to tunnel */
++#define SERVER_IP   "10.20.30.40"
++#define SERVER_PORT 1433
++
++#define SA struct sockaddr
++#define SOCKET_ERR(err,s) if(err==-1) {perror(s);return(1);}
++#define MAX_BUF 1024
++#define DH_BITS 1024
++
++/* These are global */
++gnutls_certificate_credentials_t x509_cred;
++
++static void put_packet(int sd);
++static void get_packet(int sd);
++
++typedef enum
++{
++	prelogin,
++	auth,
++	in_tls
++} State;
++static State state;
++
++static int server_sd = -1;
++static int client_sd = -1;
++
++static unsigned char packet[4096 + 192];
++static int packet_len;
++static int to_send = 0;
++static unsigned char packet_type = 0x12;
++static int pos = 0;
++
++static ssize_t
++tds_pull_func(gnutls_transport_ptr ptr, void *data, size_t len)
++{
++	fprintf(stderr, "in tds_pull_func\n");
++
++	/* if we have some data send it */
++	if (to_send && packet_len >= 8) {
++		packet[1] = 1;
++		put_packet(client_sd);
++		packet_len = 0;
++		to_send = 0;
++	}
++
++	if (state == in_tls) {
++		return recv(client_sd, data, len, 0);
++	}
++	/* read from packet */
++	if (!packet_len || pos >= packet_len) {
++		get_packet(client_sd);
++		pos = 8;
++	}
++	if (!packet_len)
++		exit(1);
++	if (len > (packet_len - pos))
++		len = packet_len - pos;
++	memcpy(data, packet + pos, len);
++	pos += len;
++	printf("read %d bytes\n", len);
++	return len;
++}
++
++static ssize_t
++tds_push_func(gnutls_transport_ptr ptr, const void *data, size_t len)
++{
++	int left;
++
++	if (state == in_tls)
++		return send(server_sd, data, len, 0);
++
++	/* write to packet */
++	if (!to_send)
++		packet_len = 8;
++	to_send = 1;
++	packet[0] = packet_type;
++	left = 4096 - packet_len;
++	if (left <= 0) {
++		packet[1] = 0;	/* not last */
++		put_packet(server_sd);
++		packet_len = 8;
++		left = 4096 - packet_len;
++	}
++	packet[1] = 1;		/* last */
++	if (len > left)
++		len = left;
++	memcpy(packet + packet_len, data, len);
++	packet_len += len;
++	packet[2] = packet_len >> 8;
++	packet[3] = packet_len;
++	return len;
++}
++
++static gnutls_session_t
++initialize_tls_session()
++{
++	gnutls_session_t session;
++	static const int cipher_priority[] = {
++		GNUTLS_CIPHER_ARCFOUR_40,
++		GNUTLS_CIPHER_DES_CBC,
++		GNUTLS_CIPHER_AES_256_CBC, GNUTLS_CIPHER_AES_128_CBC,
++		GNUTLS_CIPHER_3DES_CBC, GNUTLS_CIPHER_ARCFOUR_128,
++		0
++	};
++
++
++	gnutls_init(&session, GNUTLS_SERVER);
++	gnutls_transport_set_pull_function(session, tds_pull_func);
++	gnutls_transport_set_push_function(session, tds_push_func);
++
++	/* avoid calling all the priority functions, since the defaults
++	 * are adequate.
++	 */
++	gnutls_set_default_priority(session);
++	gnutls_cipher_set_priority(session, cipher_priority);
++
++	gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred);
++
++	gnutls_dh_set_prime_bits(session, DH_BITS);
++
++	return session;
++}
++
++static gnutls_dh_params_t dh_params;
++
++static int
++generate_dh_params(void)
++{
++
++	/* Generate Diffie Hellman parameters - for use with DHE
++	 * kx algorithms. These should be discarded and regenerated
++	 * once a day, once a week or once a month. Depending on the
++	 * security requirements.
++	 */
++	gnutls_dh_params_init(&dh_params);
++	gnutls_dh_params_generate2(dh_params, DH_BITS);
++
++	return 0;
++}
++
++static void
++tds_tls_log(int level, const char *s)
++{
++	printf("(%d) %s", level, s);
++}
++
++static int
++tcp_connect(void)
++{
++	int err, sd;
++	struct sockaddr_in sa;
++
++	/* connects to server 
++	 */
++	sd = socket(AF_INET, SOCK_STREAM, 0);
++
++	memset(&sa, '\0', sizeof(sa));
++	sa.sin_family = AF_INET;
++	sa.sin_port = htons(SERVER_PORT);
++	inet_pton(AF_INET, SERVER_IP, &sa.sin_addr);
++
++	err = connect(sd, (SA *) & sa, sizeof(sa));
++	if (sd < 0 || err < 0) {
++		fprintf(stderr, "Connect error\n");
++		exit(1);
++	}
++
++	return sd;
++}
++
++static void
++get_packet(int sd)
++{
++	int full_len, l;
++
++	printf("get_packet\n");
++	packet_len = 0;
++	for (;;) {
++		full_len = 4;
++		if (packet_len >= 4)
++			full_len = (((int) packet[2]) << 8) + packet[3];
++
++		l = recv(sd, packet + packet_len, full_len - packet_len, 0);
++		if (l <= 0) {
++			fprintf(stderr, "error recv\n");
++			exit(1);
++		}
++		packet_len += l;
++
++		if (full_len >= 8 && packet_len == full_len)
++			break;
++	}
++}
++
++static void
++put_packet(int sd)
++{
++	int sent = 0;
++
++	printf("put_packet\n");
++	for (; sent < packet_len;) {
++		int l = send(sd, packet + sent, packet_len - sent, 0);
++
++		if (l <= 0) {
++			fprintf(stderr, "error send\n");
++			exit(1);
++		}
++		sent += l;
++	}
++	to_send = 0;
++}
++
++static void
++hexdump(char *buffer, int len)
++{
++	int i;
++	char hex[16 * 3 + 2], chars[20];
++
++	hex[0] = 0;
++	for (i = 0; len > 0 && i < len; ++i) {
++		if ((i & 15) == 0) {
++			hex[0] = 0;
++			chars[0] = 0;
++		}
++		sprintf(strchr(hex, 0), "%02x ", (unsigned char) buffer[i]);
++		chars[i & 15] = buffer[i] >= 32 && buffer[i] < 126 ? buffer[i] : ' ';
++		chars[(i & 15) + 1] = 0;
++		if ((i & 15) == 15)
++			printf("%04x: %-48s %s\n", i & 0xfff0, hex, chars);
++	}
++	if ((i & 15) != 0)
++		printf("%04x: %-48s %s\n", i & 0xfff0, hex, chars);
++}
++
++int
++main()
++{
++	int err, listen_sd, i;
++	int sd, ret;
++	struct sockaddr_in sa_serv;
++	struct sockaddr_in sa_cli;
++	int client_len;
++	char topbuf[512];
++	gnutls_session_t session;
++	char buffer[MAX_BUF + 1];
++	int optval = 1;
++
++	/* this must be called once in the program
++	 */
++	gnutls_global_init();
++	gnutls_global_set_log_level(11);
++	gnutls_global_set_log_function(tds_tls_log);
++
++
++	gnutls_certificate_allocate_credentials(&x509_cred);
++
++	ret = gnutls_certificate_set_x509_key_file(x509_cred, /* CERTFILE */ CERTFILE, /* KEYFILE */ CERTFILE,
++						   GNUTLS_X509_FMT_PEM);
++	if (ret < 0) {
++		fprintf(stderr, "certificate failed (%s)\n", gnutls_strerror(ret));
++		exit(1);
++	}
++
++	generate_dh_params();
++
++	gnutls_certificate_set_dh_params(x509_cred, dh_params);
++
++	/* Socket operations
++	 */
++	listen_sd = socket(AF_INET, SOCK_STREAM, 0);
++	SOCKET_ERR(listen_sd, "socket");
++
++	memset(&sa_serv, '\0', sizeof(sa_serv));
++	sa_serv.sin_family = AF_INET;
++	sa_serv.sin_addr.s_addr = INADDR_ANY;
++	sa_serv.sin_port = htons(LISTEN_PORT);	/* Server Port number */
++
++	setsockopt(listen_sd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(int));
++
++	err = bind(listen_sd, (SA *) & sa_serv, sizeof(sa_serv));
++	SOCKET_ERR(err, "bind");
++	err = listen(listen_sd, 1024);
++	SOCKET_ERR(err, "listen");
++
++	printf("Server ready. Listening to port '%d'.\n\n", LISTEN_PORT);
++
++	client_len = sizeof(sa_cli);
++	for (;;) {
++		session = initialize_tls_session();
++
++		client_sd = sd = accept(listen_sd, (SA *) & sa_cli, &client_len);
++
++		printf("- connection from %s, port %d\n",
++		       inet_ntop(AF_INET, &sa_cli.sin_addr, topbuf, sizeof(topbuf)), ntohs(sa_cli.sin_port));
++
++		/* now do prelogin */
++		/* connect to real peer */
++		printf("connect to real peer\n");
++		server_sd = tcp_connect();
++
++		/* get prelogin packet from client */
++		printf("get prelogin packet from client\n");
++		get_packet(client_sd);
++
++		/* send prelogin packet to server */
++		printf("send prelogin packet to server\n");
++		put_packet(server_sd);
++
++		/* get prelogin reply from server */
++		printf("get prelogin reply from server\n");
++		get_packet(server_sd);
++
++		/* reply with same prelogin packet */
++		printf("reply with same prelogin packet\n");
++		put_packet(client_sd);
++
++		/* now we must do authentication with client and with server */
++		state = auth;
++		packet_len = 0;
++
++		/* do with client */
++		gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t) sd);
++		ret = gnutls_handshake(session);
++		if (ret < 0) {
++			close(sd);
++			gnutls_deinit(session);
++			fprintf(stderr, "*** Handshake has failed (%s)\n\n", gnutls_strerror(ret));
++			continue;
++		}
++		printf("- Handshake was completed\n");
++
++		/* flush last packet */
++		packet[0] = 4;
++		packet[1] = 1;
++		put_packet(client_sd);
++
++		/* on, reset all */
++		state = in_tls;
++		to_send = 0;
++		packet_len = 0;
++
++		/* do with server */
++
++		/* now log and do man-in-the-middle to see decrypted data !!! */
++		for (;;) {
++			/* wait all packet */
++			sleep(2);
++
++			/* get client */
++			ret = gnutls_record_recv(session, buffer, MAX_BUF);
++			if (ret > 0) {
++				hexdump(buffer, ret);
++
++				gnutls_record_send(session, buffer, ret);
++
++				ret = gnutls_record_recv(session, buffer, MAX_BUF);
++				if (ret > 0)
++					hexdump(buffer, ret);
++			}
++			/* for the moment.. */
++			exit(1);
++
++			/* send to server */
++		}
++
++		/* see the Getting peer's information example */
++		/* print_info(session); */
++
++		i = 0;
++		for (;;) {
++			bzero(buffer, MAX_BUF + 1);
++			ret = gnutls_record_recv(session, buffer, MAX_BUF);
++
++			if (ret == 0) {
++				printf("\n- Peer has closed the GNUTLS connection\n");
++				break;
++			} else if (ret < 0) {
++				fprintf(stderr, "\n*** Received corrupted " "data(%d). Closing the connection.\n\n", ret);
++				break;
++			} else if (ret > 0) {
++				/* echo data back to the client */
++				hexdump(buffer, ret);
++				gnutls_record_send(session, buffer, ret);
++			}
++		}
++		printf("\n");
++		/* do not wait for the peer to close the connection. */
++		gnutls_bye(session, GNUTLS_SHUT_WR);
++
++		close(sd);
++		gnutls_deinit(session);
++
++	}
++	close(listen_sd);
++
++	gnutls_certificate_free_credentials(x509_cred);
++
++	gnutls_global_deinit();
++
++	return 0;
++}
++
 diff --git b/misc/freetds_autobuild a/misc/freetds_autobuild
 new file mode 100755
 index 0000000..a78d6f4
@@ -161086,3 +161524,2916 @@
  
  		return;
  
+
+commit 54e54eefca933da532d21b2daf7a6929dcd2e5c2
+Author: freddy77 <freddy77>
+Date:   Thu Dec 23 09:32:27 2010 +0000
+
+    dblib indicator is DBINT
+
+diff --git a/ChangeLog b/ChangeLog
+index 0a57dfc..bf428a5 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,6 @@
++Thu Dec 23 10:32:02 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
++	* src/dblib/buffering.h src/dblib/dblib.c: dblib indicator is DBINT
++
+ Tue Dec 21 11:53:40 EST 2010	JK Lowden <jklowden@freetds.org>
+ 	* src/apps/bsqldb.c src/apps/tsql.c src/dblib/dblib.c
+ 	- allow Kerberos/sspi connections without username
+@@ -3067,4 +3070,4 @@ Wed Jan  9 19:54:43 EST 2008	JK Lowden <jklowden@freetds.org>
+ 	* ChangeLog-0.82 added because of release
+ 	
+ $FreeTDS$
+-$Id: ChangeLog,v 1.3172 2010/12/21 16:55:23 jklowden Exp $
++$Id: ChangeLog,v 1.3173 2010/12/23 09:32:27 freddy77 Exp $
+diff --git a/src/dblib/buffering.h b/src/dblib/buffering.h
+index f51d92c..7ad3ff8 100644
+--- a/src/dblib/buffering.h
++++ b/src/dblib/buffering.h
+@@ -344,7 +344,7 @@ buffer_transfer_bound_data(DBPROC_ROWBUF *buf, TDS_INT res_type, TDS_INT compute
+ 		} else {
+ 			copy_data_to_host_var(dbproc, srctype, src, srclen, desttype, 
+ 						(BYTE *) curcol->column_varaddr,  curcol->column_bindlen,
+-							 curcol->column_bindtype, curcol->column_nullbind);
++							 curcol->column_bindtype, (DBINT*) curcol->column_nullbind);
+ 		}
+ 	}
+ 
+diff --git a/src/dblib/dblib.c b/src/dblib/dblib.c
+index 343cce3..dd6c26f 100644
+--- a/src/dblib/dblib.c
++++ b/src/dblib/dblib.c
+@@ -75,7 +75,7 @@
+ #include <dmalloc.h>
+ #endif
+ 
+-TDS_RCSID(var, "$Id: dblib.c,v 1.372 2010/12/21 16:55:24 jklowden Exp $");
++TDS_RCSID(var, "$Id: dblib.c,v 1.373 2010/12/23 09:32:27 freddy77 Exp $");
+ 
+ static RETCODE _dbresults(DBPROCESS * dbproc);
+ static int _db_get_server_type(int bindtype);
+@@ -84,7 +84,7 @@ static char *_dbprdate(char *timestr);
+ static int _dbnullable(DBPROCESS * dbproc, int column);
+ static char *tds_prdatatype(TDS_SERVER_TYPE datatype_token);
+ 
+-static void copy_data_to_host_var(DBPROCESS *, int, const BYTE *, DBINT, int, BYTE *, DBINT, int, DBSMALLINT *);
++static void copy_data_to_host_var(DBPROCESS *, int, const BYTE *, DBINT, int, BYTE *, DBINT, int, DBINT *);
+ static int default_err_handler(DBPROCESS * dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr);
+ 
+ static RETCODE dbgetnull(DBPROCESS *dbproc, int bindtype, int varlen, BYTE* varaddr);
+@@ -7185,12 +7185,12 @@ tds_prdatatype(TDS_SERVER_TYPE datatype_token)
+ static void
+ copy_data_to_host_var(DBPROCESS * dbproc, int srctype, const BYTE * src, DBINT srclen, 
+ 				int desttype, BYTE * dest, DBINT destlen,
+-				int bindtype, DBSMALLINT *indicator)
++				int bindtype, DBINT *indicator)
+ {
+ 	CONV_RESULT dres;
+ 	DBINT ret;
+ 	int i, len;
+-	DBSMALLINT indicator_value = 0;
++	DBINT indicator_value = 0;
+ 
+ 	int limited_dest_space = 0;
+ 
+
+commit 4d66e4959040676cd7232a6d8b651999ebd6ba37
+Author: freddy77 <freddy77>
+Date:   Tue Dec 28 14:37:10 2010 +0000
+
+    use C99 constant for printf format string
+
+diff --git a/ChangeLog b/ChangeLog
+index bf428a5..f8ad579 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,9 @@
++Tue Dec 28 15:36:41 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
++	* configure.ac include/tds_sysdep_private.h:
++	* m4/sprintf_i64_format.m4 src/odbc/odbc.c src/tds/convert.c:
++	* src/tds/numeric.c src/tds/token.c:
++	- use C99 constant for printf format string
++
+ Thu Dec 23 10:32:02 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
+ 	* src/dblib/buffering.h src/dblib/dblib.c: dblib indicator is DBINT
+ 
+@@ -3070,4 +3076,4 @@ Wed Jan  9 19:54:43 EST 2008	JK Lowden <jklowden@freetds.org>
+ 	* ChangeLog-0.82 added because of release
+ 	
+ $FreeTDS$
+-$Id: ChangeLog,v 1.3173 2010/12/23 09:32:27 freddy77 Exp $
++$Id: ChangeLog,v 1.3174 2010/12/28 14:37:10 freddy77 Exp $
+diff --git a/configure.ac b/configure.ac
+index 1898af9..3d6b95b 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -1,7 +1,7 @@
+ dnl Process this file with autoconf to produce a configure script.
+ 
+ dnl ------------------------------------------------------------
+-dnl $Id: configure.ac,v 1.59 2010/11/16 13:25:15 freddy77 Exp $
++dnl $Id: configure.ac,v 1.60 2010/12/28 14:37:10 freddy77 Exp $
+ dnl If you're trying to create a new configure test, try
+ dnl
+ dnl 	http://autogen.sourceforge.net/conftest.html
+@@ -15,7 +15,7 @@ dnl ------------------------------------------------------------
+ AC_INIT(FreeTDS, 0.83.dev.esyscmd(printf $(date +"%Y%m%d")))
+ AC_CONFIG_SRCDIR(src/dblib/dblib.c)
+ AC_PREREQ(2.53)
+-AC_REVISION($Revision: 1.59 $)
++AC_REVISION($Revision: 1.60 $)
+ 
+ AM_INIT_AUTOMAKE([dist-bzip2])
+ AC_CONFIG_HEADERS(include/config.h)
+@@ -91,6 +91,7 @@ define([AC_LIBTOOL_LANG_GCJ_CONFIG], [:])dnl
+ 
+ AC_LIBTOOL_WIN32_DLL
+ AC_PROG_LIBTOOL
++AC_LTDL_DLLIB
+ LT_AC_PROG_RC
+ 
+ AC_ARG_ENABLE(libiconv,
+@@ -285,7 +286,8 @@ AC_CHECK_HEADERS([	errno.h \
+ 			sys/resource.h \
+ 			sys/wait.h \
+ 			unistd.h \
+-			wchar.h ])
++			wchar.h \
++			inttypes.h])
+ if test $tds_mingw = no; then
+     AC_CHECK_HEADERS([	arpa/inet.h \
+ 			langinfo.h \
+diff --git a/include/tds_sysdep_private.h b/include/tds_sysdep_private.h
+index 0bea2e5..cdc7c0e 100644
+--- a/include/tds_sysdep_private.h
++++ b/include/tds_sysdep_private.h
+@@ -21,7 +21,7 @@
+ #ifndef _tds_sysdep_private_h_
+ #define _tds_sysdep_private_h_
+ 
+-/* $Id: tds_sysdep_private.h,v 1.35 2010/07/25 08:40:19 freddy77 Exp $ */
++/* $Id: tds_sysdep_private.h,v 1.36 2010/12/28 14:37:10 freddy77 Exp $ */
+ 
+ #undef TDS_RCSID
+ #if defined(__GNUC__) && __GNUC__ >= 3
+@@ -235,6 +235,14 @@ typedef SOCKET TDS_SYS_SOCKET;
+ #define TDS_SDIR_SEPARATOR "/"
+ #endif /* !TDS_SDIR_SEPARATOR */
+ 
++#ifdef HAVE_INTTYPES_H
++#include <inttypes.h>
++#endif
++
++#ifndef PRId64
++#define PRId64 TDS_I64_FORMAT
++#endif
++
+ #ifdef __cplusplus
+ #if 0
+ {
+diff --git a/m4/sprintf_i64_format.m4 b/m4/sprintf_i64_format.m4
+index 14108af..b3ab926 100644
+--- a/m4/sprintf_i64_format.m4
++++ b/m4/sprintf_i64_format.m4
+@@ -1,4 +1,4 @@
+-dnl $Id: sprintf_i64_format.m4,v 1.10 2010/12/03 16:01:12 freddy77 Exp $
++dnl $Id: sprintf_i64_format.m4,v 1.11 2010/12/28 14:37:10 freddy77 Exp $
+ ##
+ # Test for 64bit integer sprintf format specifier
+ # ld   64 bit machine
+@@ -9,16 +9,19 @@ dnl $Id: sprintf_i64_format.m4,v 1.10 2010/12/03 16:01:12 freddy77 Exp $
+ AC_DEFUN([SPRINTF_I64_FORMAT],
+ [tds_i64_format=
+ 
++# Win32 case
+ AC_COMPILE_IFELSE(AC_LANG_PROGRAM([
+ #if !defined(__MINGW32__) || !defined(__MSVCRT__)
+ this should produce an error!
+ #endif
+ ],[return 0;]),[tds_i64_format="I64d"])
+ 
++# long is 64 bit
+ if test "x$ac_cv_sizeof_long" = "x8"; then
+ 	tds_i64_format=ld
+ fi
+ 
++# long long support
+ if test "x$tds_i64_format" = "x"; then
+ 	AC_LINK_IFELSE([AC_LANG_SOURCE([[
+ #include <stdlib.h>
+@@ -38,6 +41,21 @@ return 0;
+ ]])],[tds_i64_format="lld"])
+ fi
+ 
++# extract from inttypes.h
++if test "x$tds_i64_format" = "x"; then
++	AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
++[[#include <stdio.h>
++#include <inttypes.h>
++char test_fmt[] = "Start PRId64:" PRId64 ":End PRId64";
++]],
++[[]])],
++[for arg in l ll I64 L; do
++	if grep "Start PRId64:${arg}d:End PRId64" conftest.$ac_objext >/dev/null ; then
++        	tds_i64_format=$arg
++	fi
++done])
++fi
++
+ if test "x$tds_i64_format" = "x"; then
+ 	for arg in l ll I64 L; do
+ 		AC_RUN_IFELSE([AC_LANG_SOURCE([[
+diff --git a/src/odbc/odbc.c b/src/odbc/odbc.c
+index 58fbee4..0e57775 100644
+--- a/src/odbc/odbc.c
++++ b/src/odbc/odbc.c
+@@ -61,7 +61,7 @@
+ #include <dmalloc.h>
+ #endif
+ 
+-TDS_RCSID(var, "$Id: odbc.c,v 1.554 2010/11/26 19:05:30 freddy77 Exp $");
++TDS_RCSID(var, "$Id: odbc.c,v 1.555 2010/12/28 14:37:10 freddy77 Exp $");
+ 
+ static SQLRETURN _SQLAllocConnect(SQLHENV henv, SQLHDBC FAR * phdbc);
+ static SQLRETURN _SQLAllocEnv(SQLHENV FAR * phenv, SQLINTEGER odbc_version);
+@@ -819,7 +819,7 @@ SQLMoreResults(SQLHSTMT hstmt)
+ 		token_flags |= TDS_RETURN_MSG;
+ 	for (;;) {
+ 		result_type = odbc_process_tokens(stmt, token_flags);
+-		tdsdump_log(TDS_DBG_INFO1, "SQLMoreResults: result_type=%d, row_count=%" TDS_I64_FORMAT ", lastrc=%d\n", 
++		tdsdump_log(TDS_DBG_INFO1, "SQLMoreResults: result_type=%d, row_count=%" PRId64 ", lastrc=%d\n",
+ 						result_type, stmt->row_count, stmt->errs.lastrc);
+ 		switch (result_type) {
+ 		case TDS_CMD_DONE:
+@@ -833,7 +833,7 @@ SQLMoreResults(SQLHSTMT hstmt)
+ 				stmt->row_status = NOT_IN_ROW;
+ 				tdsdump_log(TDS_DBG_INFO1, "SQLMoreResults: row_status=%d\n", stmt->row_status);
+ 			}
+-			tdsdump_log(TDS_DBG_INFO1, "SQLMoreResults: row_count=%" TDS_I64_FORMAT ", lastrc=%d\n", stmt->row_count, stmt->errs.lastrc);
++			tdsdump_log(TDS_DBG_INFO1, "SQLMoreResults: row_count=%" PRId64 ", lastrc=%d\n", stmt->row_count, stmt->errs.lastrc);
+ 			if (stmt->row_count == TDS_NO_COUNT) {
+ 				if (stmt->errs.lastrc == SQL_SUCCESS || stmt->errs.lastrc == SQL_SUCCESS_WITH_INFO)
+ 					ODBC_RETURN(stmt, SQL_NO_DATA);
+@@ -3573,7 +3573,7 @@ odbc_process_tokens(TDS_STMT * stmt, unsigned flag)
+ 				tds_free_all_results(tds);
+ 				odbc_populate_ird(stmt);
+ #endif
+-				tdsdump_log(TDS_DBG_FUNC, "odbc_process_tokens: row_count=%" TDS_I64_FORMAT "\n", stmt->row_count);
++				tdsdump_log(TDS_DBG_FUNC, "odbc_process_tokens: row_count=%" PRId64 "\n", stmt->row_count);
+ 				return result_type;
+ 			}
+ 			tdsdump_log(TDS_DBG_FUNC, "odbc_process_tokens: processed %s\n", 
+diff --git a/src/tds/convert.c b/src/tds/convert.c
+index 02ab940..9108ac8 100644
+--- a/src/tds/convert.c
++++ b/src/tds/convert.c
+@@ -1,5 +1,6 @@
+ /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
+  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005  Brian Bruns
++ * Copyright (C) 2010  Frediano Ziglio
+  *
+  * This library is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU Library General Public
+@@ -64,7 +65,7 @@
+ #include <dmalloc.h>
+ #endif
+ 
+-TDS_RCSID(var, "$Id: convert.c,v 1.195 2010/01/10 14:43:12 freddy77 Exp $");
++TDS_RCSID(var, "$Id: convert.c,v 1.196 2010/12/28 14:37:10 freddy77 Exp $");
+ 
+ typedef unsigned short utf16_t;
+ 
+@@ -861,14 +862,7 @@ tds_convert_int8(int srctype, const TDS_CHAR * src, int desttype, CONV_RESULT *
+ 	switch (desttype) {
+ 	case TDS_CONVERT_CHAR:
+ 	case CASE_ALL_CHAR:
+-		/* TODO: fix for all platform. Search for lltoa/_i64toa */
+-#if defined(_WIN32)
+-		_i64toa(buf, tmp_str, 10);
+-#elif SIZEOF_LONG < 8
+-		sprintf(tmp_str, "%" TDS_I64_FORMAT, buf);
+-#else
+-		sprintf(tmp_str, "%ld", buf);
+-#endif
++		sprintf(tmp_str, "%" PRId64, buf);
+ 		return string_to_result(tmp_str, cr);
+ 		break;
+ 	case CASE_ALL_BINARY:
+@@ -923,14 +917,7 @@ tds_convert_int8(int srctype, const TDS_CHAR * src, int desttype, CONV_RESULT *
+ 		break;
+ 	case SYBNUMERIC:
+ 	case SYBDECIMAL:
+-		/* TODO portability problem. See above */
+-#if defined(_WIN32)
+-		_i64toa(buf, tmp_str, 10);
+-#elif SIZEOF_LONG < 8
+-		sprintf(tmp_str, "%" TDS_I64_FORMAT, buf);
+-#else
+-		sprintf(tmp_str, "%ld", buf);
+-#endif
++		sprintf(tmp_str, "%" PRId64, buf);
+ 		return stringz_to_numeric(tmp_str, cr);
+ 		break;
+ 		/* conversions not allowed */
+diff --git a/src/tds/numeric.c b/src/tds/numeric.c
+index 5dec69e..88cfc55 100644
+--- a/src/tds/numeric.c
++++ b/src/tds/numeric.c
+@@ -1,6 +1,6 @@
+ /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
+  * Copyright (C) 1998-1999  Brian Bruns
+- * Copyright (C) 2005-2008  Frediano Ziglio
++ * Copyright (C) 2005-2010  Frediano Ziglio
+  *
+  * This library is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU Library General Public
+@@ -37,7 +37,7 @@
+ #include <dmalloc.h>
+ #endif
+ 
+-TDS_RCSID(var, "$Id: numeric.c,v 1.46 2010/01/08 22:08:01 jklowden Exp $");
++TDS_RCSID(var, "$Id: numeric.c,v 1.47 2010/12/28 14:37:10 freddy77 Exp $");
+ 
+ /* 
+  * these routines use arrays of unsigned char to handle arbitrary
+@@ -116,16 +116,7 @@ tds_money_to_string(const TDS_MONEY * money, char *s)
+ 	frac = (int) (n % 100);
+ 	n /= 100;
+ 	/* if machine is 64 bit you do not need to split n */
+-#if defined(TDS_I64_FORMAT)
+-	sprintf(p, "%" TDS_I64_FORMAT ".%02d", n, frac);
+-#elif SIZEOF_LONG < 8
+-	if (n >= 1000000000) {
+-		sprintf(p, "%ld%09ld.%02d", (long)(n / 1000000000), (long)(n % 1000000000), frac);
+-	} else
+-		sprintf(p, "%ld.%02d", (long)n, frac);
+-#else
+-	sprintf(p, "%ld.%02d", (long)n, frac);
+-#endif
++	sprintf(p, "%" PRId64 ".%02d", n, frac);
+ 	return s;
+ #else
+ 	unsigned char multiplier[MAXPRECISION], temp[MAXPRECISION];
+diff --git a/src/tds/token.c b/src/tds/token.c
+index 8c04a58..9cddca9 100644
+--- a/src/tds/token.c
++++ b/src/tds/token.c
+@@ -43,7 +43,7 @@
+ #include <dmalloc.h>
+ #endif
+ 
+-TDS_RCSID(var, "$Id: token.c,v 1.393 2010/12/06 15:24:28 freddy77 Exp $");
++TDS_RCSID(var, "$Id: token.c,v 1.394 2010/12/28 14:37:10 freddy77 Exp $");
+ 
+ #define USE_ICONV tds->use_iconv
+ 
+@@ -2501,7 +2501,7 @@ tds_process_end(TDSSOCKET * tds, int marker, int *flags_parm)
+ 	 */
+ 
+ 	rows_affected = IS_TDS72_PLUS(tds) ? tds_get_int8(tds) : tds_get_int(tds);
+-	tdsdump_log(TDS_DBG_FUNC, "                rows_affected = %" TDS_I64_FORMAT "\n", rows_affected);
++	tdsdump_log(TDS_DBG_FUNC, "                rows_affected = %" PRId64 "\n", rows_affected);
+ 	if (done_count_valid)
+ 		tds->rows_affected = rows_affected;
+ 	else
+
+commit b964f4fef9ae846a6d780e7109265ef91c1e7767
+Author: freddy77 <freddy77>
+Date:   Thu Dec 30 12:04:52 2010 +0000
+
+    move to_utf8 function to new utf8.c file
+
+diff --git a/ChangeLog b/ChangeLog
+index f8ad579..db2fe7a 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,9 @@
++Thu Dec 30 13:04:41 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
++	* src/tds/unittests/Makefile.am src/tds/unittests/common.h:
++	- src/tds/unittests/utf8.c
++	* src/tds/unittests/utf8_1.c src/tds/unittests/utf8_3.c:
++	- move to_utf8 function to new utf8.c file
++
+ Tue Dec 28 15:36:41 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
+ 	* configure.ac include/tds_sysdep_private.h:
+ 	* m4/sprintf_i64_format.m4 src/odbc/odbc.c src/tds/convert.c:
+@@ -3076,4 +3082,4 @@ Wed Jan  9 19:54:43 EST 2008	JK Lowden <jklowden@freetds.org>
+ 	* ChangeLog-0.82 added because of release
+ 	
+ $FreeTDS$
+-$Id: ChangeLog,v 1.3174 2010/12/28 14:37:10 freddy77 Exp $
++$Id: ChangeLog,v 1.3175 2010/12/30 12:04:52 freddy77 Exp $
+diff --git a/src/tds/unittests/Makefile.am b/src/tds/unittests/Makefile.am
+index 60f8a06..4b90e62 100644
+--- a/src/tds/unittests/Makefile.am
++++ b/src/tds/unittests/Makefile.am
+@@ -1,4 +1,4 @@
+-# $Id: Makefile.am,v 1.27 2010/07/31 08:05:59 freddy77 Exp $
++# $Id: Makefile.am,v 1.28 2010/12/30 12:04:52 freddy77 Exp $
+ TESTS		=	t0001$(EXEEXT) t0002$(EXEEXT) t0003$(EXEEXT)\
+ 			t0004$(EXEEXT) t0005$(EXEEXT) t0006$(EXEEXT)\
+ 			t0007$(EXEEXT) t0008$(EXEEXT) dynamic1$(EXEEXT)\
+@@ -23,9 +23,9 @@ dynamic1_SOURCES =	dynamic1.c common.c common.h
+ convert_SOURCES	=	convert.c
+ dataread_SOURCES	=	dataread.c common.c common.h
+ # flags_SOURCES	=	flags.c common.c common.h
+-utf8_1_SOURCES	=	utf8_1.c common.c common.h
++utf8_1_SOURCES	=	utf8_1.c common.c common.h utf8.c
+ utf8_2_SOURCES	=	utf8_2.c common.c common.h
+-utf8_3_SOURCES	=	utf8_3.c common.c common.h
++utf8_3_SOURCES	=	utf8_3.c common.c common.h utf8.c
+ numeric_SOURCES =       numeric.c
+ iconv_fread_SOURCES	= iconv_fread.c
+ toodynamic_SOURCES	= toodynamic.c common.c common.h
+diff --git a/src/tds/unittests/common.h b/src/tds/unittests/common.h
+index ad4ebda..8379418 100644
+--- a/src/tds/unittests/common.h
++++ b/src/tds/unittests/common.h
+@@ -1,7 +1,7 @@
+ #ifndef COMMON_h
+ #define COMMON_h
+ 
+-static char rcsid_common_h[] = "$Id: common.h,v 1.8 2006/12/26 14:56:21 freddy77 Exp $";
++static char rcsid_common_h[] = "$Id: common.h,v 1.9 2010/12/30 12:04:52 freddy77 Exp $";
+ static void *no_unused_common_h_warn[] = { rcsid_common_h, no_unused_common_h_warn };
+ 
+ #if HAVE_CONFIG_H
+@@ -34,4 +34,9 @@ int try_tds_logout(TDSLOGIN * login, TDSSOCKET * tds, int verbose);
+ 
+ int run_query(TDSSOCKET * tds, const char *query);
+ 
++extern int utf8_max_len;
++
++int get_unichar(const char **psrc);
++char *to_utf8(const char *src, char *dest);
++
+ #endif
+diff --git a/src/tds/unittests/utf8_1.c b/src/tds/unittests/utf8_1.c
+index d8c2340..821d1a2 100644
+--- a/src/tds/unittests/utf8_1.c
++++ b/src/tds/unittests/utf8_1.c
+@@ -1,5 +1,6 @@
+ /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
+  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004  Brian Bruns
++ * Copyright (C) 2010 Frediano Ziglio
+  *
+  * This library is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU Library General Public
+@@ -21,7 +22,7 @@
+ #include <ctype.h>
+ #include <assert.h>
+ 
+-static char software_version[] = "$Id: utf8_1.c,v 1.13 2009/05/28 16:23:32 freddy77 Exp $";
++static char software_version[] = "$Id: utf8_1.c,v 1.14 2010/12/30 12:04:52 freddy77 Exp $";
+ static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
+ 
+ static TDSSOCKET *tds;
+@@ -54,53 +55,6 @@ static const char *strings[] = {
+ 	NULL
+ };
+ 
+-static int max_len = 0;
+-
+-static char *
+-to_utf8(const char *src, char *dest)
+-{
+-	unsigned char *p = (unsigned char *) dest;
+-	int len = 0;
+-
+-	for (; *src;) {
+-		if (src[0] == '&' && src[1] == '#') {
+-			const char *end = strchr(src, ';');
+-			char tmp[16];
+-			int radix = 10;
+-			int n;
+-
+-			assert(end);
+-			src += 2;
+-			if (toupper(*src) == 'X') {
+-				radix = 16;
+-				++src;
+-			}
+-			memcpy(tmp, src, end - src);
+-			tmp[end - src] = 0;
+-			n = strtol(tmp, NULL, radix);
+-			assert(n > 0 && n < 0x10000);
+-			if (n >= 0x1000) {
+-				*p++ = 0xe0 | (n >> 12);
+-				*p++ = 0x80 | ((n >> 6) & 0x3f);
+-				*p++ = 0x80 | (n & 0x3f);
+-			} else if (n >= 0x80) {
+-				*p++ = 0xc0 | (n >> 6);
+-				*p++ = 0x80 | (n & 0x3f);
+-			} else {
+-				*p++ = (unsigned char) n;
+-			}
+-			src = end + 1;
+-		} else {
+-			*p++ = *src++;
+-		}
+-		++len;
+-	}
+-	if (len > max_len)
+-		max_len = len;
+-	*p = 0;
+-	return dest;
+-}
+-
+ static void
+ query(const char *sql)
+ {
+@@ -262,7 +216,7 @@ main(int argc, char **argv)
+ 
+ 		test("NVARCHAR(500)", "NVARCHAR with large size");
+ 
+-		sprintf(type, "NVARCHAR(%d)", max_len);
++		sprintf(type, "NVARCHAR(%d)", utf8_max_len);
+ 		test(type, "NVARCHAR with sufficient size");
+ 
+ 		test("NTEXT", "TEXT");
+diff --git a/src/tds/unittests/utf8_3.c b/src/tds/unittests/utf8_3.c
+index b67259f..5c8d37e 100644
+--- a/src/tds/unittests/utf8_3.c
++++ b/src/tds/unittests/utf8_3.c
+@@ -1,5 +1,6 @@
+ /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
+  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005  Brian Bruns
++ * Copyright (C) 2010 Frediano Ziglio
+  *
+  * This library is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU Library General Public
+@@ -21,58 +22,11 @@
+ #include <ctype.h>
+ #include <assert.h>
+ 
+-static char software_version[] = "$Id: utf8_3.c,v 1.6 2005/04/14 11:35:47 freddy77 Exp $";
++static char software_version[] = "$Id: utf8_3.c,v 1.7 2010/12/30 12:04:52 freddy77 Exp $";
+ static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
+ 
+ static TDSSOCKET *tds;
+ 
+-static int max_len = 0;
+-
+-static char *
+-to_utf8(const char *src, char *dest)
+-{
+-	unsigned char *p = (unsigned char *) dest;
+-	int len = 0;
+-
+-	for (; *src;) {
+-		if (src[0] == '&' && src[1] == '#') {
+-			const char *end = strchr(src, ';');
+-			char tmp[16];
+-			int radix = 10;
+-			int n;
+-
+-			assert(end);
+-			src += 2;
+-			if (toupper(*src) == 'X') {
+-				radix = 16;
+-				++src;
+-			}
+-			memcpy(tmp, src, end - src);
+-			tmp[end - src] = 0;
+-			n = strtol(tmp, NULL, radix);
+-			assert(n > 0 && n < 0x10000);
+-			if (n >= 0x1000) {
+-				*p++ = 0xe0 | (n >> 12);
+-				*p++ = 0x80 | ((n >> 6) & 0x3f);
+-				*p++ = 0x80 | (n & 0x3f);
+-			} else if (n >= 0x80) {
+-				*p++ = 0xc0 | (n >> 6);
+-				*p++ = 0x80 | (n & 0x3f);
+-			} else {
+-				*p++ = (unsigned char) n;
+-			}
+-			src = end + 1;
+-		} else {
+-			*p++ = *src++;
+-		}
+-		++len;
+-	}
+-	if (len > max_len)
+-		max_len = len;
+-	*p = 0;
+-	return dest;
+-}
+-
+ static void
+ test(const char *buf)
+ {
+
+commit c11dfc570b1905c7e598a4e71b6afbca6a116f20
+Author: freddy77 <freddy77>
+Date:   Thu Dec 30 12:12:47 2010 +0000
+
+    missing file added
+
+diff --git a/ChangeLog b/ChangeLog
+index db2fe7a..e568103 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,7 +1,7 @@
+ Thu Dec 30 13:04:41 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
+ 	* src/tds/unittests/Makefile.am src/tds/unittests/common.h:
+-	- src/tds/unittests/utf8.c
+ 	* src/tds/unittests/utf8_1.c src/tds/unittests/utf8_3.c:
++	* src/tds/unittests/utf8.c(added):
+ 	- move to_utf8 function to new utf8.c file
+ 
+ Tue Dec 28 15:36:41 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
+@@ -3082,4 +3082,4 @@ Wed Jan  9 19:54:43 EST 2008	JK Lowden <jklowden@freetds.org>
+ 	* ChangeLog-0.82 added because of release
+ 	
+ $FreeTDS$
+-$Id: ChangeLog,v 1.3175 2010/12/30 12:04:52 freddy77 Exp $
++$Id: ChangeLog,v 1.3176 2010/12/30 12:12:47 freddy77 Exp $
+diff --git a/src/tds/unittests/utf8.c b/src/tds/unittests/utf8.c
+new file mode 100644
+index 0000000..136646f
+--- /dev/null
++++ b/src/tds/unittests/utf8.c
+@@ -0,0 +1,77 @@
++/* FreeTDS - Library of routines accessing Sybase and Microsoft databases
++ * Copyright (C) 2010 Frediano Ziglio
++ *
++ * This library is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU Library General Public
++ * License as published by the Free Software Foundation; either
++ * version 2 of the License, or (at your option) any later version.
++ *
++ * This library is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++ * Library General Public License for more details.
++ *
++ * You should have received a copy of the GNU Library General Public
++ * License along with this library; if not, write to the
++ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
++ * Boston, MA 02111-1307, USA.
++ */
++#undef NDEBUG
++#include "common.h"
++
++#include <ctype.h>
++#include <assert.h>
++
++int utf8_max_len = 0;
++
++int
++get_unichar(const char **psrc)
++{
++	const char *src = *psrc;
++	int n;
++
++	if (!*src) return -1;
++
++	if (src[0] == '&' && src[1] == '#') {
++		char *end;
++		int radix = 10;
++
++		if (toupper(src[2]) == 'X') {
++			radix = 16;
++			++src;
++		}
++		n = strtol(src+2, &end, radix);
++		assert(*end == ';' && n > 0 && n < 0x10000);
++		src = end + 1;
++	} else {
++		n = (unsigned char) *src++;
++	}
++	*psrc = src;
++	return n;
++}
++
++char *
++to_utf8(const char *src, char *dest)
++{
++	unsigned char *p = (unsigned char *) dest;
++	int len = 0, n;
++
++	while ((n=get_unichar(&src)) > 0) {
++		if (n >= 0x2000) {
++			*p++ = 0xe0 | (n >> 12);
++			*p++ = 0x80 | ((n >> 6) & 0x3f);
++			*p++ = 0x80 | (n & 0x3f);
++		} else if (n >= 0x80) {
++			*p++ = 0xc0 | (n >> 6);
++			*p++ = 0x80 | (n & 0x3f);
++		} else {
++			*p++ = (unsigned char) n;
++		}
++		++len;
++	}
++	if (len > utf8_max_len)
++		utf8_max_len = len;
++	*p = 0;
++	return dest;
++}
++
+
+commit 27a8b242f7cfc751a362f072c18d57f779d0c157
+Author: freddy77 <freddy77>
+Date:   Thu Dec 30 12:39:11 2010 +0000
+
+    silly warnings
+
+diff --git a/misc/bounce.c b/misc/bounce.c
+index 93e9c5c..744bec6 100644
+--- a/misc/bounce.c
++++ b/misc/bounce.c
+@@ -9,7 +9,7 @@
+ #include <unistd.h>
+ #include <gnutls/gnutls.h>
+ 
+-/* $Id: bounce.c,v 1.1 2007/10/23 10:08:52 freddy77 Exp $ */
++/* $Id: bounce.c,v 1.2 2010/12/30 12:39:11 freddy77 Exp $ */
+ 
+ /* This small application make man-in-the-middle with a crypted SQL Server
+  * to be able to see decrypted login
+@@ -86,7 +86,7 @@ tds_pull_func(gnutls_transport_ptr ptr, void *data, size_t len)
+ 		len = packet_len - pos;
+ 	memcpy(data, packet + pos, len);
+ 	pos += len;
+-	printf("read %d bytes\n", len);
++	printf("read %d bytes\n", (int) len);
+ 	return len;
+ }
+ 
+@@ -268,7 +268,7 @@ main()
+ 	int sd, ret;
+ 	struct sockaddr_in sa_serv;
+ 	struct sockaddr_in sa_cli;
+-	int client_len;
++	socklen_t client_len;
+ 	char topbuf[512];
+ 	gnutls_session_t session;
+ 	char buffer[MAX_BUF + 1];
+@@ -348,7 +348,7 @@ main()
+ 		packet_len = 0;
+ 
+ 		/* do with client */
+-		gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t) sd);
++		gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t) (((char*)0)+sd));
+ 		ret = gnutls_handshake(session);
+ 		if (ret < 0) {
+ 			close(sd);
+
+commit c80e1b1ddf8c1dab4321eb348040ce3a098a9ef3
+Author: freddy77 <freddy77>
+Date:   Thu Dec 30 12:41:51 2010 +0000
+
+    test Sybase DATE and TIME
+
+diff --git a/ChangeLog b/ChangeLog
+index e568103..d36205c 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,6 @@
++Thu Dec 30 13:41:44 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
++	* src/odbc/unittests/data.c: test Sybase DATE and TIME
++
+ Thu Dec 30 13:04:41 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
+ 	* src/tds/unittests/Makefile.am src/tds/unittests/common.h:
+ 	* src/tds/unittests/utf8_1.c src/tds/unittests/utf8_3.c:
+@@ -3082,4 +3085,4 @@ Wed Jan  9 19:54:43 EST 2008	JK Lowden <jklowden@freetds.org>
+ 	* ChangeLog-0.82 added because of release
+ 	
+ $FreeTDS$
+-$Id: ChangeLog,v 1.3176 2010/12/30 12:12:47 freddy77 Exp $
++$Id: ChangeLog,v 1.3177 2010/12/30 12:41:51 freddy77 Exp $
+diff --git a/src/odbc/unittests/data.c b/src/odbc/unittests/data.c
+index 6f83522..86defc3 100644
+--- a/src/odbc/unittests/data.c
++++ b/src/odbc/unittests/data.c
+@@ -13,7 +13,7 @@
+  * Also we have to check normal char and wide char
+  */
+ 
+-static char software_version[] = "$Id: data.c,v 1.34 2010/12/06 15:24:28 freddy77 Exp $";
++static char software_version[] = "$Id: data.c,v 1.35 2010/12/30 12:41:51 freddy77 Exp $";
+ static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
+ 
+ static int result = 0;
+@@ -220,6 +220,12 @@ main(int argc, char *argv[])
+ 		odbc_command("DROP XML SCHEMA COLLECTION test_schema");
+ 	}
+ 
++	if (!odbc_db_is_microsoft() && strncmp(odbc_db_version(), "15.00.", 6) >= 0) {
++		/* FIXME sure ?? with date and time always ?? */
++		Test("DATE", "1923-12-02", SQL_C_CHAR, "23 1923-12-02 00:00:00.000");
++		Test("TIME", "12:23:45", SQL_C_CHAR, "23 1900-01-01 12:23:45.000");
++	}
++
+ 	odbc_disconnect();
+ 
+ 	if (!result)
+
+commit 3ed4e921f52bf9bce55a6cc4a95cb64f840a4ce9
+Author: freddy77 <freddy77>
+Date:   Thu Dec 30 13:06:31 2010 +0000
+
+    check WVARCHAR result and no pending data
+
+diff --git a/ChangeLog b/ChangeLog
+index d36205c..54ebb43 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,7 @@
++Thu Dec 30 14:06:25 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
++	* src/odbc/unittests/typeinfo.c:
++	- check WVARCHAR result and no pending data
++
+ Thu Dec 30 13:41:44 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
+ 	* src/odbc/unittests/data.c: test Sybase DATE and TIME
+ 
+@@ -3085,4 +3089,4 @@ Wed Jan  9 19:54:43 EST 2008	JK Lowden <jklowden@freetds.org>
+ 	* ChangeLog-0.82 added because of release
+ 	
+ $FreeTDS$
+-$Id: ChangeLog,v 1.3177 2010/12/30 12:41:51 freddy77 Exp $
++$Id: ChangeLog,v 1.3178 2010/12/30 13:06:31 freddy77 Exp $
+diff --git a/src/odbc/unittests/typeinfo.c b/src/odbc/unittests/typeinfo.c
+index 223cb7e..9c06965 100644
+--- a/src/odbc/unittests/typeinfo.c
++++ b/src/odbc/unittests/typeinfo.c
+@@ -1,6 +1,6 @@
+ #include "common.h"
+ 
+-static char software_version[] = "$Id: typeinfo.c,v 1.14 2010/07/05 09:20:33 freddy77 Exp $";
++static char software_version[] = "$Id: typeinfo.c,v 1.15 2010/12/30 13:06:31 freddy77 Exp $";
+ static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
+ 
+ static void
+@@ -169,6 +169,16 @@ DoTest(int version3)
+ 	SQLFreeStmt(odbc_stmt, SQL_UNBIND);
+ 	Flushodbc_stmt();
+ 
++	/* check WVARCHAR for no pending data */
++	if (odbc_db_is_microsoft() || strncmp(odbc_db_version(), "15.00.", 6) >= 0) {
++		CHKGetTypeInfo(SQL_WVARCHAR, "SI");
++		CHKFetch("S");
++		if (odbc_db_is_microsoft())
++			CHKFetch("S");
++		CHKFetch("No");
++		CHKGetTypeInfo(SQL_BINARY, "SI");
++	}
++
+ 	odbc_disconnect();
+ }
+ 
+
+commit 310e094e1036288017344821a4f25eb75e315c68
+Author: freddy77 <freddy77>
+Date:   Thu Dec 30 14:53:12 2010 +0000
+
+    correct t0007 test (still broken), fix DBVARYCHAR declaration
+
+diff --git a/ChangeLog b/ChangeLog
+index 54ebb43..f13a105 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,7 @@
++Thu Dec 30 15:53:06 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
++	* include/sybdb.h src/dblib/unittests/t0007.c:
++	- correct t0007 test (still broken), fix DBVARYCHAR declaration
++
+ Thu Dec 30 14:06:25 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
+ 	* src/odbc/unittests/typeinfo.c:
+ 	- check WVARCHAR result and no pending data
+@@ -3089,4 +3093,4 @@ Wed Jan  9 19:54:43 EST 2008	JK Lowden <jklowden@freetds.org>
+ 	* ChangeLog-0.82 added because of release
+ 	
+ $FreeTDS$
+-$Id: ChangeLog,v 1.3178 2010/12/30 13:06:31 freddy77 Exp $
++$Id: ChangeLog,v 1.3179 2010/12/30 14:53:12 freddy77 Exp $
+diff --git a/include/sybdb.h b/include/sybdb.h
+index 0d34102..6c6ab2b 100644
+--- a/include/sybdb.h
++++ b/include/sybdb.h
+@@ -1,5 +1,6 @@
+ /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
+  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004  Brian Bruns
++ * Copyright (C) 2010  Frediano Ziglio
+  *
+  * This library is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU Library General Public
+@@ -41,7 +42,7 @@ extern "C"
+ #define TDS_STATIC_CAST(type, a) ((type)(a))
+ #endif
+ 
+-static const char rcsid_sybdb_h[] = "$Id: sybdb.h,v 1.96 2010/12/10 20:46:19 jklowden Exp $";
++static const char rcsid_sybdb_h[] = "$Id: sybdb.h,v 1.97 2010/12/30 14:53:12 freddy77 Exp $";
+ static const void *const no_unused_sybdb_h_warn[] = { rcsid_sybdb_h, no_unused_sybdb_h_warn };
+ 
+ #ifdef FALSE
+@@ -234,10 +235,16 @@ typedef unsigned tds_sysdep_int16_type DBUSMALLINT;
+ 
+ typedef struct 
+ {
+-	DBINT len;
+-    char  str[256];
++	DBSMALLINT len;
++	char  str[256];
+ } DBVARYCHAR;
+-   
++
++typedef struct
++{
++	DBSMALLINT len;
++	unsigned char  array[256];
++} DBVARYBIN;
++
+ typedef struct
+ {
+ 	unsigned char precision;
+diff --git a/src/dblib/unittests/t0007.c b/src/dblib/unittests/t0007.c
+index e2cdb07..d71d3cc 100644
+--- a/src/dblib/unittests/t0007.c
++++ b/src/dblib/unittests/t0007.c
+@@ -5,7 +5,7 @@
+ 
+ #include "common.h"
+ 
+-static char software_version[] = "$Id: t0007.c,v 1.21 2010/09/15 03:55:44 jklowden Exp $";
++static char software_version[] = "$Id: t0007.c,v 1.22 2010/12/30 14:53:12 freddy77 Exp $";
+ static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
+ 
+ static void
+@@ -66,6 +66,8 @@ main(int argc, char **argv)
+ 	int i;
+ 	char teststr[1024];
+ 	DBINT testint;
++	DBVARYBIN  testvbin;
++	DBVARYCHAR testvstr;
+ 	int failed = 0;
+ 	int expected_error;
+ 
+@@ -170,30 +172,36 @@ main(int argc, char **argv)
+ 		failed = 1;
+ 	}
+ 
+- 	dbbind(dbproc, 1, VARYBINBIND, sizeof(testint), (BYTE *) &testint);
+-	dbbind(dbproc, 2, BINARYBIND, sizeof(teststr), (BYTE *) teststr);
++	dbbind(dbproc, 1, VARYBINBIND, sizeof(testvbin), (BYTE *) &testvbin);
++	dbbind(dbproc, 2, VARYCHARBIND, sizeof(testvstr), (BYTE *) &testvstr);
+ 
+ 	for (i = 1; i <= 2; i++) {
+ 		char expected[1024];
+ 
+-		sprintf(expected, "row %07d", i);
++		sprintf(expected, "row %07d ", i);
+ 
+-		testint = -1;
+-		strcpy(teststr, "bogus");
++		memset(&testvbin, '*', sizeof(testvbin));
++		memset(&testvstr, '*', sizeof(testvstr));
+ 
+ 		if (REG_ROW != dbnextrow(dbproc)) {
+ 			fprintf(stderr, "Failed.  Expected a row\n");
+ 			abort();
+ 		}
++		if (testvbin.len != sizeof(testint)) {
++			fprintf(stderr, "Failed, line %d.  Expected bin lenght to be %d, was %d\n", __LINE__, (int) sizeof(testint), (int) testvbin.len);
++			abort();
++		}
++		testint = *((DBINT*) testvbin.array);
+ 		if (testint != i) {
+-			fprintf(stderr, "Failed, line %d.  Expected i to be %d, was %d\n", __LINE__, i, (int) testint);
++			fprintf(stderr, "Failed, line %d.  Expected i to be %d, was %d (0x%x)\n", __LINE__, i, (int) testint, (int) testint);
+ 			abort();
+ 		}
+-		if (0 != strncmp(teststr, expected, strlen(expected))) {
+-			fprintf(stdout, "Failed, line %d.  Expected s to be |%s|, was |%s|\n", __LINE__, expected, teststr);
++		if (testvstr.len != strlen(expected) || 0 != strncmp(testvstr.str, expected, strlen(expected))) {
++			fprintf(stdout, "Failed, line %d.  Expected s to be |%s|, was |%s|\n", __LINE__, expected, testvstr.str);
+ 			abort();
+ 		}
+-		printf("Read a row of data -> %d %s\n", (int) testint, teststr);
++		testvstr.str[testvstr.len] = 0;
++		printf("Read a row of data -> %d %s\n", (int) testint, testvstr.str);
+ 	}
+ 
+ 
+
+commit 653193fccb7294c62c45f27f4eb2bc1dbab0e17f
+Author: freddy77 <freddy77>
+Date:   Thu Dec 30 18:11:07 2010 +0000
+
+    improve dbmoretext tests
+
+diff --git a/ChangeLog b/ChangeLog
+index f13a105..492d615 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,8 @@
++Thu Dec 30 19:10:58 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
++	* src/dblib/unittests/common.c src/dblib/unittests/t0013.c:
++	* src/dblib/unittests/t0014.c:
++	- improve dbmoretext tests
++
+ Thu Dec 30 15:53:06 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
+ 	* include/sybdb.h src/dblib/unittests/t0007.c:
+ 	- correct t0007 test (still broken), fix DBVARYCHAR declaration
+@@ -3093,4 +3098,4 @@ Wed Jan  9 19:54:43 EST 2008	JK Lowden <jklowden@freetds.org>
+ 	* ChangeLog-0.82 added because of release
+ 	
+ $FreeTDS$
+-$Id: ChangeLog,v 1.3179 2010/12/30 14:53:12 freddy77 Exp $
++$Id: ChangeLog,v 1.3180 2010/12/30 18:11:07 freddy77 Exp $
+diff --git a/src/dblib/unittests/common.c b/src/dblib/unittests/common.c
+index a353f45..3b1bc49 100644
+--- a/src/dblib/unittests/common.c
++++ b/src/dblib/unittests/common.c
+@@ -22,7 +22,7 @@
+ 
+ #include "replacements.h"
+ 
+-static char software_version[] = "$Id: common.c,v 1.41 2010/07/24 08:08:09 freddy77 Exp $";
++static char software_version[] = "$Id: common.c,v 1.42 2010/12/30 18:11:07 freddy77 Exp $";
+ static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
+ 
+ typedef struct _tag_memcheck_t
+@@ -48,7 +48,7 @@ char PASSWORD[512];
+ char DATABASE[512];
+ 
+ static char sql_file[PATH_MAX];
+-static FILE* input_file;
++static FILE* input_file = NULL;
+ 
+ static char *ARGV0 = NULL;
+ static char *DIRNAME = NULL;
+@@ -143,7 +143,8 @@ read_login_info(int argc, char **argv)
+ 
+ 	setbuf(stdout, NULL);
+ 	setbuf(stderr, NULL);
+-	
++
++	free(ARGV0);
+ #ifdef __VMS
+ 	{
+ 		/* basename expects unix format */
+@@ -267,6 +268,8 @@ read_login_info(int argc, char **argv)
+ 	len = snprintf(sql_file, sizeof(sql_file), "%s/%s.sql", FREETDS_SRCDIR, BASENAME);
+ 	assert(len <= sizeof(sql_file));
+ 
++	if (input_file)
++		fclose(input_file);
+ 	if ((input_file = fopen(sql_file, "r")) == NULL) {
+ 		fflush(stdout);
+ 		fprintf(stderr, "could not open SQL input file \"%s\"\n", sql_file);
+diff --git a/src/dblib/unittests/t0013.c b/src/dblib/unittests/t0013.c
+index a939907..f4bda9b 100644
+--- a/src/dblib/unittests/t0013.c
++++ b/src/dblib/unittests/t0013.c
+@@ -5,7 +5,7 @@
+ 
+ #include "common.h"
+ 
+-static char software_version[] = "$Id: t0013.c,v 1.30 2009/05/11 07:53:26 freddy77 Exp $";
++static char software_version[] = "$Id: t0013.c,v 1.31 2010/12/30 18:11:07 freddy77 Exp $";
+ static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
+ 
+ #define BLOB_BLOCK_SIZE 4096
+@@ -37,8 +37,8 @@ drop_table(void)
+ 	}
+ }
+ 
+-int
+-main(int argc, char **argv)
++static int
++test(int argc, char **argv, int over4k)
+ {
+ 	LOGINREC *login;
+ 	int i;
+@@ -52,9 +52,7 @@ main(int argc, char **argv)
+ 	long numread;
+ 	BOOL readFirstImage;
+ 	int data_ok;
+-#ifdef DBWRITE_OK_FOR_OVER_4K
+ 	int numtowrite, numwritten;
+-#endif
+ 	set_malloc_options();
+ 
+ 	read_login_info(argc, argv);
+@@ -145,38 +143,38 @@ main(int argc, char **argv)
+ 	 * Use #ifndef for big buffer version (32-bit)
+ 	 */
+ 	fprintf(stdout, "writing text ... ");
+-#ifndef DBWRITE_OK_FOR_OVER_4K
+-	if (dbwritetext(dbprocw, objname, textPtr, DBTXPLEN, timeStamp, FALSE, isiz, (BYTE*) blob) != SUCCEED)
+-		return 5;
+-	fprintf(stdout, "done (in one shot)\n");
+-	for (; (result = dbnextrow(dbproc)) != NO_MORE_ROWS; i++) {
+-		assert(REG_ROW == result);
+-		printf("fetching row %d?\n", i+1);
+-	}
+-#else
+-	if (dbwritetext(dbprocw, objname, textPtr, DBTXPLEN, timeStamp, FALSE, isiz, NULL) != SUCCEED)
+-		return 15;
+-	fprintf(stdout, "done\n");
+-
+-	fprintf(stdout, "dbsqlok\n");
+-	dbsqlok(dbprocw);
+-	fprintf(stdout, "dbresults\n");
+-	dbresults(dbprocw);
+-
+-	numtowrite = 0;
+-	/* Send the update value in chunks. */
+-	for (numwritten = 0; numwritten < isiz; numwritten += numtowrite) {
+-		fprintf(stdout, "dbmoretext %d\n", 1 + numwritten);
+-		numtowrite = (isiz - numwritten);
+-		if (numtowrite > BLOB_BLOCK_SIZE)
+-			numtowrite = BLOB_BLOCK_SIZE;
+-		dbmoretext(dbprocw, (DBINT) numtowrite, blob + numwritten);
+-	}
+-	dbsqlok(dbprocw);
+-	while (dbresults(dbprocw) != NO_MORE_RESULTS){
+-		printf("suprise!\n");
++	if (over4k) {
++		if (dbwritetext(dbprocw, objname, textPtr, DBTXPLEN, timeStamp, FALSE, isiz, (BYTE*) blob) != SUCCEED)
++			return 5;
++		fprintf(stdout, "done (in one shot)\n");
++		for (; (result = dbnextrow(dbproc)) != NO_MORE_ROWS; i++) {
++			assert(REG_ROW == result);
++			printf("fetching row %d?\n", i+1);
++		}
++	} else {
++		if (dbwritetext(dbprocw, objname, textPtr, DBTXPLEN, timeStamp, FALSE, isiz, NULL) != SUCCEED)
++			return 15;
++		fprintf(stdout, "done\n");
++
++		fprintf(stdout, "dbsqlok\n");
++		dbsqlok(dbprocw);
++		fprintf(stdout, "dbresults\n");
++		dbresults(dbprocw);
++
++		numtowrite = 0;
++		/* Send the update value in chunks. */
++		for (numwritten = 0; numwritten < isiz; numwritten += numtowrite) {
++			fprintf(stdout, "dbmoretext %d\n", 1 + numwritten);
++			numtowrite = (isiz - numwritten);
++			if (numtowrite > BLOB_BLOCK_SIZE)
++				numtowrite = BLOB_BLOCK_SIZE;
++			dbmoretext(dbprocw, (DBINT) numtowrite, (BYTE *) (blob + numwritten));
++		}
++		dbsqlok(dbprocw);
++		while (dbresults(dbprocw) != NO_MORE_RESULTS){
++			printf("suprise!\n");
++		}
+ 	}
+-#endif
+ #if 0
+ 	if (SUCCEED != dbclose(dbproc)){
+ 		fprintf(stdout, "dbclose failed");
+@@ -286,6 +284,19 @@ main(int argc, char **argv)
+ 
+ 	dbexit();
+ 
++	return 0;
++}
++
++int
++main(int argc, char **argv)
++{
++	int res = test(argc, argv, 0);
++	if (!res)
++		res = test(argc, argv, 1);
++	if (res)
++		return res;
++
+ 	fprintf(stdout, "%s %s\n", __FILE__, (failed ? "failed!" : "OK"));
+ 	return failed ? 1 : 0;
+ }
++
+diff --git a/src/dblib/unittests/t0014.c b/src/dblib/unittests/t0014.c
+index 4a82e6c..bcfc060 100644
+--- a/src/dblib/unittests/t0014.c
++++ b/src/dblib/unittests/t0014.c
+@@ -5,17 +5,15 @@
+ 
+ #include "common.h"
+ 
+-static char software_version[] = "$Id: t0014.c,v 1.31 2009/02/27 15:52:48 freddy77 Exp $";
++static char software_version[] = "$Id: t0014.c,v 1.32 2010/12/30 18:11:07 freddy77 Exp $";
+ static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
+ 
+ #define BLOB_BLOCK_SIZE 4096
+ 
+-int failed = 0;
+-
+ char *testargs[] = { "", FREETDS_SRCDIR "/data.bin", "t0014.out" };
+ 
+-int
+-main(int argc, char **argv)
++static int
++test(int argc, char **argv, int over4k)
+ {
+ 	const int rows_to_add = 3;
+ 	LOGINREC *login;
+@@ -32,6 +30,7 @@ main(int argc, char **argv)
+ 	char rbuf[BLOB_BLOCK_SIZE];
+ 	long numread;
+ 	BOOL readFirstImage;
++	int numtowrite, numwritten;
+ 
+ 	set_malloc_options();
+ 
+@@ -127,28 +126,26 @@ main(int argc, char **argv)
+ 			 * Use #ifdef if you want to test dbmoretext mode (needed for 16-bit apps)
+ 			 * Use #ifndef for big buffer version (32-bit)
+ 			 */
+-#if 1
+-/* DBWRITE_OK_FOR_OVER_4K */
+-			if (dbwritetext(blobproc, objname, textPtr, DBTXPLEN, timeStamp, TRUE, isiz, (BYTE*) blob) != SUCCEED)
+-				return 5;
+-#else
+-			if (dbwritetext(blobproc, objname, textPtr, DBTXPLEN, timeStamp, TRUE, isiz, NULL) != SUCCEED)
+-				return 15;
+-			dbsqlok(blobproc);
+-			dbresults(blobproc);
+-
+-			numtowrite = 0;
+-			/* Send the update value in chunks. */
+-			for (numwritten = 0; numwritten < isiz; numwritten += numtowrite) {
+-				numtowrite = (isiz - numwritten);
+-				if (numtowrite > BLOB_BLOCK_SIZE)
+-					numtowrite = BLOB_BLOCK_SIZE;
+-				dbmoretext(blobproc, (DBINT) numtowrite, blob + numwritten);
++			if (over4k) {
++				if (dbwritetext(blobproc, objname, textPtr, DBTXPLEN, timeStamp, TRUE, isiz, (BYTE*) blob) != SUCCEED)
++					return 5;
++			} else {
++				if (dbwritetext(blobproc, objname, textPtr, DBTXPLEN, timeStamp, TRUE, isiz, NULL) != SUCCEED)
++					return 15;
++				dbsqlok(blobproc);
++				dbresults(blobproc);
++
++				numtowrite = 0;
++				/* Send the update value in chunks. */
++				for (numwritten = 0; numwritten < isiz; numwritten += numtowrite) {
++					numtowrite = (isiz - numwritten);
++					if (numtowrite > BLOB_BLOCK_SIZE)
++						numtowrite = BLOB_BLOCK_SIZE;
++					dbmoretext(blobproc, (DBINT) numtowrite, (BYTE *) (blob + numwritten));
++				}
++				dbsqlok(blobproc);
++				while (dbresults(blobproc) != NO_MORE_RESULTS);
+ 			}
+-			dbsqlok(blobproc);
+-			while (dbresults(blobproc) != NO_MORE_RESULTS);
+-
+-#endif
+ 		}
+ 	}
+ 
+@@ -158,7 +155,6 @@ main(int argc, char **argv)
+ 	dbsqlexec(dbproc);
+ 
+ 	if (dbresults(dbproc) != SUCCEED) {
+-		failed = 1;
+ 		fprintf(stdout, "Was expecting a result set.");
+ 		exit(1);
+ 	}
+@@ -168,7 +164,6 @@ main(int argc, char **argv)
+ 	}
+ 
+ 	if (SUCCEED != dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & testint)) {
+-		failed = 1;
+ 		fprintf(stderr, "Had problem with bind\n");
+ 		abort();
+ 	}
+@@ -179,12 +174,10 @@ main(int argc, char **argv)
+ 		sprintf(expected, "row %03d", i);
+ 
+ 		if (REG_ROW != dbnextrow(dbproc)) {
+-			failed = 1;
+ 			fprintf(stderr, "Failed.  Expected a row\n");
+ 			exit(1);
+ 		}
+ 		if (testint != i) {
+-			failed = 1;
+ 			fprintf(stderr, "Failed.  Expected i to be %d, was %d\n", i, (int) testint);
+ 			abort();
+ 		}
+@@ -237,7 +230,6 @@ main(int argc, char **argv)
+ 	}
+ 
+ 	if (dbnextrow(dbproc) != NO_MORE_ROWS) {
+-		failed = 1;
+ 		fprintf(stderr, "Was expecting no more rows\n");
+ 		exit(1);
+ 	}
+@@ -253,6 +245,21 @@ main(int argc, char **argv)
+ 
+ 	dbexit();
+ 
+-	fprintf(stdout, "dblib %s on %s\n", (failed ? "failed!" : "okay"), __FILE__);
+-	return failed ? 1 : 0;
++	return 0;
+ }
++
++int
++main(int argc, char **argv)
++{
++	int res;
++
++	res = test(argc, argv, 0);
++	if (!res)
++		res = test(argc, argv, 1);
++	if (res)
++		return res;
++
++	fprintf(stdout, "dblib okay on %s\n", __FILE__);
++	return 0;
++}
++
+
+commit 6541c13b15a74cd5c5beadf5b7d3ebc7ab4abf4f
+Author: freddy77 <freddy77>
+Date:   Thu Dec 30 18:18:11 2010 +0000
+
+    add small test for 64bit problems
+
+diff --git a/ChangeLog b/ChangeLog
+index 492d615..91b647c 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,7 @@
++Thu Dec 30 19:18:05 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
++	* src/odbc/unittests/Makefile.am src/odbc/unittests/test64.c:
++	- add small test for 64bit problems
++
+ Thu Dec 30 19:10:58 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
+ 	* src/dblib/unittests/common.c src/dblib/unittests/t0013.c:
+ 	* src/dblib/unittests/t0014.c:
+@@ -3098,4 +3102,4 @@ Wed Jan  9 19:54:43 EST 2008	JK Lowden <jklowden@freetds.org>
+ 	* ChangeLog-0.82 added because of release
+ 	
+ $FreeTDS$
+-$Id: ChangeLog,v 1.3180 2010/12/30 18:11:07 freddy77 Exp $
++$Id: ChangeLog,v 1.3181 2010/12/30 18:18:11 freddy77 Exp $
+diff --git a/src/odbc/unittests/Makefile.am b/src/odbc/unittests/Makefile.am
+index c4b96ba..eaad3fb 100644
+--- a/src/odbc/unittests/Makefile.am
++++ b/src/odbc/unittests/Makefile.am
+@@ -1,4 +1,4 @@
+-# $Id: Makefile.am,v 1.84 2010/10/29 14:52:41 freddy77 Exp $
++# $Id: Makefile.am,v 1.85 2010/12/30 18:18:11 freddy77 Exp $
+ TESTS		=	\
+ 			t0001$(EXEEXT) t0002$(EXEEXT) t0003$(EXEEXT)\
+ 			t0004$(EXEEXT) connect$(EXEEXT) print$(EXEEXT)\
+@@ -23,7 +23,7 @@ TESTS		=	\
+ 			attributes$(EXEEXT) hidden$(EXEEXT) blob1$(EXEEXT) \
+ 			cancel$(EXEEXT) wchar$(EXEEXT) rowset$(EXEEXT) transaction2$(EXEEXT) \
+ 			cursor6$(EXEEXT) cursor7$(EXEEXT) utf8$(EXEEXT) utf8_2$(EXEEXT) \
+-			stats$(EXEEXT) descrec$(EXEEXT) peter$(EXEEXT)
++			stats$(EXEEXT) descrec$(EXEEXT) peter$(EXEEXT) test64$(EXEEXT)
+ 
+ check_PROGRAMS	=	$(TESTS)
+ 
+@@ -94,6 +94,7 @@ utf8_2_SOURCES	= utf8_2.c common.c common.h
+ stats_SOURCES	= stats.c common.c common.h
+ descrec_SOURCES	= descrec.c common.c common.h
+ peter_SOURCES	= peter.c common.c common.h
++test64_SOURCES = test64.c common.c common.h
+ 
+ AM_CPPFLAGS	=	-I$(top_srcdir)/include $(ODBC_INC) -DFREETDS_SRCDIR=\"$(srcdir)\"
+ if MINGW32
+diff --git a/src/odbc/unittests/test64.c b/src/odbc/unittests/test64.c
+index 4df9ad4..95c5bc2 100644
+--- a/src/odbc/unittests/test64.c
++++ b/src/odbc/unittests/test64.c
+@@ -1,7 +1,7 @@
+ /* test win64 consistency */
+ #include "common.h"
+ 
+-static char software_version[] = "$Id: test64.c,v 1.10 2010/07/05 09:20:33 freddy77 Exp $";
++static char software_version[] = "$Id: test64.c,v 1.11 2010/12/30 18:18:11 freddy77 Exp $";
+ static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
+ 
+ /*
+@@ -259,6 +259,7 @@ main(void)
+ 	test_rows();
+ 
+ 	odbc_disconnect();
++	printf("Done\n");
+ 	return 0;
+ }
+ 
+
+commit d306f9bf590b6b170efafe1421dd72ab7d8987ea
+Author: freddy77 <freddy77>
+Date:   Thu Dec 30 18:28:24 2010 +0000
+
+    fix time shift problem
+
+diff --git a/ChangeLog b/ChangeLog
+index 91b647c..e3503dc 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,7 @@
++Thu Dec 30 19:28:16 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
++	* include/tds.h src/odbc/sql2tds.c src/tds/threadsafe.c:
++	- fix time shift problem
++
+ Thu Dec 30 19:18:05 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
+ 	* src/odbc/unittests/Makefile.am src/odbc/unittests/test64.c:
+ 	- add small test for 64bit problems
+@@ -3102,4 +3106,4 @@ Wed Jan  9 19:54:43 EST 2008	JK Lowden <jklowden@freetds.org>
+ 	* ChangeLog-0.82 added because of release
+ 	
+ $FreeTDS$
+-$Id: ChangeLog,v 1.3181 2010/12/30 18:18:11 freddy77 Exp $
++$Id: ChangeLog,v 1.3182 2010/12/30 18:28:24 freddy77 Exp $
+diff --git a/include/tds.h b/include/tds.h
+index 2460f88..a2ba4c0 100644
+--- a/include/tds.h
++++ b/include/tds.h
+@@ -21,7 +21,7 @@
+ #ifndef _tds_h_
+ #define _tds_h_
+ 
+-/* $Id: tds.h,v 1.346 2010/11/26 19:46:55 freddy77 Exp $ */
++/* $Id: tds.h,v 1.347 2010/12/30 18:28:24 freddy77 Exp $ */
+ 
+ #include <stdarg.h>
+ #include <stdio.h>
+@@ -1428,6 +1428,7 @@ TDSICONV *tds_iconv_from_collate(TDSSOCKET * tds, TDS_UCHAR collate[5]);
+ 
+ /* threadsafe.c */
+ char *tds_timestamp_str(char *str, int maxlen);
++struct tm *tds_localtime_r(const time_t *timep, struct tm *result);
+ struct hostent *tds_gethostbyname_r(const char *servername, struct hostent *result, char *buffer, int buflen, int *h_errnop);
+ struct hostent *tds_gethostbyaddr_r(const char *addr, int len, int type, struct hostent *result, char *buffer, int buflen,
+ 				    int *h_errnop);
+diff --git a/src/odbc/sql2tds.c b/src/odbc/sql2tds.c
+index d06c308..b8b4d4c 100644
+--- a/src/odbc/sql2tds.c
++++ b/src/odbc/sql2tds.c
+@@ -1,6 +1,6 @@
+ /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
+  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005  Brian Bruns
+- * Copyright (C) 2005-2008  Frediano Ziglio
++ * Copyright (C) 2005-2010  Frediano Ziglio
+  *
+  * This library is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU Library General Public
+@@ -54,16 +54,15 @@
+ #include <dmalloc.h>
+ #endif
+ 
+-TDS_RCSID(var, "$Id: sql2tds.c,v 1.85 2010/07/03 09:14:36 freddy77 Exp $");
++TDS_RCSID(var, "$Id: sql2tds.c,v 1.86 2010/12/30 18:28:24 freddy77 Exp $");
+ 
+ static TDS_INT
+ convert_datetime2server(int bindtype, const void *src, TDS_DATETIME * dt)
+ {
+-	struct tds_time src_tm;
++	struct tm src_tm;
++	int tm_ms;
+ 	unsigned int dt_time;
+-	TDS_INT dt_days;
+ 	int i;
+-	int got_date = 1;
+ 	time_t curr_time;
+ 
+ 	const DATE_STRUCT *src_date = (const DATE_STRUCT *) src;
+@@ -79,11 +78,10 @@ convert_datetime2server(int bindtype, const void *src, TDS_DATETIME * dt)
+ 		src_tm.tm_hour = 0;
+ 		src_tm.tm_min = 0;
+ 		src_tm.tm_sec = 0;
+-		src_tm.tm_ms = 0;
++		tm_ms = 0;
+ 		break;
+ 	case SQL_C_TIME:
+ 	case SQL_C_TYPE_TIME:
+-		got_date = 0;
+ #if HAVE_GETTIMEOFDAY
+ 		{
+ 			struct timeval tv;
+@@ -93,11 +91,11 @@ convert_datetime2server(int bindtype, const void *src, TDS_DATETIME * dt)
+ #else
+ 		curr_time = time(NULL);
+ #endif
+-		dt_days = (curr_time / 86400u) + (70u * 365u + 17u);
++		tds_localtime_r(&curr_time, &src_tm);
+ 		src_tm.tm_hour = src_time->hour;
+ 		src_tm.tm_min = src_time->minute;
+ 		src_tm.tm_sec = src_time->second;
+-		src_tm.tm_ms = 0;
++		tm_ms = 0;
+ 		break;
+ 	case SQL_C_TIMESTAMP:
+ 	case SQL_C_TYPE_TIMESTAMP:
+@@ -107,23 +105,20 @@ convert_datetime2server(int bindtype, const void *src, TDS_DATETIME * dt)
+ 		src_tm.tm_hour = src_timestamp->hour;
+ 		src_tm.tm_min = src_timestamp->minute;
+ 		src_tm.tm_sec = src_timestamp->second;
+-		src_tm.tm_ms = src_timestamp->fraction / 1000000lu;
++		tm_ms = src_timestamp->fraction / 1000000lu;
+ 		break;
+ 	default:
+ 		return TDS_FAIL;
+ 	}
+ 
+ 	/* TODO code copied from convert.c, function */
+-	if (got_date) {
+-		i = (src_tm.tm_mon - 13) / 12;
+-		dt_days = 1461 * (src_tm.tm_year + 300 + i) / 4 +
+-			(367 * (src_tm.tm_mon - 1 - 12 * i)) / 12 - (3 * ((src_tm.tm_year + 400 + i) / 100)) / 4 +
+-			src_tm.tm_mday - 109544;
+-	}
++	i = (src_tm.tm_mon - 13) / 12;
++	dt->dtdays = 1461 * (src_tm.tm_year + 300 + i) / 4 +
++		(367 * (src_tm.tm_mon - 1 - 12 * i)) / 12 - (3 * ((src_tm.tm_year + 400 + i) / 100)) / 4 +
++		src_tm.tm_mday - 109544;
+ 
+-	dt->dtdays = dt_days;
+ 	dt_time = (src_tm.tm_hour * 60 + src_tm.tm_min) * 60 + src_tm.tm_sec;
+-	dt->dttime = dt_time * 300 + (src_tm.tm_ms * 3 + 5) / 10;
++	dt->dttime = dt_time * 300 + (tm_ms * 3 + 5) / 10;
+ 	return sizeof(TDS_DATETIME);
+ }
+ 
+diff --git a/src/tds/threadsafe.c b/src/tds/threadsafe.c
+index e76f035..81df027 100644
+--- a/src/tds/threadsafe.c
++++ b/src/tds/threadsafe.c
+@@ -85,24 +85,43 @@
+ #include <dmalloc.h>
+ #endif
+ 
+-TDS_RCSID(var, "$Id: threadsafe.c,v 1.49 2010/11/16 10:29:56 freddy77 Exp $");
++TDS_RCSID(var, "$Id: threadsafe.c,v 1.50 2010/12/30 18:28:24 freddy77 Exp $");
++
++struct tm *
++tds_localtime_r(const time_t *timep, struct tm *result)
++{
++	struct tm *tm;
++
++#if defined(_REENTRANT) && !defined(_WIN32)
++#if HAVE_FUNC_LOCALTIME_R_TM
++	tm = localtime_r(timep, result);
++#else
++	tm = NULL;
++	if (!localtime_r(timep, result))
++		tm = result;
++#endif /* HAVE_FUNC_LOCALTIME_R_TM */
++#else
++	tm = localtime(timep);
++	if (tm) {
++		memcpy(result, tm, sizeof(*result));
++		tm = result;
++	}
++#endif
++	return tm;
++}
+ 
+ char *
+ tds_timestamp_str(char *str, int maxlen)
+ {
+ #if !defined(_WIN32) && !defined(_WIN64)
+ 	struct tm *tm;
++	struct tm res;
+ 	time_t t;
+ 
+ #if HAVE_GETTIMEOFDAY
+ 	struct timeval tv;
+ 	char usecs[10];
+-#endif
+-#if defined(_REENTRANT)
+-	struct tm res;
+-#endif
+ 
+-#if HAVE_GETTIMEOFDAY
+ 	gettimeofday(&tv, NULL);
+ 	t = tv.tv_sec;
+ #else
+@@ -113,17 +132,7 @@ tds_timestamp_str(char *str, int maxlen)
+ 	time(&t);
+ #endif
+ 
+-#if defined(_REENTRANT)
+-#if HAVE_FUNC_LOCALTIME_R_TM
+-	tm = localtime_r(&t, &res);
+-#else
+-	tm = NULL;
+-	if (!localtime_r(&t, &res))
+-		tm = &res;
+-#endif /* HAVE_FUNC_LOCALTIME_R_TM */
+-#else
+-	tm = localtime(&t);
+-#endif
++	tm = tds_localtime_r(&t, &res);
+ 
+ /**	strftime(str, maxlen - 6, "%Y-%m-%d %H:%M:%S", tm); **/
+ 	strftime(str, maxlen - 6, "%H:%M:%S", tm);
+
+commit 71ba6f1e6fc550ec25ea50b0673dc5f4cf918fd3
+Author: freddy77 <freddy77>
+Date:   Thu Dec 30 18:54:08 2010 +0000
+
+    fix VARYBINBIND in dblib
+
+diff --git a/ChangeLog b/ChangeLog
+index e3503dc..843be56 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,8 @@
++Thu Dec 30 19:53:59 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
++	* include/tds.h src/dblib/dblib.c src/dblib/unittests/t0007.c:
++	* src/dblib/unittests/t0007.sql:
++	- fix VARYBINBIND in dblib
++
+ Thu Dec 30 19:28:16 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
+ 	* include/tds.h src/odbc/sql2tds.c src/tds/threadsafe.c:
+ 	- fix time shift problem
+@@ -3106,4 +3111,4 @@ Wed Jan  9 19:54:43 EST 2008	JK Lowden <jklowden@freetds.org>
+ 	* ChangeLog-0.82 added because of release
+ 	
+ $FreeTDS$
+-$Id: ChangeLog,v 1.3182 2010/12/30 18:28:24 freddy77 Exp $
++$Id: ChangeLog,v 1.3183 2010/12/30 18:54:08 freddy77 Exp $
+diff --git a/include/tds.h b/include/tds.h
+index a2ba4c0..4d32887 100644
+--- a/include/tds.h
++++ b/include/tds.h
+@@ -21,7 +21,7 @@
+ #ifndef _tds_h_
+ #define _tds_h_
+ 
+-/* $Id: tds.h,v 1.347 2010/12/30 18:28:24 freddy77 Exp $ */
++/* $Id: tds.h,v 1.348 2010/12/30 18:54:08 freddy77 Exp $ */
+ 
+ #include <stdarg.h>
+ #include <stdio.h>
+@@ -157,7 +157,7 @@ typedef struct tdsvarbinary
+ } TDS_VARBINARY;
+ typedef struct tdsvarchar
+ {
+-	TDS_INT len;
++	TDS_SMALLINT len;
+ 	TDS_CHAR array[256];
+ } TDS_VARCHAR;
+ 
+diff --git a/src/dblib/dblib.c b/src/dblib/dblib.c
+index dd6c26f..acb3597 100644
+--- a/src/dblib/dblib.c
++++ b/src/dblib/dblib.c
+@@ -75,7 +75,7 @@
+ #include <dmalloc.h>
+ #endif
+ 
+-TDS_RCSID(var, "$Id: dblib.c,v 1.373 2010/12/23 09:32:27 freddy77 Exp $");
++TDS_RCSID(var, "$Id: dblib.c,v 1.374 2010/12/30 18:54:08 freddy77 Exp $");
+ 
+ static RETCODE _dbresults(DBPROCESS * dbproc);
+ static int _db_get_server_type(int bindtype);
+@@ -459,7 +459,7 @@ static NULLREP default_null_representations[MAXBINDTYPES] = {
+ 	/* STRINGBIND	     1  */	, {         NULL, 0 }
+ 	/* NTBSTRINGBIND     2  */	, { (BYTE*) &null_CHAR, sizeof(null_CHAR) }
+ 	/* VARYCHARBIND      3  */	, { (BYTE*) &null_VARYCHAR, sizeof(null_VARYCHAR) }
+-	/* VARYBINBIND       4  */	, {         &null_BINARY, sizeof(null_BINARY) }
++	/* VARYBINBIND       4  */	, { (BYTE*) &null_VARYCHAR, sizeof(null_VARYCHAR) }
+ 	/* no such bind      5  */	, {         NULL, 0 }			
+ 	/* TINYBIND	     6  */	, {         &null_TINYINT, sizeof(null_TINYINT) }
+ 	/* SMALLBIND	     7  */	, { (BYTE*) &null_SMALLINT, sizeof(null_SMALLINT) }
+@@ -2116,9 +2116,11 @@ _db_get_server_type(int bindtype)
+ 		return SYBMONEY4;
+ 		break;
+ 	case BINARYBIND:
+-	case VARYBINBIND:
+ 		return SYBBINARY;
+ 		break;
++	case VARYBINBIND:
++		return SYBVARBINARY;
++		break;
+ 	case VARYCHARBIND:
+ 		return SYBVARCHAR;
+ 		break;
+@@ -7354,16 +7356,29 @@ copy_data_to_host_var(DBPROCESS * dbproc, int srctype, const BYTE * src, DBINT s
+ 	}
+ 
+ 	switch (desttype) {
++	case SYBVARBINARY:
+ 	case SYBBINARY:
+ 	case SYBIMAGE:
+-		if (len > destlen && destlen >= 0) {
+-			dbperror(dbproc, SYBECOFL, 0);
++		if (bindtype == VARYBINBIND) {
++			if (limited_dest_space) {
++				if (len > sizeof(((DBVARYBIN *)dest)->array)) {
++					dbperror(dbproc, SYBECOFL, 0);
++					indicator_value = len;
++					len = sizeof(((DBVARYBIN *)dest)->array);
++				}
++			}
++			memcpy(((DBVARYBIN *)dest)->array, dres.c, len);
++			((DBVARYBIN *)dest)->len = len;
+ 		} else {
+-			memcpy(dest, dres.ib, len);
+-			TDS_ZERO_FREE(dres.ib);
+-			if (len < destlen)
+-				memset(dest + len, 0, destlen - len);
++			if (len > destlen && destlen >= 0) {
++				dbperror(dbproc, SYBECOFL, 0);
++			} else {
++				memcpy(dest, dres.ib, len);
++				if (len < destlen)
++					memset(dest + len, 0, destlen - len);
++			}
+ 		}
++		TDS_ZERO_FREE(dres.ib);
+ 		break;
+ 	case SYBINT1:
+ 		memcpy(dest, &(dres.ti), 1);
+@@ -7454,10 +7469,10 @@ copy_data_to_host_var(DBPROCESS * dbproc, int srctype, const BYTE * src, DBINT s
+ 				break;
+ 			case VARYCHARBIND: /* strip trailing blanks, NO null term */
+ 				if (limited_dest_space) {
+-					if (len > destlen) {
++					if (len > sizeof(((DBVARYCHAR *)dest)->str)) {
+ 						dbperror(dbproc, SYBECOFL, 0);
+ 						indicator_value = len;
+-						len = destlen;
++						len = sizeof(((DBVARYCHAR *)dest)->str);
+ 					}
+ 				} 
+ 				memcpy(((DBVARYCHAR *)dest)->str, dres.c, len);
+diff --git a/src/dblib/unittests/t0007.c b/src/dblib/unittests/t0007.c
+index d71d3cc..7404a45 100644
+--- a/src/dblib/unittests/t0007.c
++++ b/src/dblib/unittests/t0007.c
+@@ -5,7 +5,7 @@
+ 
+ #include "common.h"
+ 
+-static char software_version[] = "$Id: t0007.c,v 1.22 2010/12/30 14:53:12 freddy77 Exp $";
++static char software_version[] = "$Id: t0007.c,v 1.23 2010/12/30 18:54:08 freddy77 Exp $";
+ static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
+ 
+ static void
+@@ -174,12 +174,14 @@ main(int argc, char **argv)
+ 
+ 	dbbind(dbproc, 1, VARYBINBIND, sizeof(testvbin), (BYTE *) &testvbin);
+ 	dbbind(dbproc, 2, VARYCHARBIND, sizeof(testvstr), (BYTE *) &testvstr);
+++	dbbind(dbproc, 3, BINARYBIND, sizeof(testint), (BYTE *) &testint);
+ 
+ 	for (i = 1; i <= 2; i++) {
+ 		char expected[1024];
+ 
+ 		sprintf(expected, "row %07d ", i);
+ 
++		testint = -1;
+ 		memset(&testvbin, '*', sizeof(testvbin));
+ 		memset(&testvstr, '*', sizeof(testvstr));
+ 
+@@ -187,6 +189,10 @@ main(int argc, char **argv)
+ 			fprintf(stderr, "Failed.  Expected a row\n");
+ 			abort();
+ 		}
++		if (testint != i) {
++			fprintf(stderr, "Failed, line %d.  Expected i to be %d, was %d (0x%x)\n", __LINE__, i, (int) testint, (int) testint);
++			abort();
++		}
+ 		if (testvbin.len != sizeof(testint)) {
+ 			fprintf(stderr, "Failed, line %d.  Expected bin lenght to be %d, was %d\n", __LINE__, (int) sizeof(testint), (int) testvbin.len);
+ 			abort();
+diff --git a/src/dblib/unittests/t0007.sql b/src/dblib/unittests/t0007.sql
+index d78d390..fd714ba 100644
+--- a/src/dblib/unittests/t0007.sql
++++ b/src/dblib/unittests/t0007.sql
+@@ -28,5 +28,5 @@ go
+ /*
+  * Third select for binary bindings
+  */
+-select * from #dblib0007 where i<=5 order by i
++select i, s, i from #dblib0007 x where x.i<=5 order by x.i
+ go
+
+commit 22f9bad94401edf381413770810342ffd98473c6
+Author: freddy77 <freddy77>
+Date:   Thu Dec 30 19:44:44 2010 +0000
+
+    avoid warning
+
+diff --git a/src/dblib/dblib.c b/src/dblib/dblib.c
+index acb3597..4c0cedd 100644
+--- a/src/dblib/dblib.c
++++ b/src/dblib/dblib.c
+@@ -75,7 +75,7 @@
+ #include <dmalloc.h>
+ #endif
+ 
+-TDS_RCSID(var, "$Id: dblib.c,v 1.374 2010/12/30 18:54:08 freddy77 Exp $");
++TDS_RCSID(var, "$Id: dblib.c,v 1.375 2010/12/30 19:44:44 freddy77 Exp $");
+ 
+ static RETCODE _dbresults(DBPROCESS * dbproc);
+ static int _db_get_server_type(int bindtype);
+@@ -1641,7 +1641,7 @@ _dbresults(DBPROCESS * dbproc)
+ {
+ 	RETCODE retcode = FAIL;
+ 	TDSSOCKET *tds;
+-	int result_type, done_flags;
++	int result_type = 0, done_flags;
+ 
+ 	tdsdump_log(TDS_DBG_FUNC, "dbresults(%p)\n", dbproc);
+ 	CHECK_DBPROC();
+
+commit 1af4c9bbda28d34e598970514b9d95d398ec2053
+Author: freddy77 <freddy77>
+Date:   Thu Dec 30 19:50:21 2010 +0000
+
+    add some numeric cases
+
+diff --git a/ChangeLog b/ChangeLog
+index 843be56..99b9499 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,6 @@
++Thu Dec 30 20:50:14 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
++	* src/odbc/unittests/data.c: add some numeric cases
++
+ Thu Dec 30 19:53:59 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
+ 	* include/tds.h src/dblib/dblib.c src/dblib/unittests/t0007.c:
+ 	* src/dblib/unittests/t0007.sql:
+@@ -3111,4 +3114,4 @@ Wed Jan  9 19:54:43 EST 2008	JK Lowden <jklowden@freetds.org>
+ 	* ChangeLog-0.82 added because of release
+ 	
+ $FreeTDS$
+-$Id: ChangeLog,v 1.3183 2010/12/30 18:54:08 freddy77 Exp $
++$Id: ChangeLog,v 1.3184 2010/12/30 19:50:21 freddy77 Exp $
+diff --git a/src/odbc/unittests/data.c b/src/odbc/unittests/data.c
+index 86defc3..9899722 100644
+--- a/src/odbc/unittests/data.c
++++ b/src/odbc/unittests/data.c
+@@ -13,7 +13,7 @@
+  * Also we have to check normal char and wide char
+  */
+ 
+-static char software_version[] = "$Id: data.c,v 1.35 2010/12/30 12:41:51 freddy77 Exp $";
++static char software_version[] = "$Id: data.c,v 1.36 2010/12/30 19:50:21 freddy77 Exp $";
+ static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
+ 
+ static int result = 0;
+@@ -149,6 +149,8 @@ main(int argc, char *argv[])
+ 	Test("INT", "-123", SQL_C_CHAR, "4 -123");
+ 	Test("INT", "78654", SQL_C_WCHAR, "5 78654");
+ 	Test("VARCHAR(10)", "  51245  ", SQL_C_LONG, "51245");
++	Test("VARCHAR(20)", "  15.1245  ", SQL_C_NUMERIC, "38 0 1 0F");
++	Test("VARCHAR(20)", "  15  ", SQL_C_NUMERIC, "38 0 1 0F");
+ 	if (odbc_db_is_microsoft() && (strncmp(odbc_db_version(), "08.00.", 6) == 0 || strncmp(odbc_db_version(), "09.00.", 6) == 0)) {
+ 		/* nvarchar without extended characters */
+ 		Test("NVARCHAR(20)", "test", SQL_C_CHAR, "4 test");
+
+commit c62ea5a1cebda4ca6d5f319225a6a95f7b31bb75
+Author: jklowden <jklowden>
+Date:   Fri Dec 31 04:12:07 2010 +0000
+
+    updated to reflect current status
+
+diff --git a/ChangeLog b/ChangeLog
+index 99b9499..d85b18d 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,7 @@
++Thu Dec 30 23:06:08 EST 2010	JK Lowden <jklowden@freetds.org>
++	* doc/tsql.txt doc/userguide.sgml doc/htdoc/faq.html
++	- updated to reflect current status
++
+ Thu Dec 30 20:50:14 CET 2010    Frediano Ziglio <freddy77_A_gmail_D_com>
+ 	* src/odbc/unittests/data.c: add some numeric cases
+ 
+@@ -3114,4 +3118,4 @@ Wed Jan  9 19:54:43 EST 2008	JK Lowden <jklowden@freetds.org>
+ 	* ChangeLog-0.82 added because of release
+ 	
+ $FreeTDS$
+-$Id: ChangeLog,v 1.3184 2010/12/30 19:50:21 freddy77 Exp $
++$Id: ChangeLog,v 1.3185 2010/12/31 04:12:07 jklowden Exp $
+diff --git a/doc/htdoc/faq.html b/doc/htdoc/faq.html
+index 72488dd..bb1bb2b 100644
+--- a/doc/htdoc/faq.html
++++ b/doc/htdoc/faq.html
+@@ -3,7 +3,7 @@
+     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+ 
+ <html xmlns="http://www.w3.org/1999/xhtml">
+-<!-- $Id: faq.html,v 1.25 2009/02/11 02:41:58 jklowden Exp $ -->
++<!-- $Id: faq.html,v 1.26 2010/12/31 04:12:07 jklowden Exp $ -->
+ 
+ <head>
+   <meta name="generator" content=
+@@ -119,6 +119,8 @@
+         <li><a href="#Are.there.any.known.issues">Are there any
+         known issues?</a></li>
+ 
++        <li><a href="#What.features.are.missing">What features are missing</a> compared to the vendors' implementations?</li>
++
+         <li><a href="#pending">Why does each connection support
+         only one query at a time?</a></li>
+ 
+@@ -155,6 +157,8 @@
+         right!</a></li>
+         <li>My PHP script works from the command line but 
+ 		<a href="#php">fails in the browser!</a></li>
++		
++		<li>How do I debug my <a href="#oracle">Oracle Heterogeneous Services</a> error?</li>
+       </ul>
+     </li>
+   </ol>
+@@ -567,9 +571,7 @@
+   DBI::ODBC load for other systems. On the downside, it may be a
+   little less robust than DBD::Sybase.</p>
+ 
+-  <h3>Are there any known issues?</h3>
+-  	<a name="Are.there.any.known.issues" 
+-	     id="Are.there.any.known.issues"></a>
++  <h3 id="Are.there.any.known.issues">Are there any known issues?</h3>
+   <ul>
+     <li>ODBC can be confusing to set up. See the <tt>samples</tt>
+     directory for example <tt>.ini</tt> files, and follow the User
+@@ -596,6 +598,20 @@
+   sometimes be misleading. In the latter case, it's often necessary
+   to examine the log file to understand what went wrong. </p>
+ 
++ <h3 id="What.features.are.missing"> What features are missing compared to the vendors' implementations?</h3>
++ 
++ 	<p>In no particular order: </p>
++	<ul>
++		<li>MARS</li>
++		<li>db-lib browse API</li>
++		<li>Parameterized queries in ct-lib with TDS 7.0+ (i.e. Microsoft servers)</li>
++		<li>ct-lib money functions</li>
++	</ul>
++	
++	<p>For specific functions, consult <code>doc/api_status.txt</code> in your distribution. </p>
++	
++	<p>Very few programs actually need the missing functionality.  Parameterized ct-lib queries would benefit Perl DBD::Sybase users, but the functionality would require departing from Sybase's documented API.  MARS comes up because there must be thousands of people whom Microsoft has convinced they need it, but the benefits are meager compared to the complexity.  </p>
++	
+   <h3>Why does each connection support only one query at a time?</h3>
+ 	<a name="pending" id="pending"></a>
+ 
+@@ -635,13 +651,19 @@
+     That's not as bad as it sounds, and it certainly not unheard of
+     to have 4 or more simultaneous connections supporting an
+     application.</li>
+-  </ul>It's important to realize that the selection of rows and
++  </ul>
++  
++  <p>It's important to realize that the selection of rows and
+   their accumulation into a container of some sort are two
+   different functions. A TDS server issues its results a row at a
+   time, which the client library dutifully makes available to the
+   application on arrival. It's up to the application&mdash;or a
+   higher-level library&mdash;to form a "rowset" of some kind if
+-  desired.
++  desired.</p>
++  
++  <p><i>But what about MARS&reg;</i> you ask?  <i>Doesn't that solve the problem?</i>  Well, no.  MARS <i>does</i> make a TDS server more similar to other vendors' servers, and Microsoft benefits from one more just-like-the-others feature for its ODBC driver.  But Microsoft claims a patent on MARS, the documentation is incomplete, and supporting it would introduce significant complexity.</p>
++  
++  <p>MARS might get implemented one day; more surprising things have happened.  But the technical advantages it provides to the programmer are over server-side cursors or simply using another connection are vanishingly small.  </p>
+ 
+   <h4>PHP note</h4>If you use PHP, you will still run into this
+   problem even if you create a new connection. The reason is that
+@@ -900,14 +922,19 @@
+   normally not the one you use to log in, or to test your script
+   with on the command line.  </p>
+ 
+-
++	<h3 id="oracle">How do I debug my Oracle Heterogeneous Services error?</h3>
++	
++	<p>The message produced by the Oracle server is seldom detailed enough to understand what's wrong.  
++		Really, the only way to debug these errors reliably is with a TDSDUMP log of the session. 
++		The log will contain any error messages from the server and/or from the library.  Often that's
++		all the information needed.  If not, post the log to the mailing list. </p>
+   
+   <!-- footer -->
+   <hr size="1" />
+   <font size="-1">Updates and comments <a href=
+   "mailto:jklowden@freetds.org">FreeTDS FAQ Master</a> 
+   <br/>
+-    <i>$Id: faq.html,v 1.25 2009/02/11 02:41:58 jklowden Exp $</i>
++    <i>$Id: faq.html,v 1.26 2010/12/31 04:12:07 jklowden Exp $</i>
+ 	</font>
+ <hr/>
+   <p>
+diff --git a/doc/tsql.txt b/doc/tsql.txt
+index 8536eec..62a147f 100644
+--- a/doc/tsql.txt
++++ b/doc/tsql.txt
+@@ -1,7 +1,7 @@
+ NAME
+   tsql - utility to test FreeTDS connections and queries
+ SYNOPSIS
+-  tsql 	{ -S servername [-I inside] | -H hostname -p port } 
++  tsql 	{ -S servername [-I interface] | -H hostname -p port } 
+  	-U username [-P password] [-o options]
+ 	
+   tsql	-C
+@@ -33,7 +33,7 @@ OPTIONS
+ 
+ 	-S servername  the Database Server to which to connect.
+ 
+-	-I inside  a freetds.conf or interfaces file describing servername
++	-I interface  a freetds.conf or interfaces file describing servername
+ 
+ 	-H hostname  the DNS hostname of the server
+ 
+@@ -43,6 +43,8 @@ OPTIONS
+ 
+ 	-P password  database password.
+ 	
++	-L list server "instances" (with -H)
++
+ 	-C  prints some of the compile-time configuration parameters.  
+ 
+ 	-o options  apply the options specified to every command.
+@@ -61,6 +63,12 @@ Typing "version" displays the TDS protocol version.
+ Command batches may be separated with "go" or "GO". If "GO", the version
+ string is reported before executing the batch. 
+ 
++After prompting for the password, tsql will attempt to connect to the remote
++server.  tsql displays a counter indicating the number of seconds that
++it is attempting to connect.  Typically, tsql should immediately respond
++with a '1>' prompt.  If you see the counter (1, 2, 3, ...), most likely tsql
++is unable to connect to the indicated server.
++
+ If you can connect with "tsql -S servername", your basic FreeTDS installation
+ is working. 
+ 
+diff --git a/doc/userguide.sgml b/doc/userguide.sgml
+index 01a6d5b..2d9971d 100644
+--- a/doc/userguide.sgml
++++ b/doc/userguide.sgml
+@@ -9,8 +9,8 @@
+ ]>
+ <book>
+ 	<bookinfo>
+-		<date>$Date: 2010/09/16 07:44:33 $</date>
+-		<releaseinfo>$Revision: 1.130 $</releaseinfo>
++		<date>$Date: 2010/12/31 04:12:07 $</date>
++		<releaseinfo>$Revision: 1.131 $</releaseinfo>
+ 		<title>&freetds; User Guide</title>
+ 		<subtitle>A Guide to Installing, Configuring, and Running &freetds;</subtitle>
+ 		<author>
+@@ -62,9 +62,9 @@ This guide is here for you, and we hope that you will be here for it, that other
+ The version you're reading is:
+ 			</para> 
+   			<simplelist type='vert'>
+-<member>$Revision: 1.130 $</>
+-<member>$Date: 2010/09/16 07:44:33 $</>
+-<member>CVS control number $Id: userguide.sgml,v 1.130 2010/09/16 07:44:33 freddy77 Exp $.</>
++<member>$Revision: 1.131 $</>
++<member>$Date: 2010/12/31 04:12:07 $</>
++<member>CVS control number $Id: userguide.sgml,v 1.131 2010/12/31 04:12:07 jklowden Exp $.</>
+   			</simplelist>
+ 			</footnote>
+ can be found on the &freetds; 
+@@ -215,18 +215,16 @@ project on SourceForge.  It is a fork of the
+ 		  </sect2>
+ 		<sect2 id="Status">
+ 			<title>Status</title>
+-			<para>
+-The <systemitem class="library">db-lib</systemitem> and <systemitem class="library">ct-lib</systemitem> <acronym>API</>s have been usable for several years.  They have been successfully  substituted for Sybase's own libraries in a variety of venues, including <productname>Perl</productname> and <productname>PHP</productname>.  That is not to say that these drivers are complete; they're not.  But they faithfully implement a useful &mdash; and widely used &mdash; subset of their <acronym>API</>s.  
++			<para>The libraries are portable, mature, and stable.  They're expected to compile readily and normally do not crash or corrupt data.  There is a logging feature to aid in diagnosing problems.  While they do not include every feature provided by the vendors' libaries, they do faithfully implement a useful &mdash; and widely used &mdash; subset of their <acronym>API</>s.  
+ 			</para>
+-			<para>
+-In addition to the core <systemitem class="library">db-lib</systemitem> <acronym>API</>, &freetds;  includes a full implementation of <systemitem class="library">db-lib</systemitem>'s <acronym>bcp</> functions, as well as <command>freebcp</>, a replacement for Sybase's <application>bcp</application> utility.  
++			<para>The <systemitem class="library">db-lib</systemitem> and <systemitem class="library">ct-lib</systemitem> <acronym>API</>s have been usable for several years.  They have been successfully  substituted for Sybase's own libraries in a variety of venues, including <productname>Perl</productname> and <productname>PHP</productname>.  
+ 			</para>
+-			<para>
+-The <systemitem class="library">ODBC</> driver should be fully ODBC 3.0 compliant.  Any problems found in the currently implemented <acronym>API</> subset are cheerfully  addressed.  
++			<para>The <systemitem class="library">ODBC</> driver should be fully ODBC 3.0 compliant.  
+ 			</para>
+-			<para>
+-Basic <link linkend="apireference">API coverage</link> information for all libraries may be found in this manual.  It is maintained in <filename>doc/api_status.txt</>, included in the source distribution.   			
++			<para>Basic <link linkend="apireference">API coverage</link> information for all libraries may be found in this manual.  It is maintained in <filename>doc/api_status.txt</>, included in the source distribution.   			
+ 			</para> 
++			<para>In addition to the core <systemitem class="library">db-lib</systemitem> <acronym>API</>, &freetds;  includes a full implementation of <systemitem class="library">db-lib</systemitem>'s <acronym>bcp</> functions, as well as <command>freebcp</>, a replacement for Sybase's <application>bcp</application> utility.  
++			</para>
+ 			<para>How big is it?  &freetds; has over 90,000 lines of C code, maintained by a handful of developers.  Patches arrive irregularly, varying in size from one-liners to thousand-line monsters.  Almost all are applied or used in some way.  The mailing list has some 700 or so subscribers at this writing.  Safe to say, &freetds;'s success so far lies somewhere between the Beetle and the Edsel.  
+ 			</para>
+ 			<para>Who uses it?  Oh, pretty much everyone.  &freetds; users almost certainly number in the tens of thousands.  It's used by large corporations, by the U.S. federal government (e.g. <ulink url="http://www.ncbi.nlm.nih.gov/books/bv.fcgi?rid=toolkit.chapter.ch_dbapi">Database Access Library</ulink> at the National Center for Biotechnology Information) and, judging by the mailing list, by many webservers running Apache and PHP.  Microsoft recommends &freetds; to their customers who want access to Microsoft SQL Server from non-Win32 clients. So do we.  
+@@ -237,10 +235,6 @@ Basic <link linkend="apireference">API coverage</link> information for all libra
+ 			<para>
+ You may be wondering how these libraries fit with Perl, PHP, TCL, Python, or other popular scripting languages.  Most of these languages have bindings to Sybase that use either the <systemitem class="library">db-lib</systemitem> or <systemitem class="library">ct-lib</systemitem> <acronym>API</>, for which &freetds; is intended as a drop-in replacement.  For instance, Michael Peppler's <systemitem class="library">DBD::Sybase</systemitem> works very well using &freetds; to access Sybase or Microsoft <productname>SQL Server</productname>s.  <productname>PHP</productname> has options for <filename>sybase</filename> (<systemitem class="library">db-lib</systemitem>) and <filename>sybase-ct</filename> (<systemitem class="library">ct-lib</systemitem>) <acronym>API</>s.
+ 			</para>
+-			<para>
+-Not to be outdone, the folks at the <firstterm>O'Caml</> project have a binding for that language.  You can read more about it on <ulink url="http://kenn.frap.net/ocaml-freetds/">
+-Kenn Knowles's</ulink> site; see also his <ulink url="http://www.merjis.com/developers/">ocamldbi</ulink> driver.  
+-			</para>
+ 		</sect2>
+ 		<sect2 id="alternatives">
+ 			<title>Alternatives</title>
+@@ -475,7 +469,7 @@ There are a few optional arguments to <Command>configure</> that may be importan
+ 			<varlistentry>
+ 				<term><Option>--enable-msdblib</Option></term>
+ 				<listitem><para>Enable Microsoft behavior in the <systemitem class="library">db-lib</systemitem> <acronym>API</> where it diverges from Sybase's.  (For instance, Microsoft uses different names for the members of its date structure.)  Typically needed only for porting Win32 applications to Unix.</para>
+-					<para>As of version 0.63, this option specifies just the default behavior. Programs can change the default at compile time by defining MSDBLIB or SYBDBLIB (for Microsoft or Sybase behavior, respectively) .</para>
++					<para>This option specifies default behavior. Programs can change the default at compile time by defining MSDBLIB or SYBDBLIB (for Microsoft or Sybase behavior, respectively).</para>
+ 					</listitem>
+ 				</varlistentry>
+ 
+@@ -494,8 +488,7 @@ There are a few optional arguments to <Command>configure</> that may be importan
+ 
+ 			<varlistentry>
+ 				<term><Option>--enable-sspi</Option></term>
+-				<listitem><para>Enable SSPI support. SSPI is a Windows library that allow you to use your current logged account for 
+-					authentication. This allow you to login without entering a password again.
++				<listitem><para>Enable SSPI support. SSPI is a Micrsoft library that allows you to use your current logged account for authentication.  With this option enabled, FreeTDS supports "trusted logins" for Win32/64, just as Microsoft's own implmentations do.  
+ 				</para></listitem>
+ 				</varlistentry>
+ 
+@@ -617,7 +610,7 @@ url="http://www.madgoat.com">www.madgoat.com</ulink>).</para>
+ 		</sect3>
+ 		</sect2>
+ 		<sect2 id="osx"><title>OS X&reg;</title>
+-  			<para>As of this writing ($Date: 2010/09/16 07:44:33 $), the regular distribution compiles on OS X.  Releases prior to 0.63 either did not compile or required patching.  </para>
++  			<para>As of this writing ($Date: 2010/12/31 04:12:07 $), the regular distribution compiles on OS X.  Releases prior to 0.63 either did not compile or required patching.  </para>
+ 
+ 		<sect3 id="OSX.Build.Update">
+ 			<title>Alternative build procedure</title>
+@@ -754,13 +747,16 @@ The <acronym>TDS</> protocol version is probably something you'd rather not know
+ 	<entry>7.1</entry>
+ 	<entry>Include support for <symbol>bigint</> (64 bit integers), <symbol>variant</> and collation on all fields. Collation is not widely used. </entry>
+ 	</row>
++	<row>
++	<entry>Microsoft SQL Server 2005</entry>
++	<entry>7.2</entry>
++	<entry>Includes support for varchar(max), varbinary(max), xml datatypes and MARS<footnote><para><emphasis>Multiple Active Result Sets</>. &freetds; does not support MARS.  </para></footnote>.</entry>
++	</row>
+ </tbody>	
+ </tgroup>
+ </table>
+ 			</para>
+-			<para>
+-Why downgrade your protocol?  If you encounter a bug, reverting to 4.2 can help isolate it.  If you're using low-bandwidth connections, 4.2 is faster than 7.0, because 7.0 transfers all character data in UCS-2 (Unicode, 2 bytes/character).  
+-However TDS 4.2 has many limitations (see below).  If you encounter problems, please report them to the mailing list.  
++			<para>For best results, use the highest version of hte protocol supported by your server.  If you encounter problems, try a lower version.  If that works, though, please report it to the mailing list!  
+ 			</para>
+ 			<para>
+ 			<ItemizedList><title>TDS 4.2 has limitations</title>
+@@ -819,7 +815,7 @@ and 7.0.  Version 7.0 is recommended for compatibility with SQL Server tools.
+ 			<para>
+ Just as DNS defines hostnames for  network addresses, &freetdsconf; uses a <firstterm>servername</> to define the properties of your server.  <footnote>
+ 	<para>In general, the servername is arbitrary and local; it's used only by your client programs to tell &freetds; which server to connect to.  You can choose any name you like.  </para>
+-	<para><productname>Sybase SQL Anywhere</productname> (a/k/a Sybase ASA), however, is fussy.  You must use the database's name as your servername.  Otherwise, the server will refuse your connection.  </para>
++	<para><productname>Sybase SQL Anywhere</productname> (a/k/a Sybase ASA), however, is fussy.  Unless you use the <link linkend="asa.database">ASA Database</link> property, you must use the database's name as your servername.  Otherwise, the server will refuse your connection.  </para>
+ 	</footnote> 
+ In particular, &freetds; needs to know:
+ 			<ItemizedList><title>Primary Server Properties</title>
+@@ -909,11 +905,11 @@ It bears mentioning here that prior versions of &freetds; were quite fussy about
+ <tbody>
+ 	<row>
+ 	<entry>tds version</entry>
++	<entry>4.2, 5.0, 7.0, 7.1, 7.2, <literal>auto</></entry>
+ 	<entry><parameter>--with-tdsver</> value (<literal>5.0</> if unspecified) 
+ 		Overridden by <link  linkend="TDSVER">TDSVER</link>.  
+ 		</entry> 
+-	<entry>The <acronym>TDS</> protocol version to use when connecting.</entry>
+-	<entry>4.2, 5.0, 7.0, 7.1, 7.2</entry>
++	<entry>The <acronym>TDS</> protocol version to use when connecting.  <quote><literal>auto</></quote> tells &freetds; to use an autodetection (trial-and-error) algorithm to choose the protocol version. </entry>
+ 	</row>
+ 	<row>
+ 	<entry>host</entry>
+@@ -961,16 +957,23 @@ It bears mentioning here that prior versions of &freetds; were quite fussy about
+ 	</entrytbl>
+ 	<entry>	The port number that the servername is listening to.  
+ 		<emphasis>Please note:</emphasis>
+-			The "defaults" to the left are the server's default settings.   &freetds; chooses its default port based on the TDS protocol version: <literal>5000</> for <acronym>TDS</> <literal>5.0</>, and <literal>1433</> for everything else.  
++			The "defaults" to the left are the server's default settings.   &freetds; chooses its default port based on the TDS protocol version: <literal>5000</> for <acronym>TDS</> <literal>5.0</>, and <literal>1433</> for everything else.  Mutually exclusive with <emphasis>instance</>, below.  
+ 		Overridden by <link  linkend="TDSPORT">TDSPORT</link>.
+ 	</entry>
+ 	</row>
+ 
+ 	<row>
+-	<entry>ASA database</entry>
++	<entry>instance</entry>
++	<entry>instance name</entry>
++	<entry>none</entry>
++	<entry><para>Name of Microsoft SQL Server <emphasis>instance</> to connect to. The port will be detected automatically.  Mutually exclusive with <emphasis>port</>, above.  Requires UDP connection to port 1434 on the server.  </para></entry>
++	</row>
++
++	<row>
++	<entry id="asa.database">ASA database</entry>
+ 	<entry>valid database name</entry>
+ 	<entry>servername [<replaceable>section</>] name</entry>
+-	<entry>Specifies the name of the default database when connecting to an ASA server.  A TDS 5.0 login packet has a field called <literal>lservname</>.   For most TDS servers, <literal>lservname</> is a user-defined string with no inherent meaning.  ASA servers, however, requires that <literal>lservname</>  contain a valid database name, and sets that as the default database for the connection.  FreeTDS normally fills <literal>lservname</>  with the [<replaceable>section</>]text..   This entry instead sets the database name independently of the [<replaceable>section</>] name.   </entry>
++	<entry>Specifies the name of the default database when connecting to an ASA server.  A TDS 5.0 login packet has a field called <literal>lservname</>.   For most TDS servers, <literal>lservname</> is a user-defined string with no inherent meaning.  ASA servers, however, requires that <literal>lservname</>  contain a valid database name, and sets that as the default database for the connection.  FreeTDS normally fills <literal>lservname</>  with the [<replaceable>section</>] text..   This entry instead sets the database name independently of the [<replaceable>section</>] name.   </entry>
+ 	</row>
+ 
+ 	<row>
+@@ -1017,7 +1020,7 @@ It bears mentioning here that prior versions of &freetds; were quite fussy about
+ 	<entry>any valid iconv character set</entry>
+ 	<entry>ISO-8859-1<footnote><para>Valid for ISO 8859-1 character set.  See <link linkend="Localization">Localization and <acronym>TDS</> 7.0</link> for more information.  </para></footnote></entry>
+ 	<entry>Makes &freetds; use iconv to convert to and from the specified character set from UCS-2 in <acronym>TDS</> 7.0 or above.
+-As of 0.62 FreeTDS uses iconv to convert all character data, so there's no need to match the server's charset to insert any characters the server supports.</entry>
++&freetds; uses iconv to convert all character data, so there's no need to match the server's charset to insert any characters the server supports.</entry>
+ 	</row>
+ 	<row>
+ 	<entry>text size</entry>
+@@ -1026,12 +1029,6 @@ As of 0.62 FreeTDS uses iconv to convert all character data, so there's no need
+ 	<entry>default value of TEXTSIZE, in bytes.  For <type>text</type> and <type>image</type> datatypes, sets the maximum width of any returned column. Cf. <command>set TEXTSIZE</> in the <acronym>T-SQL</> documentation for your server.  </entry>
+ 	</row>
+ 	<row>
+-	<entry>instance</entry>
+-	<entry>instance name</entry>
+-	<entry>none</entry>
+-	<entry><para>Name of Microsoft SQL Server <emphasis>instance</> to connect to. The port will be detected automatically.</para></entry>
+-	</row>
+-	<row>
+ 	<entry>debug flags</entry>
+ 	<entry>Any number even in hex or octal notation</entry>
+ 	<entry>0x4fff</entry>
+@@ -1126,7 +1123,7 @@ As of 0.62 FreeTDS uses iconv to convert all character data, so there's no need
+ 			</sect3>
+ 
+ 			<sect3><title>Deprecated options</>	
+-	<para>As of version 0.62 the following options are deprecated and supported only for backward compatibility.</para>
++	<para>The following options have long been deprecated.</para>
+ 
+ <itemizedlist id="lst.freetds.conf.deprecated" spacing="compact">
+ 	<title>Deprecated &freetdsconf; settings</title>
+@@ -1388,17 +1385,18 @@ Compile-time settings (established with the "configure" script):
+ 			<para>When <replaceable>servername</> cannot be converted to an address, up to two messages may result.  Successful conversion (by any means) never produces an error message.  
+ 			
+ <example id="e.g.notfound">
+-<title>Failure to find or resolve <replaceable>servername</></title>
++<title>Failure to find <replaceable>servername</> in &freetdsconf;</title>
+ <screen>
+ <prompt>$ </prompt><userinput>tsql -S <replaceable>nobox</replaceable> -U <replaceable>sa</replaceable> </userinput>
+ <prompt>Password: </prompt>
+ <computeroutput>
+ locale is "C"
+ locale charset is "646"
+-Msg 20012, Level 2, State -1, Server OpenClient, Line -1
+-Server name not found in configuration files.
+-Msg 20013, Level 2, State -1, Server OpenClient, Line -1
+-Unknown host machine name.
++Password: 
++Error 20012 (severity 2):
++	Server name not found in configuration files.
++Error 20013 (severity 2):
++	Unknown host machine name.
+ There was a problem connecting to the server
+ </computeroutput>
+ <prompt>$ </prompt><userinput>host nobox</userinput>
+@@ -1408,10 +1406,10 @@ Host not found.
+ </screen>
+ </example>
+ 
+-In the above case <literal>nobox</> was not found in &freetdsconf; and was is not a valid hostname according to DNS.  
++In the above case message 20012 indicates <literal>nobox</> was not found in &freetdsconf;.  The library then treated <literal>nobox</> as a network hostname but found it also not to be valid per DNS, leading to message 20013.  
+ 			</para>
+ 
+-			<para>If <replaceable>servername</> is found but refers to an invalid hostname, only message 20013 is returned. 
++			<para>If <replaceable>servername</> is found in the configuration files, but refers to an invalid hostname, only message 20013 is returned. 
+ 
+ <example id="e.g.badname">
+ <title>Failure to resolve hostname for <replaceable>servername</></title>
+@@ -1421,17 +1419,19 @@ In the above case <literal>nobox</> was not found in &freetdsconf; and was is no
+ <computeroutput>
+ locale is "C"
+ locale charset is "646"
+-Msg 20013, Level 2, State -1, Server OpenClient, Line -1
+-Unknown host machine name.
++Error 20013 (severity 2):
++        Unknown host machine name.
+ There was a problem connecting to the server
+ </computeroutput>
+ </screen>
+ </example>	
+ 			Unfortunately, the <quote>host machine name</quote> (the right side of the <literal>host</> line in &freetdsconf;) isn't mentioned in the error message.  Fortunately, this kind of setup problem is rarely encountered by users.  
+ 			</para>
++			</sect3>
++			<sect3 id="tsql.connect"><title>Connecting to the Server</title>
+ 			<para>If name lookup succeeds, &freetds; next attempts to connect to the server.  <emphasis>To connect</> means to form at TCP connection by calling <function>connect(2)</>.  A valid connection must exist before any information can be exchanged with the server.  Specifically, we need a connection before we can log in.  
+ 			</para>
+-			<para>A few things can go wrong at this point.  The address returned by DNS may not be that of the machine hosting the server.  The machine may be down.  The server may not be running.  The server may be running but not listening to the port &freetds; is attempting to connect to.  In rare cases, both ends are correctly configured, but a firewall stands in the way. 
++			<para>A few things can go wrong at this point.  The address returned by DNS may not be that of the machine hosting the server, or indeed of <emphasis>any</> machine!  The machine may be down.  The server may not be running.  The server may be running but not listening to the port &freetds; is attempting to connect to.  In rare cases, both ends are correctly configured, but a firewall stands in the way. 
+ 			</para>
+ 			<para>If no server accepts the connection, no connection can be established.  It's difficult to know why, and the message is consequently vague. 
+ 
+@@ -1593,7 +1593,7 @@ The connection attributes are provided as a single argument, a string of concate
+ But <productname>FreeTDS</> did not start out as an ODBC driver (remember db-lib and ct-lib), and has always had its own way to store server properties: &freetdsconf;.  When Brian added the <productname>FreeTDS</> ODBC driver, he began by supporting the old <function>SQLConnect</>, using <filename>odbc.ini</> to describe the DSN.  That choice complied with the expectations of the Driver Managers, and minimized the amount of duplicated information in the configuration files.  But it can be a little confusing, too, because <filename>odbc.ini</> in effect points to &freetdsconf;.  We call this configuration <firstterm>ODBC-combined</>, because it supports all three <productname>FreeTDS</> libraries.  
+ 			</para>
+ 			<para>
+-With version 0.60, the <productname>FreeTDS</> ODBC library started to see fuller implementation. The driver was made able to read the connection attributes directly from <filename>odbc.ini</>, rather than leaning on &freetdsconf;.  For installations that don't need db-lib and ct-lib, this <firstterm>ODBC-only</> setup is simpler.  			</para>
++As progress on the the &freetds; ODBC library progressed, the driver was made able to read the connection attributes directly from <filename>odbc.ini</>, rather than leaning on &freetdsconf;.  For installations that don't need db-lib and ct-lib, this <firstterm>ODBC-only</> setup is simpler.  			</para>
+ 			<para>
+ More recently, <function>SQLDriverConnect</> was added to <productname>FreeTDS</>.  As described above, this function allows the application to specify connection attributes with reference to either, or neither, configuration file.  It's your choice.  In making that choice, keep the following terms clear in your mind:
+ 			</para>
+@@ -2136,7 +2136,8 @@ Why this happens is anyone's guess.  Here's one: it makes the datatype of the co
+ <Note><para>Domain logins can be used only with TDS protocol versions 7.0 or above.</para></Note>
+ 			<para>
+ As mentioned in the installation chapter, <productname>Microsoft SQL Server</productname> includes the ability to use domain logins instead of standard server logins.  The advantage of doing this is that the passwords are encrypted on the wire using a challenge-response protocol.
+-&freetds; began supporting domain logins in version 0.60.
++			</para>
++			<para>Domain logins may or may not support single sign-on (connecting without prompting for a password) depending on how &freetds; was configured.  For Windows hosts (both 32- and 64-bit), if SSPI is enabled, &freetds; will log in using so-called "trusted authentication".  For Linux (and similar) hosts, enabling Kerberos provides similar functionality.  If neither option is enabled, &freetds; can <emphasis>still</> log in using the domain account, but the user must re-enter the password, as described next.  
+ 			</para>
+ 			<para>
+ To use domain logins, use the <literal>'DOMAIN\username'</> syntax for the username and use the domain password.  
+
+commit 4d5c8725537f069f11c45b10e077dad4bd187ea8
+Author: jklowden <jklowden>
+Date:   Fri Dec 31 16:20:58 2010 +0000
+
+    updated per Frediano
+
+diff --git a/doc/htdoc/faq.html b/doc/htdoc/faq.html
+index bb1bb2b..bfa23bc 100644
+--- a/doc/htdoc/faq.html
++++ b/doc/htdoc/faq.html
+@@ -3,7 +3,7 @@
+     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+ 
+ <html xmlns="http://www.w3.org/1999/xhtml">
+-<!-- $Id: faq.html,v 1.26 2010/12/31 04:12:07 jklowden Exp $ -->
++<!-- $Id: faq.html,v 1.27 2010/12/31 16:20:58 jklowden Exp $ -->
+ 
+ <head>
+   <meta name="generator" content=
+@@ -167,21 +167,16 @@
+ 
+   <h2>General Questions</h2>
+ 
+-  <h3>What is FreeTDS?</h3>
+-  	<a name="What.is.FreeTDS" id="What.is.FreeTDS"></a>
++  <h3 id="What.is.FreeTDS">What is FreeTDS?</h3>
+ 
+   <p>FreeTDS is a free implementation of the TDS (Tabular Data
+   Stream) protocol that is used by Sybase and Microsoft for their
+-  database products. It implements TDS 4.2, 5.0, 7.0 and
+-  8.0, and can communicate with any Sybase or Microsoft SQL
+-  Server.</p>
++  database products. It can communicate with any Sybase or Microsoft SQL
++  Server.  It includes three client libraries: DB-Library, CT-Library, 
++  and ODBC.  All libraries use the same protocol and can communicate with 
++  servers from both vendors.  </p>
+ 
+-  <p>FreeTDS comes with a low level library (the TDS layer) along
+-  with a number of APIs (Application Programming Interfaces). The
+-  APIs are DB-Lib, CT-Lib, and ODBC.</p>
+-
+-  <h3>Where do I get FreeTDS?</h3>
+-  	<a name="Where.do.I.get.FreeTDS" id="Where.do.I.get.FreeTDS"></a>
++  <h3 id="Where.do.I.get.FreeTDS">Where do I get FreeTDS?</h3>
+ 
+   <p>You can get the latest FreeTDS from <a href=
+   "ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz">
+@@ -197,8 +192,7 @@
+   to the list if you're looking for one and don't find one in the
+   usual places.</p>
+ 
+-  <h3>Does FreeTDS support Microsoft servers?</h3>
+-  	<a name="Does.FreeTDS.support.Microsoft.servers"></a>
++  <h3 id="Does.FreeTDS.support.Microsoft.servers">Does FreeTDS support Microsoft servers?</h3>
+ 
+   <p>Yes. Microsoft servers don't usually accept TDS 5.0
+   connections. Use one of versions 4.2, 7.0 or 8.0 of the protocol.
+@@ -219,8 +213,7 @@
+   "userguide/choosingtdsprotocol.htm">User
+   Guide</a> for details.</p>
+ 
+-  <h3>How can I get help (or support)?</h3>
+-	<a name="How.can.I.get.help" id="How.can.I.get.help"></a>
++  <h3 id="How.can.I.get.help">How can I get help (or support)?</h3>
+ 	
+   <p>After reading this FAQ and the User Guide, you might want to
+   look at the mailing list <a href=
+@@ -238,161 +231,42 @@
+   to the list, where someone with the available time and expertise
+   can help you.</p>
+ 
+-  <h3>Who is responsible for FreeTDS?</h3>
+-  	<a name="Who.is.responsible.for.FreeTDS" 
+-	     id="Who.is.responsible.for.FreeTDS"></a>
+-  <!-- table is due for an update, see AUTHORS file -->
+-  <!-- table generated by /usr/pkgsrc/databases/freetds/work/freetds/./authors2html ("nospam." added later by hand)-->
+-
+-  <table summary="Who is responsible for FreeTDS">
+-    <tr>
+-      <td><a href="mailto:brian@nospam.bruns.org">Brian
+-      Bruns</a></td>
+-
+-      <td>Started this crazy thing</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:greggj@nospam.savvis.com">Gregg
+-      Jensen</a></td>
+-
+-      <td>Message handlers and extra datatype support and some
+-      sybperl stuff?</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:psaar@nospam.fenar.ee">Arno
+-      Pedusaar</a></td>
+-
+-      <td>Donated his TDS4.2 code to the cause</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:misa@nospam.dntis.ro">Mihai
+-      Ibanescu</a></td>
+-
+-      <td>GNUified the packet</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:cts@nospam.internetcds.com">Craig
+-      Spannring</a></td>
+-
+-      <td>JDBC driver and CVS repository.</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:mark@nospam.champ.tstonramp.com">Mark
+-      Schaal</a></td>
+-
+-      <td>Cleaned up message handling, bug fixes, ctlib
+-      unittests</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:kevin@nospam.nol.org">Kevin
+-      Lyons</a></td>
+-
+-      <td>Various TDS bug fixes</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:tetherow@nospam.nol.org">Sam
+-      Tetherow</a></td>
+-
+-      <td>Various TDS bug fixes</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:geoff@nospam.farmline.com">Geoff
+-      Winkless</a></td>
+-
+-      <td>Lost connection stuff</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:KenASeymour@nospam.yahoo.com">Ken
+-      Seymour</a></td>
+-
+-      <td>ODBC Driver Fixes</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:gray@nospam.voicenet.com">Scott
+-      Gray</a></td>
+-
+-      <td>TDS 7.0 numeric support and bug fixes</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:bkline@nospam.rksystems.com">Bob
+-      Kline</a></td>
+-
+-      <td>NTEXT support</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:andrey@nospam.eller.cz">Koscheev
+-      Andrey</a></td>
+-
+-      <td>negative money patch</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:nicklaus@nospam.crusher.fnal.gov">Dennis
+-      Nicklaus</a></td>
+-
+-      <td>vxWorks port and fixes for dbdata() and SYBVARBINARY</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:breynolds@nospam.comtime.com">Brandon M.
+-      Reynolds</a></td>
+-
+-      <td>fix for arbitrarily large queries under dblib.</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:vorlon@nospam.netexpress.net">Steve
+-      Langasek</a></td>
+-
+-      <td>off by one fixes and autoconf byte size thing.</td>
+-    </tr>
+-
+-    <tr>
+-      <td><a href="mailto:mark@nospam.lilback.com">Mark J.
+-      Lilback</a></td>
+-
+-      <td>implementation of dbstrlen and dbstrcpy</td>
+-    </tr>
+-
+-    <tr>
+-      <td colspan="2">Thanks go to the folks at A2i, Inc. <a href=
+-      "http://www.a2i.com">http://www.a2i.com</a> for funding the
+-      development of dblib host file bulk copy and writetext
++  <h3 id="Who.is.responsible.for.FreeTDS">Who is responsible for FreeTDS?</h3>
++
++	<h4>Current contributors</h4>
++	<dl>
++	<dt><a href="mailto:brian@nospam.bruns.org">Brian
++      Bruns</a></dt>
++		<dd>Started this crazy thing</dd>
++	<dt><a href="mailto:jklowden@nospam.freetds.org">James K. Lowden</a></dt>
++		<dd>Project maintainer since 2003</dd>
++	<dt><a href="mailto:freddy77_A_gmail_D_com">Frediano Ziglio</a></dt>
++		<dd>Wrote great swaths of the ODBC driver and keeps the TDS
++		library up to date with protocol changes.  Also contributed
++		most of the current encryption logic. </dd>
++	</dl>
++      <P>For a more complete history, see AUTHORS in the distribution.  
++      Thanks also go to the folks at A2i, Inc. <a href=
++      "http://www.a2i.com">http://www.a2i.com</a> for funding the original
++      development of db-lib host file bulk copy and writetext
+       support, and to Dave Poyourow there for helping with the
+       debugging.</td>
+-    </tr>
+-  </table><!-- end generated table -->
+ 
+-  <p>(These addresses have been mangled to defy "spamaton" programs
+-  that mindlessly collect email addresses from the web. To send
++  <p>(To send
+   email to anyone listed above, delete the "nospam." part of the
+   address.)</p>
+ 
+-  <h3>Why LGPL license?</h3>
+-  	<a name="license" id="license"></a>
++  <h3 id="license">Why LGPL license?</h3>
+ 
+   <p>Brian Bruns started the project, and that's the choice he
+   made. LGPL was chosen because if you want a commercial client,
+-  you can buy them from Sybase, Microsoft or others. "I do believe
++  you can buy them from Sybase, Microsoft or others. &ldquo;I do believe
+   BSDish licenses are better in some cases, but not for something
+-  like this," he said.</p>
++  like this,&rdquo; he said.</p>
+   <hr />
+   <!-- documentation -->
+ 
+-  <h2>Documentation</h2>
+-  	<a name="documentation" id="documentation"></a>
++  <h2 id="documentation">Documentation</h2>
+ 
+   <h3>What sort of documentation is available?</h3>
+ 
+@@ -404,9 +278,9 @@
+     "reference/">Reference Manual</a> is a
+     beginning at an independent description of the client APIs and
+     the TDS layer.</li>
+-  </ul><a name="refman" id="refman"></a>
++  </ul>
+ 
+-  <h3>What about a Programmer's Reference Manual?</h3>
++  <h3 id="refman">What about a Programmer's Reference Manual?</h3>
+ 
+   <p>The best information is available from the vendors. FreeTDS
+   means to conform to the documented (and, in some cases,
+@@ -428,8 +302,7 @@
+     <!-- valid as at 12th november 2001 -->
+   </ul>
+ 
+-  <h3>Is there any documentation on the TDS protocol?</h3>
+-  	<a name="protocol" id="protocol"></a>
++  <h3 id="protocol">Is there any documentation on the TDS protocol?</h3>
+ 
+   <p>There is <a href="tds.html">preliminary
+   documentation</a> available. The most up to date version is in
+@@ -448,7 +321,6 @@
+   <h2>Implementation</h2>
+   	<a name="SYBASE" id="SYBASE"></a>
+ 
+-  <h3>What is this <code>SYBASE</code> environment variable?</h3>
+ 
+   <p>Many programs look for the <var>SYBASE</var> environment
+   variable in order to find the library's home. You will want to
+@@ -458,8 +330,7 @@
+   <tt>/usr/local/freetds/lib</tt>), then your <var>SYBASE</var>
+   variable would be set to <tt>/usr/local/freetds</tt>.</p>
+ 
+-  <h3>How do I install the RPM?</h3>
+-  	<a name="RPM" id="RPM"></a>
++  <h3 id="RPM">How do I install the RPM?</h3>
+ 
+   <p><tt>rpm -ivh freetds-0.52-1.i386.rpm</tt> (as root) will
+   install the libraries.</p>
+@@ -468,11 +339,11 @@
+   install the headers and other stuff needed to build other
+   stuff.</p>
+   <hr />
++  
+   <!-- Programming -->
+ 
+-  <h2>Programming: C++, Sybperl, SQSH, &amp; PHP</h2>
+-  	<a name="compiling" id="compiling"></a>
+-  
++  <h2 id="compiling">Programming: C++, Sybperl, SQSH, &amp; PHP</h2>
++
+   <h3>How do I compile Sybperl with FreeTDS?</h3>
+   <h3>How do I compile SQSH with FreeTDS?</h3>
+   <h3>How do I compile PHP 3 with FreeTDS?</h3>
+@@ -488,9 +359,8 @@
+     <p>An attempt to make a connection to a MS SQL server from PHP
+     would fail, leaving a message in the Apache error log:</p>
+     <pre>
+-        "connect: Network is unreachable
+-         DB-Library: Login incorrect"
+-</pre>
++        connect: Network is unreachable
++        DB-Library: Login incorrect</pre>
+ 
+     <p>The problem turned out to be a very simple one to fix. In
+     the php.ini file under the sybase section, there is a directive
+@@ -500,10 +370,10 @@
+     <p>After uncommenting this and setting it to a reasonable value
+     (ie. /usr/local/freetds/interfaces), things started
+     working.</p>
+-  </blockquote><a name="Which.API" id="Which.API"></a>
++  </blockquote>
+ 
+-  <h3>How should I choose among <tt>db-lib</tt>, <tt>ct-lib</tt>,
+-  and <tt>ODBC</tt></h3>
++  <h3 id="Which.API">How should I choose among <tt>db-lib</tt>, <tt>ct-lib</tt>,
++  and <tt>ODBC</tt>?</h3>
+ 
+   <p><tt>FreeTDS</tt> offers three client libraries and one
+   internal one (<tt>libtds</tt>). We generally encourage people to
+@@ -532,44 +402,14 @@
+   shared object of it if you want to.  It's just not done "out of the box"
+   by the distributed makefiles.  </p>
+ 
+-  <h3>Which Perl library should I use?</h3>
+-	<a name="Which.Perl.library.should.I.use" 
+-	     id="Which.Perl.library.should.I.use"></a>
++  <h3 id="Which.Perl.library.should.I.use">Which Perl library should I use?</h3>
+ 
+   <p>There are four options for using TDS and Perl to connect to a
+-  Sybase or MSSQL database, DBD::Sybase, DBD::ODBC, DBD::FreeTDS,
+-  and Sybperl.</p>
+-
+-  <p>From Mark Schaal:<br /></p>
+-
+-  <p>DBD::Sybase is the recommended option, and yes it does work
+-  with MSSQL. You will need to install the perl DBI module and the
+-  FreeTDS package, particularly the CTLib portion. Set your SYBASE
+-  environment variable to /usr/local/freetds and install
+-  DBD::Sybase. Don't worry too much if some of the tests fail. Do
+-  worry if the module doesn't compile. Make sure you have the most
+-  recent version of FreeTDS installed. You can check the <a href=
+-  "http://lists.ibiblio.org/pipermail/freetds/">mailing list
+-  archives</a> or ask the mailing list for help.</p>
+-
+-  <p>DBD::FreeTDS does not depend on the FreeTDS libraries. It is
+-  minimally functional but it is considered alpha software and is
+-  not being actively developed.</p>
+-
+-  <p>From <a href="mailto:mpeppler@peppler.org">Michael
+-  Peppler</a>:<br />
+-  Sybperl is a thin wrapper around the Sybase C APIs. It's a lot
+-  more mature than DBI/DBD::Sybase (I've been working on it for 9
+-  years :-) and it's maybe more natural to use for someone who
+-  already knows the Sybase APIs (or MS's DBlibrary). It's a little
+-  more powerful/flexible than DBI, though obviously less portable.
+-  It's still actively maintained and developed (by yours truly)</p>
+-
+-  <p>From Brian:<br />
+-  DBD::ODBC is the newest option available. Its primary advantage
+-  is not having to load another DBI driver if you already have
+-  DBI::ODBC load for other systems. On the downside, it may be a
+-  little less robust than DBD::Sybase.</p>
++  Sybase or Microsoft database, <tt>DBD::Sybase</tt>, <tt>DBD::ODBC</tt>,
++  <tt>DBD::FreeTDS,</tt>
++  and <tt>Sybperl</tt>. As of 2010, <tt>DBD::Sybase</tt> and <tt>DBD::ODBC</tt> are your best choices.  If
++  you need paramaterized queries on a Microsoft server, use <tt>DBD::ODBC</tt></p>
++
+ 
+   <h3 id="Are.there.any.known.issues">Are there any known issues?</h3>
+   <ul>
+@@ -583,8 +423,6 @@
+     <li>BCP does not support TDS 4.2. You must use a more modern
+     protocol version.</li>
+ 
+-    <li>Server-side cursors work only in ct-lib.</li>
+-
+     <li>ODBC lacks a client-side cursor implementation.</li>
+ 
+     <li>DBD::Sybase dynamic SQL placeholders don't work, pending a client-side SQL parser.  (The ODBC ones do.)</li>
+@@ -612,8 +450,7 @@
+ 	
+ 	<p>Very few programs actually need the missing functionality.  Parameterized ct-lib queries would benefit Perl DBD::Sybase users, but the functionality would require departing from Sybase's documented API.  MARS comes up because there must be thousands of people whom Microsoft has convinced they need it, but the benefits are meager compared to the complexity.  </p>
+ 	
+-  <h3>Why does each connection support only one query at a time?</h3>
+-	<a name="pending" id="pending"></a>
++  <h3 id="pending">Why does each connection support only one query at a time?</h3>
+ 
+   <p>If you are accustomed to programming with other database
+   servers, you may be surprised when you first encounter this
+@@ -673,15 +510,13 @@
+   "http://lists.ibiblio.org/pipermail/freetds/2003q3/013915.html">this
+   post</a> by Daniel Fazekas in the mailing list archives. 
+ 
+-  <h3>Is FreeTDS thread safe?</h3>
+-	<a name="thread.safe" id="thread.safe"></a>
++  <h3 id="thread.safe">Is FreeTDS thread safe?</h3>
+ 
+   <p>Different threads may all use separate connections without
+   interfering with each other. Threads may not share a DBPROCESS or
+   CS_CONNECTION without controlling access via a mutex.</p>
+ 
+-  <h3>Are there plans to implement the OpenServer protocol/library?</h3>
+-  	<a name="Are.there.plans.to.implement.the.OpenServer.protocol.library"></a>
++  <h3 id="Are.there.plans.to.implement.the.OpenServer.protocol.library">Are there plans to implement the OpenServer protocol/library?</h3>
+ 
+   <p>Not at this point, there is still much work to do on the
+   client protocol. But, <tt>libtdssrv</tt> will do the trick for
+@@ -691,8 +526,7 @@
+ 
+   <h2>Problems Running</h2>
+ 
+-  <h3>Output Parameters</h3>
+-	<a name="ms.output.parameters" id="ms.output.parameters"></a>
++  <h3 id="ms.output.parameters">Output Parameters</h3>
+ 	
+   <p><i>I'm not getting my output parameters returned, but I seem
+          to be doing everything right!</i> </p> 
+@@ -700,8 +534,7 @@
+   <p>Microsoft SQL Server 7 with SP3, and later versions, quietly changed (which is to say, broke) how they respond to queries that execute stored procedures with output parameters.  Earlier servers let you send a query like <font size="-1"><code>EXECUTE A @P OUTPUT</code></font> and fetch the output parameter as a special result row (technique varying by library).  Newer servers simply don't send back that data.  To elicit output parameters from them, you have to use the RPC protocols such as the db-lib <a href="reference/a00336.html#a129">dbrpcparam</a>.  
+   </p>
+          
+-  <h3>What does this <tt>unknown marker</tt> message mean?</h3>
+-	<a name="unknownmarker" id="unknownmarker"></a>  
++  <h3 id="unknownmarker">What does this <tt>unknown marker</tt> message mean?</h3>
+ 
+   <p>Most of the time, it means you're not using the right protocol
+   version. That <i>can</i> happen even if your <tt>./configure</tt>
+@@ -713,9 +546,9 @@
+   needed the environment variable anyway, please post a message to
+   the list and help us track it down.</p>
+ 
+-  <h3>What if I get a <tt><font size="+1">connection
+-      refused</font></tt> message?</h3>
+-	<a name="connectionrefused" id="connectionrefused"></a>
++  <h3 id="connectionrefused">
++	  What if I get a 
++  	<tt><font size="+1">connection refused</font></tt> message?</h3>
+ 
+   <p>You want to make sure:</p>
+ 
+@@ -810,10 +643,10 @@
+     </li>
+   </ol>
+ 
+-  <h3>The Microsoft SQL Server is listening, my configuration and
+-      environment are set up per question 6.1, but logins still
+-      fail.</h3>
+-	<a name="integratedsecurity" id="integratedsecurity"></a>
++  <h3 id="integratedsecurity">The Microsoft SQL Server is listening, 
++  	my configuration and
++	environment are set up per question 6.1, but logins still
++	fail.</h3>
+ 
+   <p>Microsoft supports two security models in three
+   permutations:</p>
+@@ -850,10 +683,9 @@
+ 
+   <h3 id="encrypted">Do encrypted connections work?</h3>
+   
+-  <p>Encrypted connections to Microsoft SQL Server 2008 using 
+-  FreeTDS 0.82 do not work.  Avoid them.  Patches welcome! </p>
++  <p>Yes.  Sometimes it's tricky, though.  </p>
+ 
+-  <h3>My <tt>text</tt> data are being truncated or are causing my
++  <h3 id="textdata">My <tt>text</tt> data are being truncated or are causing my
+   client to break.</h3>
+ 
+   <p>The <tt>text</tt> data type is different from <tt>char</tt>
+@@ -871,13 +703,11 @@
+   <pre class="screen">
+ <tt class="userinput">
+ 1&gt; <b>set <tt class="envar">textsize</tt> 10000</b></tt>
+-2&gt; <b>go</b>
+-</pre>
++2&gt; <b>go</b></pre>
+ 
+-  See also the &ldquo;<tt>text size</tt>&rdquo; option in <tt>freetds.conf</tt>.
++  See also the <tt>text size</tt> option in <tt>freetds.conf</tt>.
+ 
+-  <h3>My dates aren't formatted right!</h3>
+-  	<a name="dateformat" id="dateformat"></a>
++  <h3 id="dateformat">My dates aren't formatted right!</h3>
+ 
+   <p>Some dates turn out better than others.</p>
+ 
+@@ -934,7 +764,7 @@
+   <font size="-1">Updates and comments <a href=
+   "mailto:jklowden@freetds.org">FreeTDS FAQ Master</a> 
+   <br/>
+-    <i>$Id: faq.html,v 1.26 2010/12/31 04:12:07 jklowden Exp $</i>
++    <i>$Id: faq.html,v 1.27 2010/12/31 16:20:58 jklowden Exp $</i>
+ 	</font>
+ <hr/>
+   <p>
+
+commit 064e9b3d4c1d651d1ccf6018846620e8e4e38e24
+Author: jklowden <jklowden>
+Date:   Fri Dec 31 16:34:15 2010 +0000
+
+    updated per Frediano and corrected validation errors
+
+diff --git a/ChangeLog b/ChangeLog
+index d85b18d..6b7ceb5 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,7 @@
++Fri Dec 31 11:33:05 EST 2010	JK Lowden <jklowden@freetds.org>
++	* doc/api_status.txt doc/htdoc/faq.html
++	- updated per Frediano and corrected validation errors
++
+ Thu Dec 30 23:06:08 EST 2010	JK Lowden <jklowden@freetds.org>
+ 	* doc/tsql.txt doc/userguide.sgml doc/htdoc/faq.html
+ 	- updated to reflect current status
+@@ -3118,4 +3122,4 @@ Wed Jan  9 19:54:43 EST 2008	JK Lowden <jklowden@freetds.org>
+ 	* ChangeLog-0.82 added because of release
+ 	
+ $FreeTDS$
+-$Id: ChangeLog,v 1.3185 2010/12/31 04:12:07 jklowden Exp $
++$Id: ChangeLog,v 1.3186 2010/12/31 16:34:15 jklowden Exp $
+diff --git a/doc/api_status.txt b/doc/api_status.txt
+index f3584dd..d929148 100644
+--- a/doc/api_status.txt
++++ b/doc/api_status.txt
+@@ -1,7 +1,7 @@
+ #!/usr/pkg/bin/perl
+ # API status document
+ #
+-# $Id: api_status.txt,v 1.64 2010/09/14 14:40:43 jklowden Exp $s
++# $Id: api_status.txt,v 1.65 2010/12/31 16:34:15 jklowden Exp $s
+ #
+ # This tab-delimited file is a database of the "readiness" of the various
+ # APIs.  Please feel free to modify it if you notice something is missing or 
+@@ -269,6 +269,7 @@ dblib	bcp      	n/a				bcp_options	partial
+ dblib	bcp      	bcp_readfmt			(same)		OK
+ dblib	bcp      	bcp_sendrow			(same)		OK
+ dblib	bcp      	BCP_SETL			(same)		OK
++dblib	bcp      	bcp_writefmt			(same)		
+ dblib	browse   	dbcolbrowse			n/a		never
+ dblib	browse   	dbcolsource			n/a		never
+ dblib	browse   	dbfreequal			n/a		never
+diff --git a/doc/htdoc/faq.html b/doc/htdoc/faq.html
+index bfa23bc..e0a403e 100644
+--- a/doc/htdoc/faq.html
++++ b/doc/htdoc/faq.html
+@@ -3,7 +3,7 @@
+     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+ 
+ <html xmlns="http://www.w3.org/1999/xhtml">
+-<!-- $Id: faq.html,v 1.27 2010/12/31 16:20:58 jklowden Exp $ -->
++<!-- $Id: faq.html,v 1.28 2010/12/31 16:34:15 jklowden Exp $ -->
+ 
+ <head>
+   <meta name="generator" content=
+@@ -245,12 +245,12 @@
+ 		library up to date with protocol changes.  Also contributed
+ 		most of the current encryption logic. </dd>
+ 	</dl>
+-      <P>For a more complete history, see AUTHORS in the distribution.  
++      <p>For a more complete history, see AUTHORS in the distribution.  
+       Thanks also go to the folks at A2i, Inc. <a href=
+       "http://www.a2i.com">http://www.a2i.com</a> for funding the original
+       development of db-lib host file bulk copy and writetext
+       support, and to Dave Poyourow there for helping with the
+-      debugging.</td>
++      debugging.</p>
+ 
+   <p>(To send
+   email to anyone listed above, delete the "nospam." part of the
+@@ -679,7 +679,7 @@
+   recognized by the presence of a backslash (\) character in the
+   username. See the <a href=
+   "userguide/domains.htm">User Guide</a> for
+-  details. <a name="textdata" id="textdata"></a></p>
++  details. </p>
+ 
+   <h3 id="encrypted">Do encrypted connections work?</h3>
+   
+@@ -764,7 +764,7 @@
+   <font size="-1">Updates and comments <a href=
+   "mailto:jklowden@freetds.org">FreeTDS FAQ Master</a> 
+   <br/>
+-    <i>$Id: faq.html,v 1.27 2010/12/31 16:20:58 jklowden Exp $</i>
++    <i>$Id: faq.html,v 1.28 2010/12/31 16:34:15 jklowden Exp $</i>
+ 	</font>
+ <hr/>
+   <p>