tdbc::odbc

Check-in [e8009cbbf7]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Put back initalization of "buf" (which was removed in previous commit), so Tcl_UniCharToUtf() can do proper collapsing of surrogates (See: tclUtf.c). See also TIP #389
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e8009cbbf7e2916c8e28f395c59107c3eb7b36a50fcde9829966003226bb9996
User & Date: jan.nijtmans 2018-05-13 14:31:03.594
Original Comment: Put back initalization of "buf" (which was removed in previous commit), so Tcl_UniCharToUtf() can do proper collapsing of surrogates (See: [tclUtf.c|http://core.tcl.tk/tcl/artifact/18caccb00b6196fe?ln=158-179]). See also [TIP #389|http://core.tcl.tk/tips/doc/trunk/tip/389.md]
Context
2018-06-19
01:40
Do not attempt to retrieve row count from an operation that returns SQL_NO_DATA. Tolerate any error message from attempting to open a database with an incorrect driver specified. Allow SQLite to return 'serializable' in place of 'readcommitted' on both Unix and Windows. check-in: 34a5e8496c user: kbk tags: trunk
2018-05-13
14:31
Put back initalization of "buf" (which was removed in previous commit), so Tcl_UniCharToUtf() can do proper collapsing of surrogates (See: tclUtf.c). See also TIP #389 check-in: e8009cbbf7 user: jan.nijtmans tags: trunk
2018-05-12
16:51
ADVANCE VERSION TO 1.1.0. Integrate Christian Werner's changes to support systems (specifically, iodbc) that use a 32-bit SQLWCHAR, with runtime detection of the character format in use. This change enables the use of tdbc::odbc on BSD-derived systems and Apple platforms, where iodbc is the usual ODBC implementation. check-in: 11581e229b user: kbk tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to generic/tdbcodbc.c.
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
static void
DStringAppendWChars(
    Tcl_DString* ds,		/* Output string */
    SQLWCHAR* ws,		/* Input string */
    int len			/* Length of the input string in characters */
) {
    int i;
    char buf[TCL_UTF_MAX];

    if (sizeofSQLWCHAR == sizeof(unsigned short)) {
	unsigned short* ptr16 = (unsigned short*) ws;

	for (i = 0; i < len; ++i) {
	    unsigned int ch;
	    int bytes;

	    ch = ptr16[i];
	    if (ch > 0x10ffff) {
		ch = 0xfffd;
	    }
#if TCL_UTF_MAX >= 4
	    /* Collapse a surrogate pair, if any. */
	    if (ch >= 0xd800 && ch <= 0xdbff) {
		if (i + 1 < len) {
		    unsigned int ch2 = ptr16[i+1];

		    if (ch2 >= 0xdc00 && ch2 <= 0xdfff) {
			ch = ((ch & 0x3ff) << 10) + 0x10000 + (ch2 & 0x3ff);
			i++;
		    }
		}
	    }
#endif
	    bytes = Tcl_UniCharToUtf(ch, buf);
	    Tcl_DStringAppend(ds, buf, bytes);
	}
    } else {
	unsigned int* ptr32 = (unsigned int*) ws;

	for (i = 0; i < len; ++i) {
	    unsigned int ch;
	    int bytes;

	    ch = ptr32[i];
	    if (ch > 0x10ffff) {
		ch = 0xfffd;
	    }
#if TCL_UTF_MAX >= 4
	    /* Collapse a surrogate pair, if any. */
	    if (ch >= 0xd800 && ch <= 0xdbff) {
		if (i + 1 < len) {
		    unsigned int ch2 = ptr32[i+1];

		    if (ch2 >= 0xdc00 && ch2 <= 0xdfff) {
			ch = ((ch & 0x3ff) << 10) + 0x10000 + (ch2 & 0x3ff);
			i++;
		    }
		}
	    }
#endif
	    bytes = Tcl_UniCharToUtf(ch, buf);
	    Tcl_DStringAppend(ds, buf, bytes);
	}
    }
}

/*







|









<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<














<
<
<
<
<
<
<
<
<
<
<
<
<







781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
















798
799
800
801
802
803
804
805
806
807
808
809
810
811













812
813
814
815
816
817
818
static void
DStringAppendWChars(
    Tcl_DString* ds,		/* Output string */
    SQLWCHAR* ws,		/* Input string */
    int len			/* Length of the input string in characters */
) {
    int i;
    char buf[4] = "";

    if (sizeofSQLWCHAR == sizeof(unsigned short)) {
	unsigned short* ptr16 = (unsigned short*) ws;

	for (i = 0; i < len; ++i) {
	    unsigned int ch;
	    int bytes;

	    ch = ptr16[i];
















	    bytes = Tcl_UniCharToUtf(ch, buf);
	    Tcl_DStringAppend(ds, buf, bytes);
	}
    } else {
	unsigned int* ptr32 = (unsigned int*) ws;

	for (i = 0; i < len; ++i) {
	    unsigned int ch;
	    int bytes;

	    ch = ptr32[i];
	    if (ch > 0x10ffff) {
		ch = 0xfffd;
	    }













	    bytes = Tcl_UniCharToUtf(ch, buf);
	    Tcl_DStringAppend(ds, buf, bytes);
	}
    }
}

/*
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
    char* end = bytes + len;	/* End of UTF-8 representation */
    SQLWCHAR* retval;		/* Buffer to hold the converted string */
    SQLWCHAR* wcPtr;
    int shrink = 0;
    Tcl_UniChar ch = 0;

    len = (len + 1) * sizeofSQLWCHAR;
#if TCL_UTF_MAX > 4
    if (sizeofSQLWCHAR < sizeof(Tcl_UniChar)) {
	len *= 2;	/* doubled space for surrogates */
	shrink = 1;
    }
#endif
    retval = wcPtr = (SQLWCHAR*) ckalloc(len);

    if (sizeofSQLWCHAR == sizeof(unsigned short)) {
	unsigned short *ptr16 = (unsigned short*) wcPtr;

	while (bytes < end) {
	    unsigned int uch;







<




<







844
845
846
847
848
849
850

851
852
853
854

855
856
857
858
859
860
861
    char* end = bytes + len;	/* End of UTF-8 representation */
    SQLWCHAR* retval;		/* Buffer to hold the converted string */
    SQLWCHAR* wcPtr;
    int shrink = 0;
    Tcl_UniChar ch = 0;

    len = (len + 1) * sizeofSQLWCHAR;

    if (sizeofSQLWCHAR < sizeof(Tcl_UniChar)) {
	len *= 2;	/* doubled space for surrogates */
	shrink = 1;
    }

    retval = wcPtr = (SQLWCHAR*) ckalloc(len);

    if (sizeofSQLWCHAR == sizeof(unsigned short)) {
	unsigned short *ptr16 = (unsigned short*) wcPtr;

	while (bytes < end) {
	    unsigned int uch;
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933

	    if (Tcl_UtfCharComplete(bytes, end - bytes)) {
		bytes += Tcl_UtfToUniChar(bytes, &ch);
	    } else {
		ch = *bytes++ & 0x00ff;
	    }
	    uch = ch;
#if TCL_UTF_MAX == 4
	    if ((uch & 0xfc00) == 0xd800) {
		if (Tcl_UtfCharComplete(bytes, end - bytes)) {
		    len = Tcl_UtfToUniChar(bytes, &ch);
		    if ((ch & 0xfc00) == 0xdc00) {
			bytes += len;
			uch = (((uch & 0x3ff) << 10) | (ch & 0x3ff)) + 0x10000;
		    }







|







888
889
890
891
892
893
894
895
896
897
898
899
900
901
902

	    if (Tcl_UtfCharComplete(bytes, end - bytes)) {
		bytes += Tcl_UtfToUniChar(bytes, &ch);
	    } else {
		ch = *bytes++ & 0x00ff;
	    }
	    uch = ch;
#if TCL_UTF_MAX <= 4
	    if ((uch & 0xfc00) == 0xd800) {
		if (Tcl_UtfCharComplete(bytes, end - bytes)) {
		    len = Tcl_UtfToUniChar(bytes, &ch);
		    if ((ch & 0xfc00) == 0xdc00) {
			bytes += len;
			uch = (((uch & 0x3ff) << 10) | (ch & 0x3ff)) + 0x10000;
		    }