1# Since Cython needs to know what you are using from header files this 2# definition is provided so it knows exactly what we are using from 3# FreeTDS. 4 5cdef extern from "sqlfront.h": 6 7 ## Type Definitions ## 8 cdef struct tds_dblib_dbprocess: 9 pass 10 cdef struct tds_sysdep_real32_type: 11 pass 12 cdef struct tds_sysdep_real64_type: 13 pass 14 15 ctypedef tds_dblib_dbprocess DBPROCESS 16 cdef struct tds_dblib_loginrec: 17 pass 18 ctypedef tds_dblib_loginrec LOGINREC 19 ctypedef void DBCURSOR 20 ctypedef int BOOL 21 ctypedef short int SHORT 22 ctypedef unsigned char BYTE 23 ctypedef int RETCODE 24 ctypedef short unsigned int DBUSMALLINT 25 26 ctypedef unsigned char DBBINARY 27 ctypedef int DBBIT 28 ctypedef unsigned char DBBOOL 29 ctypedef char DBCHAR 30 ctypedef int DBINT 31 ctypedef tds_sysdep_real32_type DBREAL 32 ctypedef tds_sysdep_real64_type DBFLT8 33 cdef struct DBMONEY: 34 DBINT mnyhigh 35 unsigned int mnylow 36 cdef struct DBMONEY4: 37 DBINT mny4 38 ctypedef unsigned char DBTINYINT 39 ctypedef short int DBSMALLINT 40 41 ctypedef struct DBDATETIME: 42 DBINT dtdays 43 DBINT dttime 44 ctypedef struct DBDATETIME4: 45 DBUSMALLINT days 46 DBUSMALLINT minutes 47 48 ctypedef struct DBCOL: 49 DBINT SizeOfStruct 50 DBCHAR * Name 51 DBCHAR * ActualName 52 DBCHAR * TableName 53 SHORT Type 54 DBINT UserType 55 DBINT MaxLength 56 BYTE Precision 57 BYTE Scale 58 BOOL VarLength 59 BYTE Null 60 BYTE CaseSensitive 61 BYTE Updatable 62 BOOL Identity 63 64 ctypedef struct DBDATEREC: 65 DBINT year 66 DBINT month 67 DBINT day 68 DBINT dayofyear 69 DBINT weekday 70 DBINT hour 71 DBINT minute 72 DBINT second 73 DBINT millisecond 74 DBINT tzone 75 76 ctypedef struct DBNUMERIC: 77 BYTE precision 78 BYTE scale 79 BYTE array[33] 80 81 ctypedef DBNUMERIC DBDECIMAL 82 83 # Error handler callback 84 ctypedef int(*EHANDLEFUNC)(DBPROCESS *, int, int, int, char *, char *) 85 86 # Message handler callback 87 ctypedef int(*MHANDLEFUNC)(DBPROCESS *, DBINT, int, int, char *, char *, char *, int) 88 89 ## Constants ## 90 int FAIL 91 int SUCCEED 92 int INT_CANCEL 93 int NO_MORE_ROWS 94 int NO_MORE_RESULTS 95 int REG_ROW 96 int DBNOERR 97 int DBRPCRETURN 98 99 int CI_ALTERNATE 100 int CI_CURSOR 101 int CI_REGULAR 102 int MAXCOLNAMELEN 103 104 ## Version Constants ## 105 int DBVERSION_42 106 int DBVERSION_70 107 int DBVERSION_71 108 int DBVERSION_72 109 110 ## Type Constants ## 111 cdef enum: 112 SYBBINARY 113 SYBBIT 114 SYBCHAR 115 SYBDATETIME 116 SYBDATETIME4 117 SYBDATETIMN 118 SYBDECIMAL 119 SYBFLT8 120 SYBFLTN 121 SYBIMAGE 122 SYBINT1 123 SYBINT2 124 SYBINT4 125 SYBINT8 126 SYBINTN 127 SYBMONEY 128 SYBMONEY4 129 SYBMONEYN 130 SYBNUMERIC 131 SYBREAL 132 SYBTEXT 133 SYBVARBINARY 134 SYBVARCHAR 135 136 ## Primary functions ## 137 # Get address of compute column data. 138 # 139 # Parameters: 140 # dbproc contains all information needed by db-lib to manage 141 # communications with the server. 142 # computeid of COMPUTE clause to which we're referring. 143 # column Nth column in computeid, starting from 1. 144 # 145 # Returns: 146 # pointer to columns' data buffer. 147 # 148 # Return values: 149 # NULL no such compute id or column. 150 BYTE * dbadata(DBPROCESS *, int, int) nogil 151 152 # Get address of compute column data. 153 # 154 # Parameters: 155 # dbproc contains all information needed by db-lib to manage 156 # communications with the server. 157 # computeid of COMPUTE clause to which we're referring. 158 # column Nth column in computeid, starting from 1. 159 # 160 # Returns: 161 # size of the data, in bytes 162 # 163 # Return values: 164 # -1 no such column or computeid. 165 # 0 data is NULL. 166 DBINT dbadlen(DBPROCESS *, int, int) nogil 167 168 # Get datatype for a compute column data. 169 # 170 # Parameters: 171 # dbproc contains all information needed by db-lib to manage 172 # communications with the server. 173 # computeid of COMPUTE clause to which we're referring. 174 # column Nth column in computeid, starting from 1. 175 # 176 # Returns: 177 # SYB* datatype token 178 # 179 # Return values: 180 # -1 no such column or computeid. 181 int dbalttype(DBPROCESS *, int, int) nogil 182 183 # Cancel the current command batch 184 # 185 # Parameters: 186 # dbproc contains all information needed by db-lib to manage 187 # communications with the server. 188 # 189 # Returns: 190 # SUCCEED always 191 RETCODE dbcancel(DBPROCESS *) nogil 192 193 # Close a connection to the server and free associated resources. 194 # 195 # Parameters: 196 # dbproc contains all information needed by db-lib to manage 197 # communications with the server. 198 void dbclose(DBPROCESS *) nogil 199 200 # Close a connection to the server and free associated resources. 201 # 202 # Parameters: 203 # dbproc contains all information needed by db-lib to manage 204 # communications with the server. 205 # cmdstring SQL to append to the command buffer. 206 # 207 # Returns: 208 # SUCCEED success 209 # FAIL insufficient memory 210 RETCODE dbcmd(DBPROCESS *, char *) 211 212 # Return name of a regular result column. 213 # 214 # Parameters: 215 # dbproc contains all information needed by db-lib to manage 216 # communications with the server. 217 # column Nth in the result set, starting with 1. 218 # 219 # Returns: 220 # pointer to ASCII null-terminated string, the name of the column. 221 # 222 # Return values: 223 # NULL column is not in range. 224 char * dbcolname(DBPROCESS *, int) 225 226 # Get the datatype of a regular result set column. 227 # 228 # Parameters: 229 # dbproc contains all information needed by db-lib to manage 230 # communications with the server. 231 # column Nth column in computeid, starting from 1. 232 # 233 # Returns: 234 # SYB* datatype token value, or zero if column is out of range. 235 int dbcoltype(DBPROCESS *, int) nogil 236 237 # Convert one datatype to another. 238 # 239 # Parameters: 240 # dbproc contains all information needed by db-lib to manage 241 # communications with the server. 242 # srctype datatype of the data to convert 243 # src buffer to convert 244 # srclen length of src 245 # desttype target datatype 246 # dest output buffer 247 # destlen size of dest 248 # 249 # Returns: 250 # On success, the count of output bytes in dest, else -1. On 251 # failure, it will call any user-supplied error handler. 252 DBINT dbconvert(DBPROCESS *, int, BYTE *, DBINT, int, BYTE *, DBINT) 253 254 ctypedef struct DBTYPEINFO: 255 DBINT precision 256 DBINT scale 257 258 DBINT dbconvert_ps(DBPROCESS * dbprocess, int srctype, BYTE * src, DBINT srclen, int desttype, BYTE * dest, DBINT destlen, 259 DBTYPEINFO * typeinfo) 260 261 # Get count of rows processed. 262 # 263 # Parameters: 264 # dbproc contains all information needed by db-lib to manage 265 # communications with the server. 266 # Returns: 267 # * for insert/update/delete, count of rows affected. 268 # * for select, count of rows returned, after all rows have been 269 # fetched. 270 DBINT dbcount(DBPROCESS *) nogil 271 272 # Check if dbproc is an ex-parrot. 273 # 274 # Parameters: 275 # dbproc contains all information needed by db-lib to manage 276 # communications with the server. 277 # Returns: 278 # * for insert/update/delete, count of rows affected. 279 # * for select, count of rows returned, after all rows have been 280 DBBOOL dbdead(DBPROCESS *) 281 282 # Get address of data in a regular result column. 283 # 284 # Parameters: 285 # dbproc contains all information needed by db-lib to manage 286 # communications with the server. 287 # column Nth column in computeid, starting from 1. 288 # 289 # Returns: 290 # pointer to the data, or NULL if data is NULL, or if column is 291 # out of range 292 BYTE * dbdata(DBPROCESS *, int) nogil 293 294 # Break a DBDATETIME value into useful pieces. 295 # 296 # Parameters: 297 # dbproc contains all information needed by db-lib to manage 298 # communications with the server. 299 # di output: structure to contain the exploded parts of 300 # datetime. 301 # datetime input: DBDATETIME to be converted. 302 # 303 # Return values: 304 # SUCCEED always 305 RETCODE dbdatecrack(DBPROCESS *, DBDATEREC *, DBDATETIME *) 306 307 # Get size of current row's data in a regular result column. 308 # 309 # Parameters: 310 # dbproc contains all information needed by db-lib to manage 311 # communications with the server. 312 # column Nth column in computeid, starting from 1. 313 # 314 # Returns: 315 # size of the data, in bytes 316 DBINT dbdatlen(DBPROCESS *, int) nogil 317 318 # Set an error handler, for messages from db-lib. 319 # 320 # Parameters: 321 # handler pointer to callback function that will handle errors. 322 # Pass NULL to restore the default handler. 323 # 324 # Returns: 325 # address of prior handler, or NULL if none was previously 326 # installed. 327 EHANDLEFUNC dberrhandle(EHANDLEFUNC) 328 329 # Close server connections and free all related structures. 330 void dbexit() 331 332 # Get maximum simultaneous connections db-lib will open to the server. 333 # 334 # Returns: 335 # size of the data, in bytes 336 int dbgetmaxprocs() 337 338 # Initialize db-lib 339 # 340 # Return values: 341 # SUCCEED normal 342 # FAIL cannot allocate an array of TDS_MAX_CONN TDSSOCKET 343 # pointers. 344 RETCODE dbinit() 345 346 # Allocate a LOGINREC structure. 347 # 348 # Return values: 349 # NULL the LOGINREC cannot be allocated. 350 # LOGINREC* to valid memory 351 LOGINREC * dblogin() 352 353 # free the LOGINREC 354 void dbloginfree(LOGINREC *) 355 356 # Set a message handler, for messages from the server. 357 # 358 # Parameters: 359 # handler address of the function that will process the messages. 360 MHANDLEFUNC dbmsghandle(MHANDLEFUNC) 361 362 # Get name of current database. 363 # 364 # Parameters: 365 # dbproc contains all information needed by db-lib to manage 366 # communications with the server. 367 # 368 # Returns: 369 # current database name, as null-terminated ASCII string. 370 char * dbname(DBPROCESS *) 371 372 # Read result row into the row buffer and into any bound host variables. 373 # 374 # Parameters: 375 # dbproc contains all information needed by db-lib to manage 376 # communications with the server. 377 # 378 # Return values: 379 # REG_ROW regular row has been read. 380 # BUF_FULL reading the next row would cause the buffer to be 381 # exceeded. No row was read from the server. 382 # 383 # Returns: 384 # computeid when a compute row is read. 385 RETCODE dbnextrow(DBPROCESS *) nogil 386 387 # Return number of regular columns in a result set. 388 # 389 # Parameters: 390 # dbproc contains all information needed by db-lib to manage 391 # communications with the server. 392 # 393 # Returns: 394 # number of columns in the result set row. 395 int dbnumcols(DBPROCESS *) 396 397 # Form a connection with the server. 398 # 399 # Parameters: 400 # login LOGINREC* carrying the account information 401 # server name of the dataserver to connect to 402 # 403 # Returns: 404 # value pointer on successful login. 405 # 406 # Return values: 407 # NULL insufficient memory, unable to connect for any reason 408 DBPROCESS * dbopen(LOGINREC *, char *) nogil 409 410 # Set up query results. 411 # 412 # Parameters: 413 # dbproc contains all information needed by db-lib to manage 414 # communications with the server. 415 # 416 # Return values: 417 # SUCCEED some result are available. 418 # FAIL query was not processed successfully by the server. 419 # NO_MORE_RESULTS query produced no results. 420 RETCODE dbresults(DBPROCESS *) nogil 421 422 # Set maximum seconds db-lib waits for a server response to a login 423 # attempt. 424 # 425 # Parameters: 426 # seconds New limit for application. 427 # 428 # Returns: 429 # SUCCEED always 430 RETCODE dbsetlogintime(int) 431 432 # Set maximum simultaneous connections db-lib will open to the server. 433 # 434 # Parameters: 435 # maxprocs Limit for process. 436 # 437 # Returns: 438 # SUCCEED always 439 RETCODE dbsetmaxprocs(int) 440 441 # Set maximum seconds db-lib waits for a server response to query. 442 # 443 # Parameters: 444 # seconds New limit for application. 445 # 446 # Returns: 447 # SUCCEED always 448 RETCODE dbsettime(int) 449 450 # Send the SQL command to the server and wait for an answer. 451 # 452 # Parameters: 453 # dbproc contains all information needed by db-lib to manage 454 # communications with the server. 455 # 456 # Return values: 457 # SUCCEED query was processed without errors. 458 # FAIL was returned by dbsqlsend() or dbsqlok() 459 RETCODE dbsqlexec(DBPROCESS *) nogil 460 461 # Send the SQL command to the server 462 # 463 # Parameters: 464 # dbproc contains all information needed by db-lib to manage 465 # communications with the server. 466 # 467 # Return values: 468 # SUCCEED query was processed without errors. 469 # FAIL was returned by dbsqlsend() or dbsqlok() 470 RETCODE dbsqlsend(DBPROCESS *) nogil 471 472 # Get file descriptor of the socket used by a DBPROCESS to read data coming 473 # from the server. 474 # 475 # Parameters: 476 # dbproc contains all information needed by db-lib to manage 477 # communications with the server. 478 # 479 # Return values: 480 # An integer file descriptor used by the specified DBPROCESS to read 481 # data coming from the server. 482 int dbiordesc(DBPROCESS *) nogil 483 484 # Wait for results of a query from the server. 485 # 486 # Parameters: 487 # dbproc contains all information needed by db-lib to manage 488 # communications with the server. 489 # 490 # Return values: 491 # SUCCEED everything worked, fetch results with dbnextresults(). 492 # FAIL SQL syntax error, typically. 493 RETCODE dbsqlok(DBPROCESS *) nogil 494 495 # Get the TDS version in use for dbproc. 496 # 497 # Parameters: 498 # dbproc contains all information needed by db-lib to manage 499 # communications with the server. 500 # 501 # Returns: 502 # a DBTDS* token. 503 # 504 # Remarks: 505 # The integer values of the constants are counterintuitive. 506 int dbtds(DBPROCESS *) 507 508 # Change current database 509 # 510 # Parameters: 511 # dbproc contains all information needed by db-lib to manage 512 # communications with the server. 513 # name database to use. 514 # 515 # Return values: 516 # SUCCEED query was processed without errors. 517 # FAIL query was not processed 518 RETCODE dbuse(DBPROCESS *, char *) nogil 519 520 ## End Primary functions ## 521 522 ## Remote Procedure functions ## 523 # Determine if query generated a return status number 524 # 525 # Parameters: 526 # dbproc contains all information needed by db-lib to manage 527 # communications with the server. 528 # Return values: 529 # TRUE fetch return status with dbretstatus(). 530 # FALSE no return status 531 DBBOOL dbhasretstat(DBPROCESS *) 532 533 # Get count of output parameters filled by a stored procedure 534 # 535 # Parameters: 536 # dbproc contains all information needed by db-lib to manage 537 # communications with the server. 538 # Returns: 539 # How many, possibly zero. 540 int dbnumrets(DBPROCESS *) 541 542 # Get value of an output parameter filled by a stored procedure. 543 # 544 # Parameters: 545 # dbproc contains all information needed by db-lib to manage 546 # communications with the server. 547 # retnum Nth parameter between 1 and the return value from 548 # dbnumrets() 549 # Returns: 550 # Address of a return parameter value, or NULL if no such retnum. 551 BYTE * dbretdata(DBPROCESS *, int) nogil 552 553 # Get size of an output parameter filled by a stored procedure. 554 # 555 # Parameters: 556 # dbproc contains all information needed by db-lib to manage 557 # communications with the server. 558 # retnum Nth parameter between 1 and the return value from 559 # dbnumrets() 560 # Returns: 561 # Size of a return parameter value, or NULL if no such retnum. 562 int dbretlen(DBPROCESS *, int) nogil 563 564 # Get name of an output parameter filled by a stored procedure. 565 # 566 # Parameters: 567 # dbproc contains all information needed by db-lib to manage 568 # communications with the server. 569 # retnum Nth parameter between 1 and the return value from 570 # dbnumrets() 571 # Returns: 572 # ASCII null-terminated string, NULL if no such retnum. 573 char * dbretname(DBPROCESS *, int) nogil 574 575 # Fetch status value returned by query or remote procedure call. 576 # 577 # Parameters: 578 # dbproc contains all information needed by db-lib to manage 579 # communications with the server. 580 # Returns: 581 # The return value of the rpc call 582 DBINT dbretstatus(DBPROCESS *) nogil 583 584 # Get datatype of a stored procedure's return parameter. 585 # 586 # Parameters: 587 # dbproc contains all information needed by db-lib to manage 588 # communications with the server. 589 # retnum Nth parameter between 1 and the return value from 590 # dbnumrets() 591 # Returns: 592 # SYB* datatype token, or -1 if retnum is out of range. 593 int dbrettype(DBPROCESS *, int) nogil 594 595 # Initialize a remote procedure call. 596 # 597 # Parameters: 598 # dbproc contains all information needed by db-lib to manage 599 # communications with the server. 600 # rpcname name of the stored procedure to be run. 601 # options Only supported option would be DBRPCRECOMPILE, which causes 602 # the stored procedure to be recompiled before executing. 603 # Return values: 604 # SUCCEED normal 605 # FAIL on error 606 RETCODE dbrpcinit(DBPROCESS *, char *, DBSMALLINT) nogil 607 608 # Add a parameter to a remote procedure call. 609 # 610 # Parameters: 611 # dbproc contains all information needed by db-lib to manage 612 # communications with the server. 613 # paramname literal name of the parameter, according to the stored 614 # procedure (starts with '@'). Optional. If not used, 615 # parameters will be passed in order instead of by name. 616 # status must be DBRPCRETURN, if this parameter is a return 617 # parameter, else 0. 618 # type datatype of the value parameter e.g. SYBINT4, SYBCHAR 619 # maxlen Maximum output size of the parameter's value to be returned 620 # by the stored procedure, usually the size of your host 621 # variable. Fixed-length datatypes take -1 (NULL or not). 622 # Non-OUTPUT parameters also use -1. Use 0 to send a NULL 623 # value for a variable length datatype. 624 # datalen For variable-length datatypes, the byte size of the data 625 # to be sent, exclusive of any null terminator. For 626 # fixed-length datatypes use -1. To send a NULL value, use 0. 627 # value Address of your host variable. 628 # 629 # Return values: 630 # SUCCEED normal 631 # FAIL on error 632 RETCODE dbrpcparam(DBPROCESS *, char *, BYTE, int, DBINT, DBINT, BYTE *) nogil 633 634 # Execute the procedure and free associated memory. 635 # 636 # Parameters: 637 # dbproc contains all information needed by db-lib to manage 638 # communications with the server. 639 # Return values: 640 # SUCCEED normal 641 # FAIL on error 642 RETCODE dbrpcsend(DBPROCESS *) nogil 643 ## End Remote Procedure functions ## 644 645 ## Macros ## 646 DBBOOL DBDEAD(DBPROCESS *) 647 RETCODE DBSETLAPP(LOGINREC *x, char *y) 648 RETCODE DBSETLHOST(LOGINREC *x, char *y) 649 RETCODE DBSETLPWD(LOGINREC *x, char *y) 650 RETCODE DBSETLUSER(LOGINREC *x, char *y) 651 RETCODE DBSETLCHARSET(LOGINREC *x, char *y) 652 RETCODE DBSETLVERSION(LOGINREC *login, BYTE version) 653 RETCODE DBSETLDBNAME(LOGINREC *x, char *y) 654 655ctypedef int LINE_T 656