fakesql.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * fakesql.h --
  3. *
  4. * Include file that defines the subset of SQL/CLI that TDBC
  5. * uses, so that tdbc::odbc can build without an explicit ODBC
  6. * dependency. It comprises only data type, constant and
  7. * function declarations.
  8. *
  9. * The programmers of this file believe that it contains material not
  10. * subject to copyright under the doctrines of scenes a faire and
  11. * of merger of idea and expression. Accordingly, this file is in the
  12. * public domain.
  13. *
  14. *-----------------------------------------------------------------------------
  15. */
  16. #ifndef FAKESQL_H_INCLUDED
  17. #define FAKESQL_H_INCLUDED
  18. #include <stddef.h>
  19. #ifndef MODULE_SCOPE
  20. #define MODULE_SCOPE extern
  21. #endif
  22. /* Limits */
  23. #define SQL_MAX_DSN_LENGTH 32
  24. #define SQL_MAX_MESSAGE_LENGTH 512
  25. /* Fundamental data types */
  26. #ifndef _WIN32
  27. typedef int BOOL;
  28. typedef unsigned int DWORD;
  29. typedef void* HANDLE;
  30. typedef HANDLE HWND;
  31. typedef unsigned short WCHAR;
  32. typedef char* LPSTR;
  33. typedef WCHAR* LPWSTR;
  34. typedef const char* LPCSTR;
  35. typedef const WCHAR* LPCWSTR;
  36. typedef unsigned short WORD;
  37. #endif
  38. typedef void* PVOID;
  39. typedef short RETCODE;
  40. typedef long SDWORD;
  41. typedef short SWORD;
  42. typedef unsigned short USHORT;
  43. typedef USHORT UWORD;
  44. /* ODBC data types */
  45. typedef Tcl_WideInt SQLBIGINT;
  46. typedef unsigned char SQLCHAR;
  47. typedef double SQLDOUBLE;
  48. typedef void* SQLHANDLE;
  49. typedef SDWORD SQLINTEGER;
  50. typedef PVOID SQLPOINTER;
  51. typedef SWORD SQLSMALLINT;
  52. typedef Tcl_WideUInt SQLUBIGINT;
  53. typedef unsigned char SQLUCHAR;
  54. typedef unsigned int SQLUINTEGER;
  55. typedef UWORD SQLUSMALLINT;
  56. typedef WCHAR SQLWCHAR;
  57. typedef SQLSMALLINT SQLRETURN;
  58. /* TODO - Check how the SQLLEN and SQLULEN types are handled on
  59. * 64-bit Unix. */
  60. #if defined(_WIN64)
  61. typedef Tcl_WideInt SQLLEN;
  62. typedef Tcl_WideUInt SQLULEN;
  63. #else
  64. typedef SQLINTEGER SQLLEN;
  65. typedef SQLUINTEGER SQLULEN;
  66. #endif
  67. /* Handle types */
  68. typedef SQLHANDLE SQLHENV;
  69. typedef SQLHANDLE SQLHDBC;
  70. typedef SQLHANDLE SQLHSTMT;
  71. typedef HWND SQLHWND;
  72. #define SQL_HANDLE_DBC 2
  73. #define SQL_HANDLE_ENV 1
  74. #define SQL_HANDLE_STMT 3
  75. /* Null handles */
  76. #define SQL_NULL_HANDLE ((SQLHANDLE) 0)
  77. #define SQL_NULL_HENV ((SQLHENV) 0)
  78. #define SQL_NULL_HDBC ((SQLHDBC) 0)
  79. #define SQL_NULL_HSTMT ((SQLHSTMT) 0)
  80. /* SQL data types */
  81. enum _SQL_DATATYPE {
  82. SQL_BIGINT = -5,
  83. SQL_BINARY = -2,
  84. SQL_BIT = -7,
  85. SQL_CHAR = 1,
  86. SQL_DATE = 9,
  87. SQL_DECIMAL = 3,
  88. SQL_DOUBLE = 8,
  89. SQL_FLOAT = 6,
  90. SQL_INTEGER = 4,
  91. SQL_LONGVARBINARY = -4,
  92. SQL_LONGVARCHAR = -1,
  93. SQL_NUMERIC = 2,
  94. SQL_REAL = 7,
  95. SQL_SMALLINT = 5,
  96. SQL_TIME = 10,
  97. SQL_TIMESTAMP = 11,
  98. SQL_TINYINT = -6,
  99. SQL_VARBINARY = -3,
  100. SQL_VARCHAR = 12,
  101. SQL_WCHAR = -8,
  102. SQL_WVARCHAR = -9,
  103. SQL_WLONGVARCHAR = -10,
  104. };
  105. /* C data types */
  106. #define SQL_SIGNED_OFFSET (-20)
  107. #define SQL_C_BINARY SQL_BINARY
  108. #define SQL_C_CHAR SQL_CHAR
  109. #define SQL_C_DOUBLE SQL_DOUBLE
  110. #define SQL_C_LONG SQL_INTEGER
  111. #define SQL_C_SBIGINT SQL_BIGINT + SQL_SIGNED_OFFSET
  112. #define SQL_C_SLONG SQL_INTEGER + SQL_SIGNED_OFFSET
  113. #define SQL_C_WCHAR SQL_WCHAR
  114. /* Parameter transmission diretions */
  115. #define SQL_PARAM_INPUT 1
  116. /* Status returns */
  117. #define SQL_ERROR (-1)
  118. #define SQL_NO_DATA 100
  119. #define SQL_NO_TOTAL (-4)
  120. #define SQL_SUCCESS 0
  121. #define SQL_SUCCESS_WITH_INFO 1
  122. #define SQL_SUCCEEDED(rc) (((rc)&(~1))==0)
  123. /* Diagnostic fields */
  124. enum _SQL_DIAG {
  125. SQL_DIAG_SQLSTATE = 4,
  126. };
  127. /* Transaction isolation levels */
  128. #define SQL_TXN_READ_COMMITTED 2
  129. #define SQL_TXN_READ_UNCOMMITTED 1
  130. #define SQL_TXN_REPEATABLE_READ 4
  131. #define SQL_TXN_SERIALIZABLE 8
  132. /* Access modes */
  133. #define SQL_MODE_READ_ONLY 1UL
  134. #define SQL_MODE_READ_WRITE 0UL
  135. /* ODBC properties */
  136. #define SQL_ACCESS_MODE 101
  137. #define SQL_AUTOCOMMIT 102
  138. #define SQL_TXN_ISOLATION 108
  139. /* ODBC attributes */
  140. #define SQL_ATTR_ACCESS_MODE SQL_ACCESS_MODE
  141. #define SQL_ATTR_CONNECTION_TIMEOUT 113
  142. #define SQL_ATTR_ODBC_VERSION 200
  143. #define SQL_ATTR_TXN_ISOLATION SQL_TXN_ISOLATION
  144. #define SQL_ATTR_AUTOCOMMIT SQL_AUTOCOMMIT
  145. /* Nullable? */
  146. #define SQL_NULLABLE_UNKNOWN 2
  147. /* Placeholder for length of missing data */
  148. #define SQL_NULL_DATA (-1)
  149. /* ODBC versions */
  150. #define SQL_OV_ODBC3 3UL
  151. #define SQL_ODBC_VER 10
  152. /* SQLDriverConnect flags */
  153. #define SQL_DRIVER_COMPLETE_REQUIRED 3
  154. #define SQL_DRIVER_NOPROMPT 0
  155. /* SQLGetTypeInfo flags */
  156. #define SQL_ALL_TYPES 0
  157. /* Transaction actions */
  158. #define SQL_COMMIT 0
  159. #define SQL_ROLLBACK 1
  160. /* Data source fetch flags */
  161. #define SQL_FETCH_FIRST 2
  162. #define SQL_FETCH_FIRST_SYSTEM 32
  163. #define SQL_FETCH_FIRST_USER 31
  164. #define SQL_FETCH_NEXT 1
  165. /* ODBCINST actions */
  166. #define ODBC_ADD_DSN 1
  167. #define ODBC_CONFIG_DSN 2
  168. #define ODBC_REMOVE_DSN 3
  169. #define ODBC_ADD_SYS_DSN 4
  170. #define ODBC_CONFIG_SYS_DSN 5
  171. #define ODBC_REMOVE_SYS_DSN 6
  172. /* ODBCINST errors */
  173. #define ODBC_ERROR_GENERAL_ERR 1
  174. #define ODBC_ERROR_INVALID_BUFF_LEN 2
  175. #define ODBC_ERROR_INVALID_HWND 3
  176. #define ODBC_ERROR_INVALID_STR 4
  177. #define ODBC_ERROR_INVALID_REQUEST_TYPE 5
  178. #define ODBC_ERROR_COMPONENT_NOT_FOUND 6
  179. #define ODBC_ERROR_INVALID_NAME 7
  180. #define ODBC_ERROR_INVALID_KEYWORD_VALUE 8
  181. #define ODBC_ERROR_INVALID_DSN 9
  182. #define ODBC_ERROR_INVALID_INF 10
  183. #define ODBC_ERROR_REQUEST_FAILED 11
  184. #define ODBC_ERROR_INVALID_PATH 12
  185. #define ODBC_ERROR_LOAD_LIB_FAILED 13
  186. #define ODBC_ERROR_INVALID_PARAM_SEQUENCE 14
  187. #define ODBC_ERROR_INVALID_LOG_FILE 15
  188. #define ODBC_ERROR_USER_CANCELED 16
  189. #define ODBC_ERROR_USAGE_UPDATE_FAILED 17
  190. #define ODBC_ERROR_CREATE_DSN_FAILED 18
  191. #define ODBC_ERROR_WRITING_SYSINFO_FAILED 19
  192. #define ODBC_ERROR_REMOVE_DSN_FAILED 20
  193. #define ODBC_ERROR_OUT_OF_MEM 21
  194. #define ODBC_ERROR_OUTPUT_STRING_TRUNCATED 22
  195. /* ODBC client library entry points */
  196. #ifdef _WIN32
  197. #define SQL_API __stdcall
  198. #define INSTAPI __stdcall
  199. #else
  200. #define SQL_API /* nothing */
  201. #define INSTAPI /* nothing */
  202. #endif
  203. #include "odbcStubs.h"
  204. MODULE_SCOPE const odbcStubDefs* odbcStubs;
  205. /*
  206. * Additional entry points in ODBCINST - all of these are optional
  207. * and resolved with Tcl_FindSymbol, not directly in Tcl_LoadLibrary.
  208. */
  209. MODULE_SCOPE BOOL (INSTAPI* SQLConfigDataSourceW)(HWND, WORD, LPCWSTR,
  210. LPCWSTR);
  211. MODULE_SCOPE BOOL (INSTAPI* SQLConfigDataSource)(HWND, WORD, LPCSTR, LPCSTR);
  212. MODULE_SCOPE BOOL (INSTAPI* SQLInstallerErrorW)(WORD, DWORD*, LPWSTR, WORD,
  213. WORD*);
  214. MODULE_SCOPE BOOL (INSTAPI* SQLInstallerError)(WORD, DWORD*, LPSTR, WORD,
  215. WORD*);
  216. /*
  217. * Function that initialises the stubs
  218. */
  219. MODULE_SCOPE Tcl_LoadHandle OdbcInitStubs(Tcl_Interp*, Tcl_LoadHandle*);
  220. #endif