tdbc::mysql
Diff
Not logged in

Differences From Artifact [f551b9b7cf]:

To Artifact [6a788939f4]:


8
9
10
11
12
13
14




15
16
17
18
19
20
21
 * Please refer to the file, 'license.terms' for the conditions on
 * redistribution of this file and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * $Id: $
 *
 *-----------------------------------------------------------------------------
 */





#include <tcl.h>
#include <tclOO.h>
#include <tdbc.h>

#include <stdio.h>
#include <string.h>







>
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 * Please refer to the file, 'license.terms' for the conditions on
 * redistribution of this file and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * $Id: $
 *
 *-----------------------------------------------------------------------------
 */

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <tcl.h>
#include <tclOO.h>
#include <tdbc.h>

#include <stdio.h>
#include <string.h>
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
 *	other objects that refer to it vanish.
 */

typedef struct ConnectionData {
    int refCount;		/* Reference count. */
    PerInterpData* pidata;	/* Per-interpreter data */
    MYSQL* mysqlPtr;		/* MySql connection handle */
    int nCollations;		/* Number of collations defined */
    int* collationSizes;	/* Character lengths indexed by collation ID */
    int flags;
} ConnectionData;

/*
 * Flags for the state of an MYSQL connection
 */







|







103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 *	other objects that refer to it vanish.
 */

typedef struct ConnectionData {
    int refCount;		/* Reference count. */
    PerInterpData* pidata;	/* Per-interpreter data */
    MYSQL* mysqlPtr;		/* MySql connection handle */
    unsigned int nCollations;	/* Number of collations defined */
    int* collationSizes;	/* Character lengths indexed by collation ID */
    int flags;
} ConnectionData;

/*
 * Flags for the state of an MYSQL connection
 */
1561
1562
1563
1564
1565
1566
1567
1568
1569

1570
1571
1572
1573
1574
1575
1576
    Tcl_Object thisObject = Tcl_ObjectContextObject(objectContext);
				/* The current connection object */
    ConnectionData* cdata = (ConnectionData*)
	Tcl_ObjectGetMetadata(thisObject, &connectionDataType);
				/* Instance data */
    int listLen;
    Tcl_Obj* objPtr;
    int collationNum;
    int i;


    if (objc <= 2) {
	Tcl_WrongNumArgs(interp, 2, objv, "{collationNum size}...");
	return TCL_ERROR;
    }
    if (Tcl_ListObjIndex(interp, objv[2], 0, &objPtr) != TCL_OK) {
	return TCL_ERROR;







|

>







1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
    Tcl_Object thisObject = Tcl_ObjectContextObject(objectContext);
				/* The current connection object */
    ConnectionData* cdata = (ConnectionData*)
	Tcl_ObjectGetMetadata(thisObject, &connectionDataType);
				/* Instance data */
    int listLen;
    Tcl_Obj* objPtr;
    unsigned int collationNum;
    int i;
    int t;

    if (objc <= 2) {
	Tcl_WrongNumArgs(interp, 2, objv, "{collationNum size}...");
	return TCL_ERROR;
    }
    if (Tcl_ListObjIndex(interp, objv[2], 0, &objPtr) != TCL_OK) {
	return TCL_ERROR;
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600

1601
1602
1603
1604
1605
1606
1607
	}
	if (listLen != 2) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("args must be 2-element "
						      "lists", -1));
	    return TCL_ERROR;
	}
	if (Tcl_ListObjIndex(interp, objv[i], 0, &objPtr) != TCL_OK
	    || Tcl_GetIntFromObj(interp, objPtr, &collationNum) != TCL_OK) {
	    return TCL_ERROR;
	}

	if (collationNum > cdata->nCollations) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("collations must be "
						      "in decreasing sequence",
						      -1));
	    return TCL_ERROR;
	}
	if ((Tcl_ListObjIndex(interp, objv[i], 1, &objPtr) != TCL_OK)







|


>







1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
	}
	if (listLen != 2) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("args must be 2-element "
						      "lists", -1));
	    return TCL_ERROR;
	}
	if (Tcl_ListObjIndex(interp, objv[i], 0, &objPtr) != TCL_OK
	    || Tcl_GetIntFromObj(interp, objPtr, &t) != TCL_OK) {
	    return TCL_ERROR;
	}
	collationNum = (unsigned int) t;
	if (collationNum > cdata->nCollations) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("collations must be "
						      "in decreasing sequence",
						      -1));
	    return TCL_ERROR;
	}
	if ((Tcl_ListObjIndex(interp, objv[i], 1, &objPtr) != TCL_OK)
1920
1921
1922
1923
1924
1925
1926





1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
static Tcl_Obj*
ResultDescToTcl(
    MYSQL_RES* result,		/* Result set description */
    int flags			/* Flags governing the conversion */
) {
    Tcl_Obj* retval = Tcl_NewObj();
    Tcl_HashTable names;	/* Hash table to resolve name collisions */





    Tcl_InitHashTable(&names, TCL_STRING_KEYS);
    if (result != NULL) {
	unsigned int fieldCount = mysql_num_fields(result);
	MYSQL_FIELD* fields = mysql_fetch_fields(result);
	unsigned int i;
	char numbuf[16];
	for (i = 0; i < fieldCount; ++i) {
	    int new;
            int count = 1;
	    Tcl_Obj* nameObj = Tcl_NewStringObj(fields[i].name,
						fields[i].name_length);
	    Tcl_HashEntry* entry =
		Tcl_CreateHashEntry(&names, fields[i].name, &new);
	    Tcl_IncrRefCount(nameObj);
	    while (!new) {
		count = (int) Tcl_GetHashValue(entry);
		++count;
		Tcl_SetHashValue(entry, (ClientData) count);
		sprintf(numbuf, "#%d", count);
		Tcl_AppendToObj(nameObj, numbuf, -1);
		entry = Tcl_CreateHashEntry(&names, Tcl_GetString(nameObj),







>
>
>
>
>







<
<
|
|
<
|
|







1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944


1945
1946

1947
1948
1949
1950
1951
1952
1953
1954
1955
static Tcl_Obj*
ResultDescToTcl(
    MYSQL_RES* result,		/* Result set description */
    int flags			/* Flags governing the conversion */
) {
    Tcl_Obj* retval = Tcl_NewObj();
    Tcl_HashTable names;	/* Hash table to resolve name collisions */
    Tcl_Obj* nameObj;		/* Name of a result column */
    int new;			/* Flag == 1 if a result column is unique */
    Tcl_HashEntry* entry;	/* Hash table entry for a column name */
    int count;			/* Number used to disambiguate a column name */

    Tcl_InitHashTable(&names, TCL_STRING_KEYS);
    if (result != NULL) {
	unsigned int fieldCount = mysql_num_fields(result);
	MYSQL_FIELD* fields = mysql_fetch_fields(result);
	unsigned int i;
	char numbuf[16];
	for (i = 0; i < fieldCount; ++i) {


	    nameObj = Tcl_NewStringObj(fields[i].name, fields[i].name_length);
	    Tcl_IncrRefCount(nameObj);

	    entry = Tcl_CreateHashEntry(&names, fields[i].name, &new);
	    count = 1;
	    while (!new) {
		count = (int) Tcl_GetHashValue(entry);
		++count;
		Tcl_SetHashValue(entry, (ClientData) count);
		sprintf(numbuf, "#%d", count);
		Tcl_AppendToObj(nameObj, numbuf, -1);
		entry = Tcl_CreateHashEntry(&names, Tcl_GetString(nameObj),
2886
2887
2888
2889
2890
2891
2892
2893

2894
2895
2896
2897
2898
2899
2900
    unsigned long* resultLengths = rdata->resultLengths;
				/* String lengths of the results */
    my_bool* resultNulls = rdata->resultNulls;
				/* Indicators that the results are null */
    unsigned char byte;		/* One byte extracted from a bit field */
    Tcl_WideInt bitVal;		/* Value of a bit field */
    int mysqlStatus;		/* Status return from MySQL */
    int i, j;


    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "varName");
	return TCL_ERROR;
    }









|
>







2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
    unsigned long* resultLengths = rdata->resultLengths;
				/* String lengths of the results */
    my_bool* resultNulls = rdata->resultNulls;
				/* Indicators that the results are null */
    unsigned char byte;		/* One byte extracted from a bit field */
    Tcl_WideInt bitVal;		/* Value of a bit field */
    int mysqlStatus;		/* Status return from MySQL */
    int i;
    unsigned int j;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "varName");
	return TCL_ERROR;
    }