Skip to Content.
Sympa Menu

freetds - Re: [freetds] Status of support for Time type

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Eduard Heimann <eheimann AT pe-fittinge.de>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Status of support for Time type
  • Date: Sun, 05 May 2013 10:08:05 +0200

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/04/13 18:51, James K. Lowden wrote:
> On Sat, 04 May 2013 18:04:03 +0200 Eduard Heimann <eheimann AT pe-fittinge.de>
> wrote:
>
>> Please help me to integrate my fix into the mainline of freetds. I have
>> no experience with this kind of distributed development.
>
> Thank you for reporting the problem and developing a fix. :-)
>
> The most developer-friendly way to supply a patch is with "git diff". If
> you're not using git, "diff -u oldfile newfile > file.diff" works, too.
>
> As a last resort, simply attached your modified file to a message you post
> here.
>
> It helps if the file is an *attachment* because email systems often wrap
> long lines in the code, something that can be undone only by hand.
>
> Provided we agree with with your assessment and solution, we'll update the
> master git branch. Usually someone gets around to it within a week or so.
>
>
> --jkl _______________________________________________ FreeTDS mailing list
> FreeTDS AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds
>
>

Description of this fix for freetds:
BCP-copying wide rows (>255 bytes, from file into server-table) results in an
error in bcp_sendrow() and a bogus state in Sybase SQL Server. Tested against
Server 10.2/32bit and Server 12.4/64bit.
This patch is a result of reverse-engineering Sybase's bcp-library on
datastream level.


- --
Eduard Heimann, Hörmannsdorf 9, D-94104 Tittling
Tel: 08504 955249 Fax: 08504 955248
Mail mailto:eheimann AT pe-fittinge.de Web: http://www.pe-fittinge.de
Eine Haustüre ohne Schloß ist wie eMail ohne http://www.GNUPG.org
GPG key ID: 0xB542BD21 http://keyserver.ubuntu.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlGGE2UACgkQUzMNXFvaJEbHPACeI+qOPGQxWNRnCY4/wyN4lOx4
KvIAn06JlDuVwLo+qVK3dpXXMO/s1mLq
=p3R8
-----END PGP SIGNATURE-----
diff -ur freetds-0.91.dev.20120624-bcpfix/include/tds.h freetds-0.91.dev.20120624/include/tds.h
--- freetds-0.91.dev.20120624-bcpfix/include/tds.h	2013-01-08 20:46:30.000000000 +0100
+++ freetds-0.91.dev.20120624/include/tds.h	2011-08-12 18:29:36.000000000 +0200
@@ -716,13 +716,13 @@
 			x==SYBVOID      || \
 			x==SYBUNIQUE)
 #define is_nullable_type(x) ( \
-		     x==SYBBITN      || \
+			x==SYBBITN      || \
                      x==SYBINTN      || \
                      x==SYBFLTN      || \
                      x==SYBMONEYN    || \
                      x==SYBDATETIMN  || \
                      x==SYBVARCHAR   || \
-                     /*EVEVEV x==SYBBINARY    ||*/ \
+                     x==SYBBINARY    || \
                      x==SYBVARBINARY || \
                      x==SYBTEXT      || \
                      x==SYBNTEXT     || \
diff -ur freetds-0.91.dev.20120624-bcpfix/src/tds/bulk.c freetds-0.91.dev.20120624/src/tds/bulk.c
--- freetds-0.91.dev.20120624-bcpfix/src/tds/bulk.c	2013-05-05 08:42:37.000000000 +0200
+++ freetds-0.91.dev.20120624/src/tds/bulk.c	2011-06-02 21:19:30.000000000 +0200
@@ -584,23 +584,19 @@
 				if ((get_col_data(bcpinfo, bindcol, offset)) != TDS_SUCCEED) {
 					return TDS_FAIL;
 				}
-				/* maybe the same code in bcp_moretext ? */
-				tdsdump_log(TDS_DBG_INFO1, "is_blob_type col=%u datalen=%u data=%x\n", 
-				    	    	    	i, bindcol->bcp_column_data->datalen, bindcol->bcp_column_data->data);
-    	    	    	    	if (bindcol->bcp_column_data->datalen && bindcol->bcp_column_data->data) {
-				    /* unknown but zero */
-				    tds_put_smallint(tds, 0);
-				    tds_put_byte(tds, bindcol->column_type);
-				    tds_put_byte(tds, 0xff - blob_cols);
-				    /*
-				     * offset of txptr we stashed during variable
-				     * column processing 
-				     */
-				    tds_put_smallint(tds, bindcol->column_textpos);
-				    tds_put_int(tds, bindcol->bcp_column_data->datalen);
-				    tds_put_n(tds, bindcol->bcp_column_data->data, bindcol->bcp_column_data->datalen);
-				} /*else server table gets into very strange&broken state */
+				/* unknown but zero */
+				tds_put_smallint(tds, 0);
+				tds_put_byte(tds, bindcol->column_type);
+				tds_put_byte(tds, 0xff - blob_cols);
+				/*
+				 * offset of txptr we stashed during variable
+				 * column processing 
+				 */
+				tds_put_smallint(tds, bindcol->column_textpos);
+				tds_put_int(tds, bindcol->bcp_column_data->datalen);
+				tds_put_n(tds, bindcol->bcp_column_data->data, bindcol->bcp_column_data->datalen);
 				blob_cols++;
+
 			}
 		}
 	}
@@ -680,9 +676,9 @@
 static int
 tds_bcp_add_variable_columns(TDSBCPINFO *bcpinfo, tds_bcp_get_col_data get_col_data, tds_bcp_null_error null_error, int offset, TDS_UCHAR* rowbuffer, int start, int *pncols)
 {
-	TDS_USMALLINT offsets[256];
-	unsigned int i, row_pos;
-	unsigned int ncols = 0;
+	TDS_SMALLINT offsets[256];
+	int i, row_pos;
+	int ncols = 0;
 
 	assert(bcpinfo);
 	assert(rowbuffer);
@@ -709,7 +705,7 @@
 	tdsdump_log(TDS_DBG_FUNC, "%4s %8s %8s %8s\n", "col", "ncols", "row_pos", "cpbytes");
 
 	for (i = 0; i < bcpinfo->bindinfo->num_cols; i++) {
-		unsigned int cpbytes = 0;
+		int cpbytes = 0;
 		TDSCOLUMN *bcpcol = bcpinfo->bindinfo->columns[i];
 
 		/*
@@ -776,27 +772,16 @@
 		ncols--;	/* trailing NULL columns are not sent and are not included in the offset table */
 
 	if (ncols) {
-/*EVEVEVE*/
 		TDS_UCHAR *padj = rowbuffer + row_pos;
-		TDS_UCHAR *poff = padj;
-		unsigned int pfx_top = offsets[ncols] / 256;
-		
-		*poff++ = ncols + 1;
-		/* this is some kind of run-length-prefix encoding */
-		while (pfx_top) {
-			unsigned int n_pfx = 0;
-			unsigned int n;
-		    for (n = 0; n <= ncols ; ++n)
-		    	if ((offsets[n] / 256) < pfx_top)
-		    	    ++n_pfx;
-			*poff++ = n_pfx + 1;
-		    --pfx_top;
-		}
-		    
-		tdsdump_log(TDS_DBG_FUNC, "ncols=%u padj=%x poff=%x [%u]\n", ncols, padj, poff, offsets[ncols]);
+		TDS_UCHAR *poff = offsets[ncols] > 0xFF? padj + ncols + 1 : padj;
 
-		for (i=0; i <= ncols; i++)
+		*padj++ = 1 + ncols;
+		*poff++ = 1 + ncols;
+		
+		for (i=0; i <= ncols; i++) {
+			padj[i] = offsets[ncols-i] >> 8;
 			poff[i] = offsets[ncols-i] & 0xFF;
+		}
 		row_pos = (int)(poff + ncols + 1 - rowbuffer);
 	}




Archive powered by MHonArc 2.6.24.

Top of Page