aboutsummaryrefslogtreecommitdiffstats
path: root/databases/mysqltcl/files/patch-aa
blob: a801304bc85dc4c875508ece56905be4bb37938a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
--- mysqltcl.c  Mon Jul  6 11:35:17 1998
+++ mysqltcl.c  Wed Jul 12 17:46:20 2000
@@ -34,7 +34,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <unistd.h>
-
+#include <stdlib.h>
 
 #define MYSQL_HANDLES      15  /* Default number of handles available. */
 #define MYSQL_BUFF_SIZE    1024    /* Conversion buffer size for various needs. */
@@ -60,7 +60,7 @@
 #define MYSQL_HPREFIX_LEN 5
 
 /* Array for status info, and its elements. */
-static char *MysqlStatusArr = "mysqlstatus";
+#define MysqlStatusArr "mysqlstatus"
 #define MYSQL_STATUS_CODE "code"
 #define MYSQL_STATUS_CMD  "command"
 #define MYSQL_STATUS_MSG  "message"
@@ -686,7 +686,6 @@
 Mysqltcl_Init (interp)
     Tcl_Interp *interp;
 {
-  int i;
   char nbuf[MYSQL_SMALL_SIZE];
 
   /*
@@ -742,7 +739,7 @@
    * If this message appears you must change the source code and recompile.
    */
   if (strlen (MysqlHandlePrefix) == MYSQL_HPREFIX_LEN)
-    return TCL_OK;
+    return Tcl_PkgProvide(interp, "mysql", "1.53");
   else
     {
       fprintf (stderr, "*** mysqltcl (mysqltcl.c): handle prefix inconsistency!\n") ;
@@ -921,13 +917,13 @@
 
   if ((MysqlHandle[hand].result = mysql_store_result (MysqlHandle[hand].mysql)) == NULL)
     {
-      (void)strcpy (interp->result, "-1") ;
+      Tcl_SetObjResult(interp, Tcl_NewIntObj(-1));
     }
   else
     {
       MysqlHandle[hand].res_count = mysql_num_rows (MysqlHandle[hand].result) ;
       MysqlHandle[hand].col_count = mysql_num_fields (MysqlHandle[hand].result) ;
-      (void)sprintf (interp->result, "%d", MysqlHandle[hand].res_count) ;
+      Tcl_SetObjResult(interp, Tcl_NewIntObj(MysqlHandle[hand].res_count));
     }
 
   return TCL_OK;
@@ -1073,7 +1069,7 @@
    MysqlHandle[hand].res_count = total - row;
       }
 
-    (void)sprintf (interp->result, "%d", MysqlHandle[hand].res_count) ;
+    Tcl_SetObjResult(interp, Tcl_NewIntObj(MysqlHandle[hand].res_count));
     return TCL_OK;
 }
 
@@ -1244,7 +1240,7 @@
     {
     case MYSQL_INFNAME_OPT:
     case MYSQL_INFNAMEQ_OPT:
-      strcpy (interp->result, MysqlHandle[hand].database) ;
+      Tcl_SetResult(interp, MysqlHandle[hand].database, TCL_STATIC);
       break ;
     case MYSQL_INFTABLES_OPT:
       if ((list = mysql_list_tables (MysqlHandle[hand].mysql,(char*)NULL)) == NULL)
@@ -1259,7 +1255,7 @@
       break ;
     case MYSQL_INFHOST_OPT:
     case MYSQL_INFHOSTQ_OPT:
-      strcpy (interp->result, MysqlHandle[hand].host) ;
+      Tcl_SetResult(interp, MysqlHandle[hand].host, TCL_STATIC);
       break ;
     case MYSQL_INFLIST_OPT:
       if ((list = mysql_list_dbs (MysqlHandle[hand].mysql,(char*)NULL)) == NULL)
@@ -1299,8 +1295,6 @@
   int count ;
   int hand ;
   int idx ;
-  MYSQL_RES* list ;
-  MYSQL_ROW row ;
 
 
   /* We can't fully check the handle at this stage. */
@@ -1342,19 +1336,20 @@
     {
     case MYSQL_RESROWS_OPT:
     case MYSQL_RESROWSQ_OPT:
-      sprintf (interp->result, "%d", MysqlHandle[hand].res_count) ;
+      count = MysqlHandle[hand].res_count;
       break ;
     case MYSQL_RESCOLS_OPT:
     case MYSQL_RESCOLSQ_OPT:
-      sprintf (interp->result, "%d", MysqlHandle[hand].col_count) ;
+      count = MysqlHandle[hand].col_count;
       break ;
     case MYSQL_RESCUR_OPT:
     case MYSQL_RESCURQ_OPT:
-      sprintf (interp->result, "%d", mysql_num_rows (MysqlHandle[hand].result)
-          - MysqlHandle[hand].res_count) ;
+      count = mysql_num_rows (MysqlHandle[hand].result)
+               - MysqlHandle[hand].res_count;
     default:
-      ;
+      return TCL_OK; /* none of the above -- return without touching result */
     }
+  Tcl_SetObjResult(interp, Tcl_NewIntObj(count));
   return TCL_OK ;
 }
 
@@ -1500,8 +1495,12 @@
   int hi;
   char* hp ;
   int numeric ;
-  char* res ;
-  
+  register short res;
+
+  static const char *states[] = {
+    "NOT_A_HANDLE", "UNCONNECTED", "CONNECTED", "IN_USE", "RESULT_PENDING"
+  };
+
   if (mysql_prologue(interp, argc, argv, 2, NULL, "?-numeric? handle") < 0)
     return TCL_ERROR;
 
@@ -1511,17 +1510,18 @@
   hp = (numeric)?argv[2]:argv[1] ;
 
   if (HSYNTAX(hp,hi) < 0)
-    res = (numeric)?"0":"NOT_A_HANDLE" ;
+    res = 0;
   else if (MysqlHandle[hi].connection == 0)
-    res = (numeric)?"1":"UNCONNECTED" ;
+    res = 1;
   else if (MysqlHandle[hi].database[0] == '\0')
-    res = (numeric)?"2":"CONNECTED" ;
+    res = 2;
   else if (MysqlHandle[hi].result == NULL)
-    res = (numeric)?"3":"IN_USE" ;
+    res = 3;
   else
-    res = (numeric)?"4":"RESULT_PENDING" ;
+    res = 4;
 
-  (void)strcpy (interp->result, res) ;
+  if (numeric) Tcl_SetObjResult(interp, Tcl_NewIntObj(res));
+  else Tcl_SetResult(interp, (char *)states[res], TCL_STATIC);
   return TCL_OK ;
 }
 
@@ -1543,7 +1543,6 @@
      char       **argv;
 {
   int hand;
-  char* res ;
   MYSQL* mysql;
   
   if ((hand = mysql_prologue(interp, argc, argv, 2, get_handle_conn,
@@ -1552,7 +1551,7 @@
 
   mysql = MysqlHandle[hand].mysql;
 
-  (void)sprintf (interp->result, "%d", mysql_insert_id(mysql)) ;
+  Tcl_SetObjResult(interp, Tcl_NewIntObj(mysql_insert_id(mysql)));
 
   return TCL_OK;
 }