forked from pymssql/pymssql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlfront.pxd
619 lines (559 loc) · 19.6 KB
/
sqlfront.pxd
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# Since Cython needs to know what you are using from header files this
# definition is provided so it knows exactly what we are using from
# FreeTDS.
cdef extern from "sqlfront.h":
## Type Definitions ##
cdef struct tds_dblib_dbprocess:
pass
cdef struct tds_sysdep_real32_type:
pass
cdef struct tds_sysdep_real64_type:
pass
ctypedef tds_dblib_dbprocess DBPROCESS
cdef struct tds_dblib_loginrec:
pass
ctypedef tds_dblib_loginrec LOGINREC
ctypedef void DBCURSOR
ctypedef int BOOL
ctypedef short int SHORT
ctypedef unsigned char BYTE
ctypedef int RETCODE
ctypedef short unsigned int DBUSMALLINT
ctypedef unsigned char DBBINARY
ctypedef int DBBIT
ctypedef unsigned char DBBOOL
ctypedef char DBCHAR
ctypedef int DBINT
ctypedef tds_sysdep_real32_type DBREAL
ctypedef tds_sysdep_real64_type DBFLT8
cdef struct DBMONEY:
DBINT mnyhigh
unsigned int mnylow
cdef struct DBMONEY4:
DBINT mny4
ctypedef unsigned char DBTINYINT
ctypedef short int DBSMALLINT
ctypedef struct DBDATETIME:
DBINT dtdays
DBINT dttime
ctypedef struct DBDATETIME4:
DBUSMALLINT days
DBUSMALLINT minutes
ctypedef struct DBCOL:
DBINT SizeOfStruct
DBCHAR * Name
DBCHAR * ActualName
DBCHAR * TableName
SHORT Type
DBINT UserType
DBINT MaxLength
BYTE Precision
BYTE Scale
BOOL VarLength
BYTE Null
BYTE CaseSensitive
BYTE Updatable
BOOL Identity
ctypedef struct DBDATEREC:
DBINT year
DBINT month
DBINT day
DBINT dayofyear
DBINT weekday
DBINT hour
DBINT minute
DBINT second
DBINT millisecond
DBINT tzone
# Error handler callback
ctypedef int(*EHANDLEFUNC)(DBPROCESS *, int, int, int, char *, char *)
# Message handler callback
ctypedef int(*MHANDLEFUNC)(DBPROCESS *, DBINT, int, int, char *, char *, char *, int)
## Constants ##
int FAIL
int SUCCEED
int INT_CANCEL
int NO_MORE_ROWS
int NO_MORE_RESULTS
int REG_ROW
int DBNOERR
int DBRPCRETURN
int CI_ALTERNATE
int CI_CURSOR
int CI_REGULAR
int MAXCOLNAMELEN
## Version Constants ##
int DBVERSION_42
int DBVERSION_70
int DBVERSION_71
int DBVERSION_72
int DBVERSION_80
## Type Constants ##
cdef enum:
SYBBINARY
SYBBIT
SYBCHAR
SYBDATETIME
SYBDATETIME4
SYBDATETIMN
SYBDECIMAL
SYBFLT8
SYBFLTN
SYBIMAGE
SYBINT1
SYBINT2
SYBINT4
SYBINT8
SYBINTN
SYBMONEY
SYBMONEY4
SYBMONEYN
SYBNUMERIC
SYBREAL
SYBTEXT
SYBVARBINARY
SYBVARCHAR
## Primary functions ##
# Get address of compute column data.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# computeid of COMPUTE clause to which we're referring.
# column Nth column in computeid, starting from 1.
#
# Returns:
# pointer to columns' data buffer.
#
# Return values:
# NULL no such compute id or column.
BYTE * dbadata(DBPROCESS *, int, int) nogil
# Get address of compute column data.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# computeid of COMPUTE clause to which we're referring.
# column Nth column in computeid, starting from 1.
#
# Returns:
# size of the data, in bytes
#
# Return values:
# -1 no such column or computeid.
# 0 data is NULL.
DBINT dbadlen(DBPROCESS *, int, int) nogil
# Get datatype for a compute column data.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# computeid of COMPUTE clause to which we're referring.
# column Nth column in computeid, starting from 1.
#
# Returns:
# SYB* datatype token
#
# Return values:
# -1 no such column or computeid.
int dbalttype(DBPROCESS *, int, int) nogil
# Cancel the current command batch
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
#
# Returns:
# SUCCEED always
RETCODE dbcancel(DBPROCESS *) nogil
# Close a connection to the server and free associated resources.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
void dbclose(DBPROCESS *) nogil
# Close a connection to the server and free associated resources.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# cmdstring SQL to append to the command buffer.
#
# Returns:
# SUCCEED success
# FAIL insufficient memory
RETCODE dbcmd(DBPROCESS *, char *)
# Return name of a regular result column.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# column Nth in the result set, starting with 1.
#
# Returns:
# pointer to ASCII null-terminated string, the name of the column.
#
# Return values:
# NULL column is not in range.
char * dbcolname(DBPROCESS *, int)
# Get the datatype of a regular result set column.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# column Nth column in computeid, starting from 1.
#
# Returns:
# SYB* datatype token value, or zero if column is out of range.
int dbcoltype(DBPROCESS *, int) nogil
# Convert one datatype to another.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# srctype datatype of the data to convert
# src buffer to convert
# srclen length of src
# desttype target datatype
# dest output buffer
# destlen size of dest
#
# Returns:
# On success, the count of output bytes in dest, else -1. On
# failure, it will call any user-supplied error handler.
DBINT dbconvert(DBPROCESS *, int, BYTE *, DBINT, int, BYTE *, DBINT)
# Get count of rows processed.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# Returns:
# * for insert/update/delete, count of rows affected.
# * for select, count of rows returned, after all rows have been
# fetched.
DBINT dbcount(DBPROCESS *) nogil
# Check if dbproc is an ex-parrot.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# Returns:
# * for insert/update/delete, count of rows affected.
# * for select, count of rows returned, after all rows have been
DBBOOL dbdead(DBPROCESS *)
# Get address of data in a regular result column.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# column Nth column in computeid, starting from 1.
#
# Returns:
# pointer to the data, or NULL if data is NULL, or if column is
# out of range
BYTE * dbdata(DBPROCESS *, int) nogil
# Break a DBDATETIME value into useful pieces.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# di output: structure to contain the exploded parts of
# datetime.
# datetime input: DBDATETIME to be converted.
#
# Return values:
# SUCCEED always
RETCODE dbdatecrack(DBPROCESS *, DBDATEREC *, DBDATETIME *)
# Get size of current row's data in a regular result column.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# column Nth column in computeid, starting from 1.
#
# Returns:
# size of the data, in bytes
DBINT dbdatlen(DBPROCESS *, int) nogil
# Set an error handler, for messages from db-lib.
#
# Parameters:
# handler pointer to callback function that will handle errors.
# Pass NULL to restore the default handler.
#
# Returns:
# address of prior handler, or NULL if none was previously
# installed.
EHANDLEFUNC dberrhandle(EHANDLEFUNC)
# Close server connections and free all related structures.
void dbexit()
# Get maximum simultaneous connections db-lib will open to the server.
#
# Returns:
# size of the data, in bytes
int dbgetmaxprocs()
# Initialize db-lib
#
# Return values:
# SUCCEED normal
# FAIL cannot allocate an array of TDS_MAX_CONN TDSSOCKET
# pointers.
RETCODE dbinit()
# Allocate a LOGINREC structure.
#
# Return values:
# NULL the LOGINREC cannot be allocated.
# LOGINREC* to valid memory
LOGINREC * dblogin()
# free the LOGINREC
void dbloginfree(LOGINREC *)
# Set a message handler, for messages from the server.
#
# Parameters:
# handler address of the function that will process the messages.
MHANDLEFUNC dbmsghandle(MHANDLEFUNC)
# Get name of current database.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
#
# Returns:
# current database name, as null-terminated ASCII string.
char * dbname(DBPROCESS *)
# Read result row into the row buffer and into any bound host variables.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
#
# Return values:
# REG_ROW regular row has been read.
# BUF_FULL reading the next row would cause the buffer to be
# exceeded. No row was read from the server.
#
# Returns:
# computeid when a compute row is read.
RETCODE dbnextrow(DBPROCESS *) nogil
# Return number of regular columns in a result set.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
#
# Returns:
# number of columns in the result set row.
int dbnumcols(DBPROCESS *)
# Form a connection with the server.
#
# Parameters:
# login LOGINREC* carrying the account information
# server name of the dataserver to connect to
#
# Returns:
# value pointer on successful login.
#
# Return values:
# NULL insufficient memory, unable to connect for any reason
DBPROCESS * dbopen(LOGINREC *, char *)
# Set up query results.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
#
# Return values:
# SUCCEED some result are available.
# FAIL query was not processed successfully by the server.
# NO_MORE_RESULTS query produced no results.
RETCODE dbresults(DBPROCESS *) nogil
# Set maximum seconds db-lib waits for a server response to a login
# attempt.
#
# Parameters:
# seconds New limit for application.
#
# Returns:
# SUCCEED always
RETCODE dbsetlogintime(int)
# Set maximum simultaneous connections db-lib will open to the server.
#
# Parameters:
# maxprocs Limit for process.
#
# Returns:
# SUCCEED always
RETCODE dbsetmaxprocs(int)
# Set maximum seconds db-lib waits for a server response to query.
#
# Parameters:
# seconds New limit for application.
#
# Returns:
# SUCCEED always
RETCODE dbsettime(int)
# Send the SQL command to the server and wait for an answer.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
#
# Return values:
# SUCCEED query was processed without errors.
# FAIL was returned by dbsqlsend() or dbsqlok()
RETCODE dbsqlexec(DBPROCESS *) nogil
# Wait for results of a query from the server.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
#
# Return values:
# SUCCEED everything worked, fetch results with dbnextresults().
# FAIL SQL syntax error, typically.
RETCODE dbsqlok(DBPROCESS *) nogil
# Get the TDS version in use for dbproc.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
#
# Returns:
# a DBTDS* token.
#
# Remarks:
# The integer values of the constants are counterintuitive.
int dbtds(DBPROCESS *)
# Change current database
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# name database to use.
#
# Return values:
# SUCCEED query was processed without errors.
# FAIL query was not processed
RETCODE dbuse(DBPROCESS *, char *) nogil
## End Primary functions ##
## Remote Procedure functions ##
# Determine if query generated a return status number
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# Return values:
# TRUE fetch return status with dbretstatus().
# FALSE no return status
DBBOOL dbhasretstat(DBPROCESS *)
# Get count of output parameters filled by a stored procedure
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# Returns:
# How many, possibly zero.
int dbnumrets(DBPROCESS *)
# Get value of an output parameter filled by a stored procedure.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# retnum Nth parameter between 1 and the return value from
# dbnumrets()
# Returns:
# Address of a return parameter value, or NULL if no such retnum.
BYTE * dbretdata(DBPROCESS *, int) nogil
# Get size of an output parameter filled by a stored procedure.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# retnum Nth parameter between 1 and the return value from
# dbnumrets()
# Returns:
# Size of a return parameter value, or NULL if no such retnum.
int dbretlen(DBPROCESS *, int) nogil
# Get name of an output parameter filled by a stored procedure.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# retnum Nth parameter between 1 and the return value from
# dbnumrets()
# Returns:
# ASCII null-terminated string, NULL if no such retnum.
char * dbretname(DBPROCESS *, int) nogil
# Fetch status value returned by query or remote procedure call.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# Returns:
# The return value of the rpc call
DBINT dbretstatus(DBPROCESS *) nogil
# Get datatype of a stored procedure's return parameter.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# retnum Nth parameter between 1 and the return value from
# dbnumrets()
# Returns:
# SYB* datatype token, or -1 if retnum is out of range.
int dbrettype(DBPROCESS *, int) nogil
# Initialize a remote procedure call.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# rpcname name of the stored procedure to be run.
# options Only supported option would be DBRPCRECOMPILE, which causes
# the stored procedure to be recompiled before executing.
# Return values:
# SUCCEED normal
# FAIL on error
RETCODE dbrpcinit(DBPROCESS *, char *, DBSMALLINT) nogil
# Add a parameter to a remote procedure call.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# paramname literal name of the parameter, according to the stored
# procedure (starts with '@'). Optional. If not used,
# parameters will be passed in order instead of by name.
# status must be DBRPCRETURN, if this parameter is a return
# parameter, else 0.
# type datatype of the value parameter e.g. SYBINT4, SYBCHAR
# maxlen Maximum output size of the parameter's value to be returned
# by the stored procedure, usually the size of your host
# variable. Fixed-length datatypes take -1 (NULL or not).
# Non-OUTPUT parameters also use -1. Use 0 to send a NULL
# value for a variable length datatype.
# datalen For variable-length datatypes, the byte size of the data
# to be sent, exclusive of any null terminator. For
# fixed-length datatypes use -1. To send a NULL value, use 0.
# value Address of your host variable.
#
# Return values:
# SUCCEED normal
# FAIL on error
RETCODE dbrpcparam(DBPROCESS *, char *, BYTE, int, DBINT, DBINT, BYTE *) nogil
# Execute the procedure and free associated memory.
#
# Parameters:
# dbproc contains all information needed by db-lib to manage
# communications with the server.
# Return values:
# SUCCEED normal
# FAIL on error
RETCODE dbrpcsend(DBPROCESS *) nogil
## End Remote Procedure functions ##
## Macros ##
DBBOOL DBDEAD(DBPROCESS *)
RETCODE DBSETLAPP(LOGINREC *x, char *y)
RETCODE DBSETLHOST(LOGINREC *x, char *y)
RETCODE DBSETLPWD(LOGINREC *x, char *y)
RETCODE DBSETLUSER(LOGINREC *x, char *y)
RETCODE DBSETLCHARSET(LOGINREC *x, char *y)
RETCODE DBSETLVERSION(LOGINREC *login, BYTE version)
ctypedef int LINE_T