summaryrefslogtreecommitdiff
path: root/databases/sybtcl/files/patch-generic_sybtcl.c
blob: 84acf3f29041964f986a6f85b1729b2ee3a66252 (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
--- generic/sybtcl.c	2000-08-30 20:24:18.000000000 -0400
+++ generic/sybtcl.c	2007-10-12 16:54:36.000000000 -0400
@@ -178,5 +178,6 @@
 #endif
 
-#include "tcl.h"
+#include <strings.h>
+#include <tcl.h>
 
 
@@ -279,4 +280,12 @@
 #endif
 
+#ifndef CS_INTERNAL
+#define CS_INTERNAL	/* Not defined by FreeTDS */
+#endif
+
+#ifndef TDS_DEF_CHARSET
+#define TDS_DEF_CHARSET "iso_1" /* Not defined by Sybase */
+#endif
+
 typedef struct SybTclProcs {	/* struct for handle entries */
     int         in_use;		/* if this entry is opened */
@@ -393,5 +402,5 @@
 #else
 
-extern void * malloc();
+#include <stdlib.h>
 
 #endif
@@ -428,22 +437,22 @@
 /* prototypes for all tcl command functions */
 
-EXTERN Sybtcl_Init      _ANSI_ARGS_((Tcl_Interp *interp));
-EXTERN Sybtcl_SafeInit  _ANSI_ARGS_((Tcl_Interp *interp));
+EXTERN int Sybtcl_Init      _ANSI_ARGS_((Tcl_Interp *interp));
+EXTERN int Sybtcl_SafeInit  _ANSI_ARGS_((Tcl_Interp *interp));
 
-extern Tcl_ObjCmdProc  Sybtcl_Connect;
-extern Tcl_ObjCmdProc  Sybtcl_ErrHandler;
-extern Tcl_ObjCmdProc  Sybtcl_MsgHandler;
-extern Tcl_ObjCmdProc  Sybtcl_Money;
-extern Tcl_ObjCmdProc  Sybtcl_Use;
-extern Tcl_ObjCmdProc  Sybtcl_Sql;
-extern Tcl_ObjCmdProc  Sybtcl_Poll;
-extern Tcl_ObjCmdProc  Sybtcl_Next;
-extern Tcl_ObjCmdProc  Sybtcl_Cols;
-extern Tcl_ObjCmdProc  Sybtcl_Cancel;
-extern Tcl_ObjCmdProc  Sybtcl_Close;
-extern Tcl_ObjCmdProc  Sybtcl_Retval;
-extern Tcl_ObjCmdProc  Sybtcl_Wrtext;
-extern Tcl_ObjCmdProc  Sybtcl_Rdtext;
-extern Tcl_ObjCmdProc  Sybtcl_Event;
+static Tcl_ObjCmdProc  Sybtcl_Connect;
+static Tcl_ObjCmdProc  Sybtcl_ErrHandler;
+static Tcl_ObjCmdProc  Sybtcl_MsgHandler;
+static Tcl_ObjCmdProc  Sybtcl_Money;
+static Tcl_ObjCmdProc  Sybtcl_Use;
+static Tcl_ObjCmdProc  Sybtcl_Sql;
+static Tcl_ObjCmdProc  Sybtcl_Poll;
+static Tcl_ObjCmdProc  Sybtcl_Next;
+static Tcl_ObjCmdProc  Sybtcl_Cols;
+static Tcl_ObjCmdProc  Sybtcl_Cancel;
+static Tcl_ObjCmdProc  Sybtcl_Close;
+static Tcl_ObjCmdProc  Sybtcl_Retval;
+static Tcl_ObjCmdProc  Sybtcl_Wrtext;
+static Tcl_ObjCmdProc  Sybtcl_Rdtext;
+static Tcl_ObjCmdProc  Sybtcl_Event;
 
 
@@ -461,8 +470,10 @@
 			Tcl_Interp *interp));
 
+#ifdef POLLED_EVENTS
 static int dbEventProc _ANSI_ARGS_((Tcl_Event *evPtr, int flags));
 static void dbSetupProc _ANSI_ARGS_((ClientData cd_hand, int flags));
 static void dbCheckProc _ANSI_ARGS_((ClientData cd_hand, int flags));
-void Sybtcl_Kill _ANSI_ARGS_((ClientData clientData));
+#endif
+static void Sybtcl_Kill _ANSI_ARGS_((ClientData clientData));
 static int CS_INTERNAL syb_tcl_err_handler _ANSI_ARGS_((
 	DBPROCESS *db_proc,
@@ -496,4 +507,5 @@
 
 
+#ifdef POLLED_EVENTS /* { */
 /*
  *----------------------------------------------------------------------
@@ -566,5 +578,5 @@
     }
 }
-
+#endif /* POLLED_EVENTS } */
 
 
@@ -609,5 +621,4 @@
 {
     dbState *statePtr = (dbState *) instanceData;
-    int hand = statePtr->hand;
 
 #ifdef POLLED_EVENTS
@@ -641,5 +652,5 @@
     dbState *statePtr = (dbState *) instanceData;
 
-    *handlePtr = (ClientData)statePtr->fd; 
+    *handlePtr = (ClientData)(intptr_t)statePtr->fd; 
     return TCL_OK;                      
 }   
@@ -661,5 +672,5 @@
 }
 
-Tcl_Channel
+static Tcl_Channel
 dbMakeChannel (sock, hand, channelName)
     int sock;
@@ -1167,9 +1178,9 @@
  */
 
+CALLBACK_SCOPE Tcl_ChannelProc callback_handler;
 static void
 remove_handler (hand)
     int hand;
 {
-    CALLBACK_SCOPE Tcl_ChannelProc callback_handler;
     if (SybProcs[hand].callBackScript != NULL) {
         Tcl_DecrRefCount(SybProcs[hand].callBackScript);
@@ -1177,8 +1188,8 @@
 	if (SybProcs[hand].sybChan != NULL) {
 	    Tcl_DeleteChannelHandler(SybProcs[hand].sybChan,
-				callback_handler, (ClientData) hand);
+				callback_handler, (ClientData)(intptr_t)hand);
         }
 #ifdef POLLED_EVENTS
-        Tcl_DeleteEventSource( dbSetupProc, dbCheckProc, (ClientData) hand);
+        Tcl_DeleteEventSource( dbSetupProc, dbCheckProc, (ClientData)(intptr_t)hand);
 #endif
     }
@@ -1451,4 +1462,16 @@
 				&dateinfo,(DBDATETIME *) col_ptr);
 		j=0;
+#if defined(MSDBLIB) && !defined(dateyear)
+#	define dateyear	year
+#	define datemonth	month
+#	define datedmonth	day
+#	define datedyear	dayofyear
+#	define datedweek	weekday
+#	define datehour	hour
+#	define dateminute	minute
+#	define datesecond	second
+#	define datemsecond	millisecond
+#	define datetzone	tzone
+#endif
 		while((unsigned int) j < strlen(date_str)) {
 		    if (!strncmp(&(date_str[j]),"YYYY",4)) {
@@ -1669,6 +1692,8 @@
 
 
-#ifdef DBVERSION_100
+#ifdef SYBBOUNDARY
 	case SYBBOUNDARY:
+#endif
+#ifdef SYBSENSITIVITY
 	case SYBSENSITIVITY:
 #endif  
@@ -1694,5 +1719,5 @@
  */
 
-void
+static void
 Sybtcl_Kill (clientData)
     ClientData clientData;
@@ -1776,5 +1801,5 @@
  */
 
-void
+static void
 Sybtcl_DeleteInterp (clientData, interp)
     ClientData clientData;
@@ -2429,5 +2454,5 @@
  */
 
-int
+static int
 Sybtcl_ErrHandler (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -2466,5 +2491,5 @@
  */
 
-int
+static int
 Sybtcl_MsgHandler (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -2505,5 +2530,5 @@
  */
 
-int
+static int
 Sybtcl_Connect (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -2556,5 +2581,7 @@
 
     DBSETLUSER(login,Tcl_GetStringFromObj(objv[1],NULL));
-    DBSETLPWD(login, Tcl_GetStringFromObj(objv[2],NULL));
+    server_str = Tcl_GetStringFromObj(objv[2],&len);
+    if (len > 0)
+	DBSETLPWD(login, server_str);
 
     /* check for server optional parameter */
@@ -2594,8 +2621,8 @@
             DBSETLCHARSET(login, charset_str);
 	} else {
-            DBSETLCHARSET(login, NULL);
+            DBSETLCHARSET(login, TDS_DEF_CHARSET);
 	}
     } else {
-        DBSETLCHARSET(login, NULL);
+        DBSETLCHARSET(login, TDS_DEF_CHARSET);
     }
 
@@ -2607,5 +2634,6 @@
     if (SybProcs[hand].dbproc == NULL) {
 	Sybtcl_AppendObjResult (interp, CMD_STR,
-	   ": sybconnect failed in dbopen", (char *) NULL);
+	   ": sybconnect to ", server_str ? server_str : "(DEFAULT)",
+	   " failed in dbopen", (char *) NULL);
 	return TCL_ERROR;
     }
@@ -2673,4 +2701,5 @@
  */
 
+static int
 Sybtcl_Money (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -2788,4 +2817,5 @@
  */
 
+static int
 Sybtcl_Use (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -2850,4 +2880,5 @@
  */
 
+static int
 Sybtcl_Sql (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -2909,5 +2940,5 @@
     if (SybProcs[hand].last_text != SybOptions[i].maxtext) {
 	SybProcs[hand].last_text = SybOptions[i].maxtext;
-	sprintf(conv_buf,"%d",SybOptions[i].maxtext);
+	sprintf(conv_buf,"%ld",SybOptions[i].maxtext);
 	dbsetopt(SybProcs[hand].dbproc, DBTEXTSIZE, conv_buf, -1);
 	dbsqlexec(SybProcs[hand].dbproc);  /* execute dbsetopt() */
@@ -3022,4 +3053,5 @@
  */
 
+static int
 Sybtcl_Poll (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -3551,4 +3583,5 @@
  */
 
+static int
 Sybtcl_Next (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -3819,4 +3852,5 @@
  */
 
+static int
 Sybtcl_Cols (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -3972,4 +4006,5 @@
  */
 
+static int
 Sybtcl_Cancel (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -4020,4 +4055,5 @@
  */
 
+static int
 Sybtcl_Retval (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -4091,4 +4127,5 @@
  */
 
+static int
 Sybtcl_Close (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -4167,4 +4204,5 @@
  */
 
+static int
 Sybtcl_Wrtext (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -4190,5 +4228,5 @@
     int      obj_parm;
     int      isvar = 0;
-    Tcl_Channel fd;
+    Tcl_Channel fd = NULL;
 #ifndef MAC_TCL
     struct stat stat_buf;		
@@ -4305,5 +4343,6 @@
     txtptr = dbtxptr(SybProcs[hand].dbproc,col);
     if (txtptr == NULL) {
-        Tcl_Close (NULL,fd);
+	if (fd != NULL)
+            Tcl_Close (NULL,fd);
         Sybtcl_AppendObjResult (interp, CMD_STR,
 	   ": dbtxptr failed ", (char *) NULL);
@@ -4448,5 +4487,5 @@
  */
 
-
+static int
 Sybtcl_Rdtext (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -4638,5 +4677,5 @@
     int        mask;
 {
-    int         hand = (int) cd_hand;
+    int         hand = (int)(intptr_t)cd_hand;
     Tcl_Interp *interp = SybProcs[hand].interp;
     DBPROCESS  *readyproc;
@@ -4754,5 +4793,5 @@
  */
 
-
+static int
 Sybtcl_Event (clientData, interp, objc, objv)
     ClientData   clientData;
@@ -4791,9 +4830,9 @@
                 /* create handler */
                 Tcl_CreateChannelHandler(SybProcs[hand].sybChan, TCL_READABLE, 
-    				    callback_handler, (ClientData) hand);
+    				    callback_handler, (ClientData)(intptr_t)hand);
 
 #ifdef POLLED_EVENTS
                 Tcl_CreateEventSource(dbSetupProc, dbCheckProc,
-				(ClientData) hand);
+				(ClientData)(intptr_t)hand);
 #endif