1 /********************************************************************/ 2 /* */ 3 /* db_tds.h TDS interfaces used by Seed7. */ 4 /* Copyright (C) 1989 - 2020 Thomas Mertes */ 5 /* */ 6 /* This file is part of the Seed7 Runtime Library. */ 7 /* */ 8 /* The Seed7 Runtime Library is free software; you can */ 9 /* redistribute it and/or modify it under the terms of the GNU */ 10 /* Lesser General Public License as published by the Free Software */ 11 /* Foundation; either version 2.1 of the License, or (at your */ 12 /* option) any later version. */ 13 /* */ 14 /* The Seed7 Runtime Library is distributed in the hope that it */ 15 /* will be useful, but WITHOUT ANY WARRANTY; without even the */ 16 /* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR */ 17 /* PURPOSE. See the GNU Lesser General Public License for more */ 18 /* details. */ 19 /* */ 20 /* You should have received a copy of the GNU Lesser General */ 21 /* Public License along with this program; if not, write to the */ 22 /* Free Software Foundation, Inc., 51 Franklin Street, */ 23 /* Fifth Floor, Boston, MA 02110-1301, USA. */ 24 /* */ 25 /* Module: Seed7 Runtime Library */ 26 /* File: seed7/src/db_tds.h */ 27 /* Changes: 2018 - 2020 Thomas Mertes */ 28 /* Content: TDS interfaces used by Seed7. */ 29 /* */ 30 /********************************************************************/ 31 32 #if defined(__cplusplus) || defined(c_plusplus) 33 extern "C" { 34 #endif 35 36 typedef int RETCODE; 37 38 typedef unsigned char DBBOOL; 39 typedef char DBCHAR; 40 typedef unsigned char BYTE; 41 typedef INT16TYPE DBSMALLINT; 42 typedef INT32TYPE DBINT; 43 typedef INT64TYPE DBBIGINT; 44 typedef UINT16TYPE DBUSMALLINT; 45 typedef UINT32TYPE DBUINT; 46 typedef UINT64TYPE DBUBIGINT; 47 48 typedef struct dbtypeinfo { 49 DBINT precision; 50 DBINT scale; 51 } DBTYPEINFO; 52 53 #define MAXCOLNAMELEN 512 54 55 typedef struct { 56 DBINT SizeOfStruct; 57 DBCHAR Name[MAXCOLNAMELEN + 2]; 58 DBCHAR ActualName[MAXCOLNAMELEN + 2]; 59 DBCHAR TableName[MAXCOLNAMELEN + 2]; 60 short Type; 61 DBINT UserType; 62 DBINT MaxLength; 63 BYTE Precision; 64 BYTE Scale; 65 int VarLength; 66 BYTE Null; 67 BYTE CaseSensitive; 68 BYTE Updatable; 69 int Identity; 70 } DBCOL; 71 72 typedef struct { 73 DBUBIGINT time; 74 DBINT date; 75 DBSMALLINT offset; 76 DBUSMALLINT time_prec:3; 77 DBUSMALLINT unused_data:10; 78 DBUSMALLINT has_time:1; 79 DBUSMALLINT has_date:1; 80 DBUSMALLINT has_offset:1; 81 } DBDATETIMEALL; 82 83 typedef struct tds_dblib_loginrec LOGINREC; 84 85 typedef struct tds_dblib_dbprocess DBPROCESS; 86 87 typedef int (*EHANDLEFUNC) (DBPROCESS *dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr); 88 89 typedef int (*MHANDLEFUNC) (DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, 90 char *proc, int line); 91 92 #define NO_MORE_ROWS -2 93 #define MORE_ROWS -1 94 #define FAIL 0 95 #define SUCCEED 1 96 #define NO_MORE_RESULTS 2 97 98 #define INT_EXIT 0 99 #define INT_CONTINUE 1 100 #define INT_CANCEL 2 101 #define INT_TIMEOUT 3 102 103 #define SYBETIME 20003 /* SQL Server connection timed out. */ 104 105 #define SYBVOID 31 106 #define SYBIMAGE 34 107 #define SYBTEXT 35 108 #define SYBVARBINARY 37 109 #define SYBINTN 38 110 #define SYBVARCHAR 39 111 #define SYBMSDATE 40 112 #define SYBMSTIME 41 113 #define SYBMSDATETIME2 42 114 #define SYBMSDATETIMEOFFSET 43 115 #define SYBBINARY 45 116 #define SYBCHAR 47 117 #define SYBINT1 48 118 #define SYBDATE 49 119 #define SYBBIT 50 120 #define SYBTIME 51 121 #define SYBINT2 52 122 #define SYBINT4 56 123 #define SYBDATETIME4 58 124 #define SYBREAL 59 125 #define SYBMONEY 60 126 #define SYBDATETIME 61 127 #define SYBFLT8 62 128 #define SYBNTEXT 99 129 #define SYBNVARCHAR 103 130 #define SYBBITN 104 131 #define SYBDECIMAL 106 132 #define SYBNUMERIC 108 133 #define SYBFLTN 109 134 #define SYBMONEYN 110 135 #define SYBDATETIMN 111 136 #define SYBMONEY4 122 137 #define SYBINT8 127 138 #define SYBBIGDATETIME 187 139 #define SYBBIGTIME 188 140 141 #define CHARBIND 0 142 #define STRINGBIND 1 143 #define NTBSTRINGBIND 2 144 #define VARYCHARBIND 3 145 #define VARYBINBIND 4 146 #define TINYBIND 6 147 #define SMALLBIND 7 148 #define INTBIND 8 149 #define FLT8BIND 9 150 #define REALBIND 10 151 #define DATETIMEBIND 11 152 #define SMALLDATETIMEBIND 12 153 #define MONEYBIND 13 154 #define SMALLMONEYBIND 14 155 #define BINARYBIND 15 156 #define BITBIND 16 157 #define NUMERICBIND 17 158 #define DECIMALBIND 18 159 #define SRCNUMERICBIND 19 160 #define SRCDECIMALBIND 20 161 #define DATEBIND 21 162 #define TIMEBIND 22 163 #define BIGDATETIMEBIND 23 164 #define BIGTIMEBIND 24 165 #define BIGINTBIND 30 166 #define DATETIME2BIND 31 167 #define MAXBINDTYPES 32 168 169 #define DBSETHOST 1 170 #define DBSETUSER 2 171 #define DBSETPWD 3 172 #define DBSETCHARSET 10 173 174 #define DBSETLHOST(x,y) dbsetlname((x), (y), DBSETHOST) 175 #define DBSETLUSER(x,y) dbsetlname((x), (y), DBSETUSER) 176 #define DBSETLPWD(x,y) dbsetlname((x), (y), DBSETPWD) 177 #define DBSETLCHARSET(x,y) dbsetlname((x), (y), DBSETCHARSET) 178 179 #ifdef MSDBLIB 180 #define dbopen(x,y) tdsdbopen((x),(y), 1) 181 #else 182 #define dbopen(x,y) tdsdbopen((x),(y), 0) 183 #endif 184 185 RETCODE dbbind (DBPROCESS *dbproc, 186 int column, 187 int vartype, 188 DBINT varlen, 189 BYTE *varaddr); 190 void dbclose (DBPROCESS * dbproc); 191 DBINT dbcollen (DBPROCESS *dbproc, int column); 192 char *dbcolname (DBPROCESS *dbproc, int column); 193 int dbcoltype (DBPROCESS *dbproc, int column); 194 DBTYPEINFO *dbcoltypeinfo (DBPROCESS *dbproc, int column); 195 RETCODE dbcmd (DBPROCESS *dbproc, const char *cmdstring); 196 BYTE *dbdata (DBPROCESS *dbproc, int column); 197 DBINT dbdatlen (DBPROCESS *dbproc, int column); 198 EHANDLEFUNC dberrhandle (EHANDLEFUNC handler); 199 void dbexit (void); 200 RETCODE dbinit (void); 201 LOGINREC *dblogin (void); 202 void dbloginfree(LOGINREC *loginptr); 203 MHANDLEFUNC dbmsghandle (MHANDLEFUNC handler); 204 RETCODE dbnextrow (DBPROCESS *dbproc); 205 int dbnumcols (DBPROCESS *dbproc); 206 RETCODE dbnullbind (DBPROCESS *dbproc, int column, DBINT *indicator); 207 RETCODE dbresults (DBPROCESS *dbproc); 208 RETCODE dbsetlname (LOGINREC * login, const char *value, int which); 209 RETCODE dbsqlexec (DBPROCESS *dbproc); 210 RETCODE dbtablecolinfo (DBPROCESS *dbproc, 211 DBINT column, 212 DBCOL *pdbcol); 213 RETCODE dbuse (DBPROCESS * dbproc, const char *name); 214 DBPROCESS *tdsdbopen (LOGINREC * login, const char *server, int msdblib); 215 216 #if defined(__cplusplus) || defined(c_plusplus) 217 } 218 #endif 219