php_mssql.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Frank M. Kromann <frank@kromann.info> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. #ifndef PHP_MSSQL_H
  20. #define PHP_MSSQL_H
  21. #if HAVE_MSSQL
  22. #define MSDBLIB
  23. /* FreeTDS checks for PHP_MSSQL_API for avoid type redefinition */
  24. #ifdef HAVE_FREETDS
  25. #define PHP_MSSQL_API
  26. #endif
  27. #include <sqlfront.h>
  28. #include <sqldb.h>
  29. typedef short TDS_SHORT;
  30. #ifdef HAVE_FREETDS
  31. #define MSSQL_VERSION "FreeTDS"
  32. #define SQLTEXT SYBTEXT
  33. #define SQLCHAR SYBCHAR
  34. #define SQLVARCHAR SYBVARCHAR
  35. #define SQLINT1 SYBINT1
  36. #define SQLINT2 SYBINT2
  37. #define SQLINT4 SYBINT4
  38. #define SQLINTN SYBINTN
  39. #define SQLBIT SYBBIT
  40. #define SQLFLT4 SYBREAL
  41. #define SQLFLT8 SYBFLT8
  42. #define SQLFLTN SYBFLTN
  43. #define SQLDECIMAL SYBDECIMAL
  44. #define SQLNUMERIC SYBNUMERIC
  45. #define SQLDATETIME SYBDATETIME
  46. #define SQLDATETIM4 SYBDATETIME4
  47. #define SQLDATETIMN SYBDATETIMN
  48. #define SQLMONEY SYBMONEY
  49. #define SQLMONEY4 SYBMONEY4
  50. #define SQLMONEYN SYBMONEYN
  51. #define SQLIMAGE SYBIMAGE
  52. #define SQLBINARY SYBBINARY
  53. #define SQLVARBINARY SYBVARBINARY
  54. #ifdef SQLUNIQUE /* FreeTSD 0.61+ */
  55. #define SQLUNIQUE SYBUNIQUE
  56. #endif
  57. #define DBERRHANDLE(a, b) dberrhandle(b)
  58. #define DBMSGHANDLE(a, b) dbmsghandle(b)
  59. #define DBSETOPT(a, b, c) dbsetopt(a, b, c, -1)
  60. #define NO_MORE_RPC_RESULTS 3
  61. #ifndef dbfreelogin
  62. #define dbfreelogin dbloginfree
  63. #endif
  64. #define dbrpcexec dbrpcsend
  65. typedef unsigned char *LPBYTE;
  66. typedef float DBFLT4;
  67. #else
  68. #define MSSQL_VERSION "7.0"
  69. #define DBERRHANDLE(a, b) dbprocerrhandle(a, b)
  70. #define DBMSGHANDLE(a, b) dbprocmsghandle(a, b)
  71. #define EHANDLEFUNC DBERRHANDLE_PROC
  72. #define MHANDLEFUNC DBMSGHANDLE_PROC
  73. #define DBSETOPT(a, b, c) dbsetopt(a, b, c)
  74. #endif
  75. #define coltype(j) dbcoltype(mssql_ptr->link,j)
  76. #define intcol(i) ((int) *(DBINT *) dbdata(mssql_ptr->link,i))
  77. #define smallintcol(i) ((int) *(DBSMALLINT *) dbdata(mssql_ptr->link,i))
  78. #define tinyintcol(i) ((int) *(DBTINYINT *) dbdata(mssql_ptr->link,i))
  79. #define anyintcol(j) (coltype(j)==SQLINT4?intcol(j):(coltype(j)==SQLINT2?smallintcol(j):tinyintcol(j)))
  80. #define charcol(i) ((DBCHAR *) dbdata(mssql_ptr->link,i))
  81. #define floatcol4(i) (*(DBFLT4 *) dbdata(mssql_ptr->link,i))
  82. #define floatcol8(i) (*(DBFLT8 *) dbdata(mssql_ptr->link,i))
  83. #ifdef ZTS
  84. #include "TSRM.h"
  85. #endif
  86. extern zend_module_entry mssql_module_entry;
  87. #define mssql_module_ptr &mssql_module_entry
  88. PHP_MINIT_FUNCTION(mssql);
  89. PHP_MSHUTDOWN_FUNCTION(mssql);
  90. PHP_RINIT_FUNCTION(mssql);
  91. PHP_RSHUTDOWN_FUNCTION(mssql);
  92. PHP_MINFO_FUNCTION(mssql);
  93. PHP_FUNCTION(mssql_connect);
  94. PHP_FUNCTION(mssql_pconnect);
  95. PHP_FUNCTION(mssql_close);
  96. PHP_FUNCTION(mssql_select_db);
  97. PHP_FUNCTION(mssql_query);
  98. PHP_FUNCTION(mssql_fetch_batch);
  99. PHP_FUNCTION(mssql_rows_affected);
  100. PHP_FUNCTION(mssql_free_result);
  101. PHP_FUNCTION(mssql_get_last_message);
  102. PHP_FUNCTION(mssql_num_rows);
  103. PHP_FUNCTION(mssql_num_fields);
  104. PHP_FUNCTION(mssql_fetch_field);
  105. PHP_FUNCTION(mssql_fetch_row);
  106. PHP_FUNCTION(mssql_fetch_array);
  107. PHP_FUNCTION(mssql_fetch_assoc);
  108. PHP_FUNCTION(mssql_fetch_object);
  109. PHP_FUNCTION(mssql_field_length);
  110. PHP_FUNCTION(mssql_field_name);
  111. PHP_FUNCTION(mssql_field_type);
  112. PHP_FUNCTION(mssql_data_seek);
  113. PHP_FUNCTION(mssql_field_seek);
  114. PHP_FUNCTION(mssql_result);
  115. PHP_FUNCTION(mssql_next_result);
  116. PHP_FUNCTION(mssql_min_error_severity);
  117. PHP_FUNCTION(mssql_min_message_severity);
  118. PHP_FUNCTION(mssql_init);
  119. PHP_FUNCTION(mssql_bind);
  120. PHP_FUNCTION(mssql_execute);
  121. PHP_FUNCTION(mssql_free_statement);
  122. PHP_FUNCTION(mssql_guid_string);
  123. typedef struct mssql_link {
  124. LOGINREC *login;
  125. DBPROCESS *link;
  126. int valid;
  127. } mssql_link;
  128. typedef struct mssql_statement {
  129. int id;
  130. mssql_link *link;
  131. HashTable *binds;
  132. int executed;
  133. } mssql_statement;
  134. typedef struct {
  135. zval *zval;
  136. /* TODO: more data for special types (BLOBS, NUMERIC...) */
  137. } mssql_bind;
  138. ZEND_BEGIN_MODULE_GLOBALS(mssql)
  139. long default_link;
  140. long num_links,num_persistent;
  141. long max_links,max_persistent;
  142. zend_bool allow_persistent;
  143. char *appname;
  144. char *server_message;
  145. #ifdef HAVE_FREETDS
  146. char *charset;
  147. #endif
  148. long min_error_severity, min_message_severity;
  149. long cfg_min_error_severity, cfg_min_message_severity;
  150. long connect_timeout, timeout;
  151. zend_bool compatibility_mode;
  152. void (*get_column_content)(mssql_link *mssql_ptr,int offset,zval *result,int column_type TSRMLS_DC);
  153. long textsize, textlimit, batchsize;
  154. zend_bool datetimeconvert;
  155. HashTable *resource_list, *resource_plist;
  156. zend_bool secure_connection;
  157. long max_procs;
  158. ZEND_END_MODULE_GLOBALS(mssql)
  159. #define MSSQL_ROWS_BLOCK 128
  160. typedef struct mssql_field {
  161. char *name,*column_source;
  162. long max_length;
  163. int numeric;
  164. int type;
  165. } mssql_field;
  166. typedef struct mssql_result {
  167. zval **data;
  168. mssql_field *fields;
  169. mssql_link *mssql_ptr;
  170. mssql_statement * statement;
  171. int batchsize;
  172. int lastresult;
  173. int blocks_initialized;
  174. int cur_row,cur_field;
  175. int num_rows,num_fields,have_fields;
  176. } mssql_result;
  177. #ifdef ZTS
  178. # define MS_SQL_G(v) TSRMG(mssql_globals_id, zend_mssql_globals *, v)
  179. #else
  180. # define MS_SQL_G(v) (mssql_globals.v)
  181. #endif
  182. #else
  183. #define mssql_module_ptr NULL
  184. #endif /* HAVE_MSSQL */
  185. #define phpext_mssql_ptr mssql_module_ptr
  186. #endif /* PHP_MSSQL_H */