20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include <tcl.h>
#include <tclOO.h>
#include <tdbc.h>
#include <stdio.h>
#include <string.h>
#include "fakemysql.h"
/* Static data contained in this file */
TCL_DECLARE_MUTEX(mysqlMutex); /* Mutex protecting the global environment
* and its reference count */
static int mysqlRefCount = 0; /* Reference count on the global environment */
Tcl_LoadHandle mysqlLoadHandle = NULL;
/* Handle to the MySQL library */
unsigned long mysqlClientVersion;
/* Version number of MySQL */
/*
* Objects to create within the literal pool
*/
const char* LiteralValues[] = {
"",
|
>
|
>
>
>
>
>
<
<
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include <tcl.h>
#include <tclOO.h>
#include <tdbc.h>
#include <stdio.h>
#include <string.h>
#ifdef USE_DBLIB_STUBS
# include "fakemysql.h"
# include "mysqlCompat.c"
#else
# include <mysql.h>
# include "mysqlNative.c"
#endif /* USE_DBLIB_STUBS */
/* Static data contained in this file */
TCL_DECLARE_MUTEX(mysqlMutex); /* Mutex protecting the global environment
* and its reference count */
static int mysqlRefCount = 0; /* Reference count on the global environment */
Tcl_LoadHandle mysqlLoadHandle = NULL;
/* Handle to the MySQL library */
/*
* Objects to create within the literal pool
*/
const char* LiteralValues[] = {
"",
|
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
ISOL_SERIALIZABLE,
ISOL_NONE = -1
};
/* Declarations of static functions appearing in this file */
static MYSQL_BIND* MysqlBindAlloc(int nBindings);
static MYSQL_BIND* MysqlBindIndex(MYSQL_BIND* b, int i);
static void* MysqlBindAllocBuffer(MYSQL_BIND* b, int i, unsigned long len);
static void MysqlBindFreeBuffer(MYSQL_BIND* b, int i);
static void MysqlBindSetBufferType(MYSQL_BIND* b, int i,
enum enum_field_types t);
static void* MysqlBindGetBuffer(MYSQL_BIND* b, int i);
static unsigned long MysqlBindGetBufferLength(MYSQL_BIND* b, int i);
static void MysqlBindSetLength(MYSQL_BIND* b, int i, unsigned long* p);
static void MysqlBindSetIsNull(MYSQL_BIND* b, int i, my_bool* p);
static void MysqlBindSetError(MYSQL_BIND* b, int i, my_bool* p);
static MYSQL_FIELD* MysqlFieldIndex(MYSQL_FIELD* fields, int i);
static void TransferMysqlError(Tcl_Interp* interp, MYSQL* mysqlPtr);
static void TransferMysqlStmtError(Tcl_Interp* interp, MYSQL_STMT* mysqlPtr);
static Tcl_Obj* QueryConnectionOption(ConnectionData* cdata, Tcl_Interp* interp,
int optionNum);
static int ConfigureConnection(ConnectionData* cdata, Tcl_Interp* interp,
int objc, Tcl_Obj *const objv[], int skip);
|
<
<
<
<
<
<
|
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
ISOL_SERIALIZABLE,
ISOL_NONE = -1
};
/* Declarations of static functions appearing in this file */
static MYSQL_BIND* MysqlBindAlloc(int nBindings);
static void MysqlBindSetBufferType(MYSQL_BIND* b, int i,
enum enum_field_types t);
static unsigned long MysqlBindGetBufferLength(MYSQL_BIND* b, int i);
static void MysqlBindSetLength(MYSQL_BIND* b, int i, unsigned long* p);
static void MysqlBindSetIsNull(MYSQL_BIND* b, int i, my_bool* p);
static void MysqlBindSetError(MYSQL_BIND* b, int i, my_bool* p);
static void TransferMysqlError(Tcl_Interp* interp, MYSQL* mysqlPtr);
static void TransferMysqlStmtError(Tcl_Interp* interp, MYSQL_STMT* mysqlPtr);
static Tcl_Obj* QueryConnectionOption(ConnectionData* cdata, Tcl_Interp* interp,
int optionNum);
static int ConfigureConnection(ConnectionData* cdata, Tcl_Interp* interp,
int objc, Tcl_Obj *const objv[], int skip);
|
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
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
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
|
*
*-----------------------------------------------------------------------------
*/
static MYSQL_BIND*
MysqlBindAlloc(int nBindings)
{
int size;
void* retval = NULL;
if (mysqlClientVersion >= 50100) {
size = sizeof(struct st_mysql_bind_51);
} else {
size = sizeof(struct st_mysql_bind_50);
}
size *= nBindings;
if (size != 0) {
retval = ckalloc(size);
memset(retval, 0, size);
}
return (MYSQL_BIND*) retval;
}
/*
*-----------------------------------------------------------------------------
*
* MysqlBindIndex --
*
* Returns a pointer to one of an array of MYSQL_BIND objects
*
*-----------------------------------------------------------------------------
*/
static MYSQL_BIND*
MysqlBindIndex(
MYSQL_BIND* b, /* Binding array to alter */
int i /* Index in the binding array */
) {
if (mysqlClientVersion >= 50100) {
return (MYSQL_BIND*)(((struct st_mysql_bind_51*) b) + i);
} else {
return (MYSQL_BIND*)(((struct st_mysql_bind_50*) b) + i);
}
}
/*
*-----------------------------------------------------------------------------
*
* MysqlBindAllocBuffer --
*
* Allocates the buffer in a MYSQL_BIND object
*
* Results:
* Returns a pointer to the allocated buffer
*
*-----------------------------------------------------------------------------
*/
static void*
MysqlBindAllocBuffer(
MYSQL_BIND* b, /* Pointer to a binding array */
int i, /* Index into the array */
unsigned long len /* Length of the buffer to allocate or 0 */
) {
void* block = NULL;
if (len != 0) {
block = ckalloc(len);
}
if (mysqlClientVersion >= 50100) {
((struct st_mysql_bind_51*) b)[i].buffer = block;
((struct st_mysql_bind_51*) b)[i].buffer_length = len;
} else {
((struct st_mysql_bind_50*) b)[i].buffer = block;
((struct st_mysql_bind_50*) b)[i].buffer_length = len;
}
return block;
}
/*
*-----------------------------------------------------------------------------
*
* MysqlBindFreeBuffer --
*
* Frees trhe buffer in a MYSQL_BIND object
*
* Results:
* None.
*
* Side effects:
* Buffer is returned to the system.
*
*-----------------------------------------------------------------------------
*/
static void
MysqlBindFreeBuffer(
MYSQL_BIND* b, /* Pointer to a binding array */
int i /* Index into the array */
) {
if (mysqlClientVersion >= 50100) {
struct st_mysql_bind_51* bindings = (struct st_mysql_bind_51*) b;
if (bindings[i].buffer) {
ckfree(bindings[i].buffer);
bindings[i].buffer = NULL;
}
bindings[i].buffer_length = 0;
} else {
struct st_mysql_bind_50* bindings = (struct st_mysql_bind_50*) b;
if (bindings[i].buffer) {
ckfree(bindings[i].buffer);
bindings[i].buffer = NULL;
}
bindings[i].buffer_length = 0;
}
}
/*
*-----------------------------------------------------------------------------
*
* MysqlBindGetBufferLength, MysqlBindSetBufferType, MysqlBindGetBufferType,
* MysqlBindSetLength, MysqlBindSetIsNull,
* MysqlBindSetError --
*
* Access the fields of a MYSQL_BIND object
*
*-----------------------------------------------------------------------------
*/
static void*
MysqlBindGetBuffer(
MYSQL_BIND* b, /* Binding array to alter */
int i /* Index in the binding array */
) {
if (mysqlClientVersion >= 50100) {
return ((struct st_mysql_bind_51*) b)[i].buffer;
} else {
return ((struct st_mysql_bind_50*) b)[i].buffer;
}
}
static unsigned long
MysqlBindGetBufferLength(
MYSQL_BIND* b, /* Binding array to alter */
int i /* Index in the binding array */
) {
if (mysqlClientVersion >= 50100) {
return ((struct st_mysql_bind_51*) b)[i].buffer_length;
} else {
return ((struct st_mysql_bind_50*) b)[i].buffer_length;
}
}
static enum enum_field_types
MysqlBindGetBufferType(
MYSQL_BIND* b, /* Binding array to alter */
int i /* Index in the binding array */
) {
if (mysqlClientVersion >= 50100) {
return ((struct st_mysql_bind_51*) b)[i].buffer_type;
} else {
return ((struct st_mysql_bind_50*) b)[i].buffer_type;
}
}
static void
MysqlBindSetBufferType(
MYSQL_BIND* b, /* Binding array to alter */
int i, /* Index in the binding array */
enum enum_field_types t /* Buffer type to assign */
) {
if (mysqlClientVersion >= 50100) {
((struct st_mysql_bind_51*) b)[i].buffer_type = t;
} else {
((struct st_mysql_bind_50*) b)[i].buffer_type = t;
}
}
static void
MysqlBindSetLength(
MYSQL_BIND* b, /* Binding array to alter */
int i, /* Index in the binding array */
unsigned long* p /* Length pointer to assign */
) {
if (mysqlClientVersion >= 50100) {
((struct st_mysql_bind_51*) b)[i].length = p;
} else {
((struct st_mysql_bind_50*) b)[i].length = p;
}
}
static void
MysqlBindSetIsNull(
MYSQL_BIND* b, /* Binding array to alter */
int i, /* Index in the binding array */
my_bool* p /* "Is null" indicator pointer to assign */
) {
if (mysqlClientVersion >= 50100) {
((struct st_mysql_bind_51*) b)[i].is_null = p;
} else {
((struct st_mysql_bind_50*) b)[i].is_null = p;
}
}
static void
MysqlBindSetError(
MYSQL_BIND* b, /* Binding array to alter */
int i, /* Index in the binding array */
my_bool* p /* Error indicator pointer to assign */
) {
if (mysqlClientVersion >= 50100) {
((struct st_mysql_bind_51*) b)[i].error = p;
} else {
((struct st_mysql_bind_50*) b)[i].error = p;
}
}
/*
*-----------------------------------------------------------------------------
*
* MysqlFieldIndex --
*
* Return a pointer to a given MYSQL_FIELD structure in an array
*
* The MYSQL_FIELD structure grows by one pointer between 5.0 and 5.1.
* Our code never creates a MYSQL_FIELD, nor does it try to access that
* pointer, so we handle things simply by casting the types.
*
*-----------------------------------------------------------------------------
*/
static MYSQL_FIELD*
MysqlFieldIndex(MYSQL_FIELD* fields,
/* Pointer to the array*/
int i) /* Index in the array */
{
MYSQL_FIELD* retval;
if (mysqlClientVersion >= 50100) {
retval = (MYSQL_FIELD*)(((struct st_mysql_field_51*) fields)+i);
} else {
retval = (MYSQL_FIELD*)(((struct st_mysql_field_50*) fields)+i);
}
return retval;
}
/*
*-----------------------------------------------------------------------------
*
* TransferMysqlError --
*
* Obtains the error message, SQL state, and error number from the
|
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
|
*
*-----------------------------------------------------------------------------
*/
static MYSQL_BIND*
MysqlBindAlloc(int nBindings)
{
void* retval = NULL;
int size = nBindings * MysqlGetBindSize();
if (size != 0) {
retval = ckalloc(size);
memset(retval, 0, size);
}
return (MYSQL_BIND*) retval;
}
/*
*-----------------------------------------------------------------------------
*
* TransferMysqlError --
*
* Obtains the error message, SQL state, and error number from the
|
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
|
/*
* Initialize the MySQL library if this is the first interp using it
*/
Tcl_MutexLock(&mysqlMutex);
if (mysqlRefCount == 0) {
if ((mysqlLoadHandle = MysqlInitStubs(interp)) == NULL) {
Tcl_MutexUnlock(&mysqlMutex);
return TCL_ERROR;
}
mysql_library_init(0, NULL, NULL);
mysqlClientVersion = mysql_get_client_version();
}
++mysqlRefCount;
Tcl_MutexUnlock(&mysqlMutex);
/*
* TODO: mysql_thread_init, and keep a TSD reference count of users.
*/
|
>
>
|
|
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
|
/*
* Initialize the MySQL library if this is the first interp using it
*/
Tcl_MutexLock(&mysqlMutex);
if (mysqlRefCount == 0) {
#ifdef USE_DBLIB_STUBS
if ((mysqlLoadHandle = MysqlInitStubs(interp)) == NULL) {
Tcl_MutexUnlock(&mysqlMutex);
return TCL_ERROR;
}
#endif /* USE_DBLIB_STUBS */
mysql_library_init(0, NULL, NULL);
MysqlSaveClientVersion(mysql_get_client_version());
}
++mysqlRefCount;
Tcl_MutexUnlock(&mysqlMutex);
/*
* TODO: mysql_thread_init, and keep a TSD reference count of users.
*/
|
3754
3755
3756
3757
3758
3759
3760
|
Tcl_MutexLock(&mysqlMutex);
if (--mysqlRefCount == 0) {
mysql_library_end();
Tcl_FSUnloadFile(NULL, mysqlLoadHandle);
}
Tcl_MutexUnlock(&mysqlMutex);
}
|
>
>
>
|
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
|
Tcl_MutexLock(&mysqlMutex);
if (--mysqlRefCount == 0) {
mysql_library_end();
Tcl_FSUnloadFile(NULL, mysqlLoadHandle);
}
Tcl_MutexUnlock(&mysqlMutex);
}
/* vim: set ts=8 sw=4 sts=4 noet: */
|