1 //-----------------------------------------------------------------------------
2 // File:        odbcss.h
3 //
4 // Copyright:    Copyright (c) Microsoft Corporation
5 //
6 // Contents:
7 //
8 // Comments:    This is the application include file for the SQL Server driver specific defines.
9 //
10 //-----------------------------------------------------------------------------
11
12 #ifndef __ODBCSS
13 #define __ODBCSS
14
15 #ifdef __cplusplus
16 extern "C" {             /* Assume C declarations for C++     */
17 #endif  /* __cplusplus */
18
19 //    Useful defines
20 #define SQL_MAX_SQLSERVERNAME    128        // max SQL Server identifier length
21
22 //    SQLSetConnectOption/SQLSetStmtOption driver specific defines.
23 //    Microsoft has 1200 thru 1249 reserved for Microsoft SQL Server driver usage.
24
25 //    Connection Options
26 #define SQL_COPT_SS_BASE                1200
27 #define SQL_COPT_SS_REMOTE_PWD            (SQL_COPT_SS_BASE+1) // dbrpwset SQLSetConnectOption only
28 #define SQL_COPT_SS_USE_PROC_FOR_PREP    (SQL_COPT_SS_BASE+2) // Use create proc for SQLPrepare
29 #define SQL_COPT_SS_INTEGRATED_SECURITY    (SQL_COPT_SS_BASE+3) // Force integrated security on login
30 #define SQL_COPT_SS_PRESERVE_CURSORS    (SQL_COPT_SS_BASE+4) // Preserve server cursors after SQLTransact
31 #define SQL_COPT_SS_USER_DATA            (SQL_COPT_SS_BASE+5) // dbgetuserdata/dbsetuserdata
32 #define SQL_COPT_SS_ENLIST_IN_DTC        SQL_ATTR_ENLIST_IN_DTC // Enlist in a DTC transaction
33 #define SQL_COPT_SS_ENLIST_IN_XA        SQL_ATTR_ENLIST_IN_XA // Enlist in a XA transaction
34 //SQL_ATTR_CONNECTION_DEAD 1209 (It will return current connection status, it will not go to server)
35 #define SQL_COPT_SS_FALLBACK_CONNECT    (SQL_COPT_SS_BASE+10) // Enables FallBack connections
36 #define SQL_COPT_SS_PERF_DATA            (SQL_COPT_SS_BASE+11) // Used to access SQL Server ODBC driver performance data
37 #define SQL_COPT_SS_PERF_DATA_LOG        (SQL_COPT_SS_BASE+12) // Used to set the logfile name for the Performance data
38 #define SQL_COPT_SS_PERF_QUERY_INTERVAL (SQL_COPT_SS_BASE+13) // Used to set the query logging threshold in milliseconds.
39 #define SQL_COPT_SS_PERF_QUERY_LOG        (SQL_COPT_SS_BASE+14) // Used to set the logfile name for saving queryies.
40 #define SQL_COPT_SS_PERF_QUERY            (SQL_COPT_SS_BASE+15) // Used to start and stop query logging.
41 #define SQL_COPT_SS_PERF_DATA_LOG_NOW    (SQL_COPT_SS_BASE+16) // Used to make a statistics log entry to disk.
42 #define SQL_COPT_SS_QUOTED_IDENT        (SQL_COPT_SS_BASE+17) // Enable/Disable Quoted Identifiers
43 #define SQL_COPT_SS_ANSI_NPW            (SQL_COPT_SS_BASE+18) // Enable/Disable ANSI NULL, Padding and Warnings
44 #define SQL_COPT_SS_BCP                    (SQL_COPT_SS_BASE+19) // Allow BCP usage on connection
45 #define SQL_COPT_SS_TRANSLATE            (SQL_COPT_SS_BASE+20) // Perform code page translation
46 #define SQL_COPT_SS_ATTACHDBFILENAME    (SQL_COPT_SS_BASE+21) // File name to be attached as a database
47 #define SQL_COPT_SS_CONCAT_NULL            (SQL_COPT_SS_BASE+22) // Enable/Disable CONCAT_NULL_YIELDS_NULL
48 #define SQL_COPT_SS_ENCRYPT                     (SQL_COPT_SS_BASE+23) // Allow strong encryption for data
49
50 #define SQL_COPT_SS_MAX_USED            SQL_COPT_SS_ENCRYPT
Lines 51 ... 432 are skipped.
433 typedef unsigned char     DBTINYINT;
434 typedef short                  DBSMALLINT;
435 typedef unsigned short  DBUSMALLINT;
436 typedef double                DBFLT8;
437 typedef unsigned char     DBBIT;
438 typedef unsigned char     DBBOOL;
439 typedef float                  DBFLT4;
440
441 typedef DBFLT4 DBREAL;
442 typedef UINT     DBUBOOL;
443
444 typedef struct dbvarychar
445 {
446     DBSMALLINT  len;
447     DBCHAR          str[DBMAXCHAR];
448 } DBVARYCHAR;
449
450 typedef struct dbvarybin
451 {
452     DBSMALLINT  len;
453     BYTE             array[DBMAXCHAR];
454 } DBVARYBIN;
455
456 typedef struct dbmoney
457 {                        // Internal representation of MONEY data type
458     LONG  mnyhigh;        // Money value *10,000 (High 32 bits/signed)
459     ULONG mnylow;        // Money value *10,000 (Low 32 bits/unsigned)
460 } DBMONEY;
461
462 typedef struct dbdatetime
463 {                        // Internal representation of DATETIME data type
464     LONG  dtdays;        // No of days since Jan-1-1900 (maybe negative)
465     ULONG dttime;        // No. of 300 hundredths of a second since midnight
466 } DBDATETIME;
467
468 typedef struct dbdatetime4
469 {                        // Internal representation of SMALLDATETIME data type
470     USHORT numdays;     // No of days since Jan-1-1900
471     USHORT nummins;     // No. of minutes since midnight
472 } DBDATETIM4;
473
474 typedef LONG DBMONEY4;    // Internal representation of SMALLMONEY data type
475                         // Money value *10,000
476
477 #define DBNUM_PREC_TYPE BYTE
478 #define DBNUM_SCALE_TYPE BYTE
479 #define DBNUM_VAL_TYPE BYTE
480
481 #if (ODBCVER < 0x0300)
482 #define MAXNUMERICLEN 16
483
484 typedef struct dbnumeric
485 {                            // Internal representation of NUMERIC data type
486     DBNUM_PREC_TYPE     precision;            // Precision
487     DBNUM_SCALE_TYPE  scale;                // Scale
488     BYTE              sign;                 // Sign (1 if positive, 0 if negative)
489     DBNUM_VAL_TYPE      val[MAXNUMERICLEN];    // Value
490 } DBNUMERIC;
491 typedef DBNUMERIC DBDECIMAL;// Internal representation of DECIMAL data type
492 #else    //    Use ODBC 3.0 definitions since same as DBLib
493 #define MAXNUMERICLEN SQL_MAX_NUMERIC_LEN
494 typedef SQL_NUMERIC_STRUCT DBNUMERIC;
495 typedef SQL_NUMERIC_STRUCT DBDECIMAL;
496 #endif
497
498 #endif //    MAXNUMERICLEN
499
500 #ifndef INT
501 typedef int INT;
502 typedef long                    DBINT;
503 #ifndef _LPCBYTE_DEFINED
504 #define _LPCBYTE_DEFINED
505 typedef const LPBYTE    LPCBYTE;
506 #endif
507 typedef DBINT *            LPDBINT;
508 #endif
509
510 /*****************************************************************
511  This struct is a global used for
512  gathering statistical data on the driver.
513  Access to this structure is controlled via the
514  pStatCrit;
515 ******************************************************************/
516
517 typedef struct sqlperf
518 {
519     // Application Profile Statistics
520     DWORD TimerResolution;
521     DWORD SQLidu;
522     DWORD SQLiduRows;
523     DWORD SQLSelects;
524     DWORD SQLSelectRows;
525     DWORD Transactions;
526     DWORD SQLPrepares;
527     DWORD ExecDirects;
528     DWORD SQLExecutes;
529     DWORD CursorOpens;
530     DWORD CursorSize;
531     DWORD CursorUsed;
532     LDOUBLE PercentCursorUsed;
533     LDOUBLE AvgFetchTime;
534     LDOUBLE AvgCursorSize;
535     LDOUBLE AvgCursorUsed;
536     DWORD SQLFetchTime;
537     DWORD SQLFetchCount;
538     DWORD CurrentStmtCount;
539     DWORD MaxOpenStmt;
540     DWORD SumOpenStmt;
541
542     // Connection Statistics
543     DWORD CurrentConnectionCount;
544     DWORD MaxConnectionsOpened;
545     DWORD SumConnectionsOpened;
546     DWORD SumConnectiontime;
547     LDOUBLE AvgTimeOpened;
548
549     // Network Statistics
550     DWORD ServerRndTrips;
551     DWORD BuffersSent;
552     DWORD BuffersRec;
553     DWORD BytesSent;
554     DWORD BytesRec;
555
556     // Time Statistics;
557     DWORD msExecutionTime;
558     DWORD msNetWorkServerTime;
559
560 }     SQLPERF;
561
562 // The following are options for SQL_COPT_SS_PERF_DATA and SQL_COPT_SS_PERF_QUERY
563 #define SQL_PERF_START    1            // Starts the driver sampling performance data.
564 #define SQL_PERF_STOP    2            // Stops the counters from sampling performance data.
565
566 // The following are defines for SQL_COPT_SS_PERF_DATA_LOG
567 #define SQL_SS_DL_DEFAULT    TEXT("STATS.LOG")
568
569 // The following are defines for SQL_COPT_SS_PERF_QUERY_LOG
570 #define SQL_SS_QL_DEFAULT    TEXT("QUERY.LOG")
571
572 // The following are defines for SQL_COPT_SS_PERF_QUERY_INTERVAL
573 #define SQL_SS_QI_DEFAULT    30000    //    30,000 milliseconds
574
575 //    ODBC BCP prototypes and defines
576
577 //    Return codes
578 #define SUCCEED         1
579 #define FAIL            0
580 #define SUCCEED_ABORT    2
581 #define SUCCEED_ASYNC    3
582
583 //    Transfer directions
584 #define DB_IN            1    // Transfer from client to server
585 #define DB_OUT            2    // Transfer from server to client
586
587 //    bcp_control option
588 #define BCPMAXERRS        1    // Sets max errors allowed
589 #define BCPFIRST        2    // Sets first row to be copied out
590 #define BCPLAST         3    // Sets number of rows to be copied out
591 #define BCPBATCH        4    // Sets input batch size
592 #define BCPKEEPNULLS    5    // Sets to insert NULLs for empty input values
593 #define BCPABORT        6    // Sets to have bcpexec return SUCCEED_ABORT
594 #define BCPODBC         7    // Sets ODBC canonical character output
595 #define BCPKEEPIDENTITY    8    // Sets IDENTITY_INSERT on
596 #define BCP6xFILEFMT    9    // DEPRECATED: Sets 6x file format on
597 #define BCPHINTSA        10    // Sets server BCP hints (ANSI string)
598 #define BCPHINTSW        11    // Sets server BCP hints (UNICODE string)
599 #define BCPFILECP        12    // Sets clients code page for the file
600 #define BCPUNICODEFILE    13    // Sets that the file contains unicode header
601 #define BCPTEXTFILE        14    // Sets BCP mode to expect a text file and to detect Unicode or ANSI automatically
602 #define BCPFILEFMT        15    // Sets file format version
603
604 //    BCPFILECP values
605 //    Any valid code page that is installed on the client can be passed plus:
606 #define BCPFILECP_ACP    0    // Data in file is in Windows code page
607 #define BCPFILECP_OEMCP    1    // Data in file is in OEM code page (default)
608 #define BCPFILECP_RAW    (-1)// Data in file is in Server code page (no conversion)
609
610 //    bcp_collen definition
611 #define SQL_VARLEN_DATA (-10)    //    Use default length for column
612
613 // BCP functions
614 DBINT    SQL_API bcp_batch (HDBC);
615 RETCODE SQL_API bcp_bind (HDBC, LPCBYTE, INT, DBINT, LPCBYTE, INT, INT, INT);
616 RETCODE SQL_API bcp_colfmt (HDBC, INT, BYTE, INT, DBINT, LPCBYTE, INT, INT);
617 RETCODE SQL_API bcp_collen (HDBC, DBINT, INT);
618 RETCODE SQL_API bcp_colptr (HDBC, LPCBYTE, INT);
619 RETCODE SQL_API bcp_columns (HDBC, INT);
620 RETCODE SQL_API bcp_control (HDBC, INT, void *);
621 DBINT    SQL_API bcp_done (HDBC);
622 RETCODE SQL_API bcp_exec (HDBC, LPDBINT);
623 RETCODE SQL_API bcp_getcolfmt (HDBC, INT, INT, void *, INT, INT *);
624 RETCODE SQL_API bcp_initA (HDBC, LPCSTR, LPCSTR, LPCSTR, INT);
625 RETCODE SQL_API bcp_initW (HDBC, LPCWSTR, LPCWSTR, LPCWSTR, INT);
626 RETCODE SQL_API bcp_moretext (HDBC, DBINT, LPCBYTE);
627 RETCODE SQL_API bcp_readfmtA (HDBC, LPCSTR);
628 RETCODE SQL_API bcp_readfmtW (HDBC, LPCWSTR);
629 RETCODE SQL_API bcp_sendrow (HDBC);
630 RETCODE SQL_API bcp_setcolfmt (HDBC, INT, INT, void *, INT);
631 RETCODE SQL_API bcp_writefmtA (HDBC, LPCSTR);
632 RETCODE SQL_API bcp_writefmtW (HDBC, LPCWSTR);
633 CHAR *    SQL_API dbprtypeA (INT);
634 WCHAR * SQL_API dbprtypeW (INT);
635
636 #ifdef UNICODE
637 #define bcp_init        bcp_initW
638 #define bcp_readfmt        bcp_readfmtW
639 #define bcp_writefmt    bcp_writefmtW
640 #define dbprtype        dbprtypeW
641 #define BCPHINTS        BCPHINTSW
642
643 #else
644 #define bcp_init        bcp_initA
645 #define bcp_readfmt        bcp_readfmtA
646 #define bcp_writefmt    bcp_writefmtA
647 #define dbprtype        dbprtypeA
648 #define BCPHINTS        BCPHINTSA
649 #endif
650
651 //    SQL Server catalog extensions for distributed queries
652 SQLRETURN SQL_API SQLLinkedServers (SQLHSTMT);
653 SQLRETURN SQL_API SQLLinkedCatalogsA (SQLHSTMT, LPCSTR, SWORD);
654 SQLRETURN SQL_API SQLLinkedCatalogsW (SQLHSTMT, LPCWSTR, SWORD);
655
656 //    SQL Server extensions for server enumeration
657 HANDLE     SQL_API SQLInitEnumServers(__in LPWSTR pwchServerName, __in LPWSTR pwchInstanceName);
658 RETCODE  SQL_API SQLGetNextEnumeration (HANDLE hEnumHandle,BYTE * prgEnumData,INT * piEnumLength);
659 RETCODE  SQL_API SQLCloseEnumServers (HANDLE hEnumHandle);
660
661 #ifdef UNICODE
662 #define SQLLinkedCatalogs    SQLLinkedCatalogsW
663 #else
664 #define SQLLinkedCatalogs    SQLLinkedCatalogsA
665 #endif
666
667 //  BCP column format properties
668 #define BCP_FMT_TYPE            0x01
669 #define BCP_FMT_INDICATOR_LEN    0x02
670 #define BCP_FMT_DATA_LEN        0x03
671 #define    BCP_FMT_TERMINATOR        0x04
672 #define BCP_FMT_SERVER_COL        0x05
673 #define BCP_FMT_COLLATION        0x06
674 #define BCP_FMT_COLLATION_ID    0x07
675
676 //    The following options have been deprecated
677
678 #define SQL_FAST_CONNECT                (SQL_COPT_SS_BASE+0)
679 //    Defines for use with SQL_FAST_CONNECT - only useable before connecting
680 #define SQL_FC_OFF        0L            //    Fast connect is off
681 #define SQL_FC_ON        1L            //    Fast connect is on
682 #define SQL_FC_DEFAULT    SQL_FC_OFF
683 #define SQL_COPT_SS_ANSI_OEM            (SQL_COPT_SS_BASE+6)
684 #define SQL_AO_OFF                        0L
685 #define SQL_AO_ON                        1L
686 #define SQL_AO_DEFAULT                    SQL_AO_OFF
687
688 //    Define old names
689 #define SQL_REMOTE_PWD                    SQL_COPT_SS_REMOTE_PWD
690 #define SQL_USE_PROCEDURE_FOR_PREPARE    SQL_COPT_SS_USE_PROC_FOR_PREP
691 #define SQL_INTEGRATED_SECURITY         SQL_COPT_SS_INTEGRATED_SECURITY
692 #define SQL_PRESERVE_CURSORS            SQL_COPT_SS_PRESERVE_CURSORS
693 #define SQL_TEXTPTR_LOGGING             SQL_SOPT_SS_TEXTPTR_LOGGING
694 #define SQL_CA_SS_BASE_COLUMN_NAME        SQL_DESC_BASE_COLUMN_NAME
695 #define SQLDECIMALN                        0x6a
696 #define SQLNUMERICN                     0x6c
697
698 #ifdef __cplusplus
699 }                                     /* End of extern "C" { */
700 #endif  /* __cplusplus */
701 #endif
702
703 //    End of odbcss.h
704
705