birdstep.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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. | Authors: Nikolay P. Romanyuk <mag@redcom.ru> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. /*
  20. * TODO:
  21. * birdstep_fetch_into(),
  22. * Check all on real life apps.
  23. */
  24. #ifdef HAVE_CONFIG_H
  25. #include "config.h"
  26. #endif
  27. #include "php.h"
  28. #if WIN32
  29. # include "config.w32.h"
  30. # include "win95nt.h"
  31. # ifdef PHP_EXPORTS
  32. # define PHPAPI __declspec(dllexport)
  33. # else
  34. # define PHPAPI __declspec(dllimport)
  35. # endif
  36. #else
  37. # include <php_config.h>
  38. # define PHPAPI
  39. # define THREAD_LS
  40. #endif
  41. #ifdef HAVE_BIRDSTEP
  42. #include "php_birdstep.h"
  43. #include "ext/standard/info.h"
  44. #include "php_ini.h"
  45. /* {{{ arginfo */
  46. ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_connect, 0, 0, 3)
  47. ZEND_ARG_INFO(0, server)
  48. ZEND_ARG_INFO(0, user)
  49. ZEND_ARG_INFO(0, pass)
  50. ZEND_END_ARG_INFO()
  51. ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_close, 0, 0, 1)
  52. ZEND_ARG_INFO(0, id)
  53. ZEND_END_ARG_INFO()
  54. ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_exec, 0, 0, 2)
  55. ZEND_ARG_INFO(0, index)
  56. ZEND_ARG_INFO(0, exec_str)
  57. ZEND_END_ARG_INFO()
  58. ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_fetch, 0, 0, 1)
  59. ZEND_ARG_INFO(0, index)
  60. ZEND_END_ARG_INFO()
  61. ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_result, 0, 0, 2)
  62. ZEND_ARG_INFO(0, index)
  63. ZEND_ARG_INFO(0, col)
  64. ZEND_END_ARG_INFO()
  65. ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_freeresult, 0, 0, 1)
  66. ZEND_ARG_INFO(0, index)
  67. ZEND_END_ARG_INFO()
  68. ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_autocommit, 0, 0, 1)
  69. ZEND_ARG_INFO(0, index)
  70. ZEND_END_ARG_INFO()
  71. ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_off_autocommit, 0, 0, 1)
  72. ZEND_ARG_INFO(0, index)
  73. ZEND_END_ARG_INFO()
  74. ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_commit, 0, 0, 1)
  75. ZEND_ARG_INFO(0, index)
  76. ZEND_END_ARG_INFO()
  77. ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_rollback, 0, 0, 1)
  78. ZEND_ARG_INFO(0, index)
  79. ZEND_END_ARG_INFO()
  80. ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_fieldname, 0, 0, 2)
  81. ZEND_ARG_INFO(0, index)
  82. ZEND_ARG_INFO(0, col)
  83. ZEND_END_ARG_INFO()
  84. ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_fieldnum, 0, 0, 1)
  85. ZEND_ARG_INFO(0, index)
  86. ZEND_END_ARG_INFO()
  87. /* }}} */
  88. const zend_function_entry birdstep_functions[] = {
  89. PHP_FE(birdstep_connect, arginfo_birdstep_connect)
  90. PHP_FE(birdstep_close, arginfo_birdstep_close)
  91. PHP_FE(birdstep_exec, arginfo_birdstep_exec)
  92. PHP_FE(birdstep_fetch, arginfo_birdstep_fetch)
  93. PHP_FE(birdstep_result, arginfo_birdstep_result)
  94. PHP_FE(birdstep_freeresult, arginfo_birdstep_freeresult)
  95. PHP_FE(birdstep_autocommit, arginfo_birdstep_autocommit)
  96. PHP_FE(birdstep_off_autocommit, arginfo_birdstep_off_autocommit)
  97. PHP_FE(birdstep_commit, arginfo_birdstep_commit)
  98. PHP_FE(birdstep_rollback, arginfo_birdstep_rollback)
  99. PHP_FE(birdstep_fieldnum, arginfo_birdstep_fieldnum)
  100. PHP_FE(birdstep_fieldname, arginfo_birdstep_fieldname)
  101. /*
  102. * Temporary Function aliases until the next major upgrade to PHP.
  103. * These should allow users to continue to use their current scripts,
  104. * but should in reality warn the user that this functionality is
  105. * deprecated.
  106. */
  107. PHP_FALIAS(velocis_connect, birdstep_connect, arginfo_birdstep_connect)
  108. PHP_FALIAS(velocis_close, birdstep_close, arginfo_birdstep_close)
  109. PHP_FALIAS(velocis_exec, birdstep_exec, arginfo_birdstep_exec)
  110. PHP_FALIAS(velocis_fetch, birdstep_fetch, arginfo_birdstep_fetch)
  111. PHP_FALIAS(velocis_result, birdstep_result, arginfo_birdstep_result)
  112. PHP_FALIAS(velocis_freeresult, birdstep_freeresult, arginfo_birdstep_freeresult)
  113. PHP_FALIAS(velocis_autocommit, birdstep_autocommit, arginfo_birdstep_autocommit)
  114. PHP_FALIAS(velocis_off_autocommit, birdstep_off_autocommit, arginfo_birdstep_off_autocommit)
  115. PHP_FALIAS(velocis_commit, birdstep_commit, arginfo_birdstep_commit)
  116. PHP_FALIAS(velocis_rollback, birdstep_rollback, arginfo_birdstep_rollback)
  117. PHP_FALIAS(velocis_fieldnum, birdstep_fieldnum, arginfo_birdstep_fieldnum)
  118. PHP_FALIAS(velocis_fieldname, birdstep_fieldname, arginfo_birdstep_fieldname)
  119. /* End temporary aliases */
  120. {NULL, NULL, NULL}
  121. };
  122. zend_module_entry birdstep_module_entry = {
  123. STANDARD_MODULE_HEADER,
  124. "birdstep",
  125. birdstep_functions,
  126. PHP_MINIT(birdstep),
  127. PHP_MSHUTDOWN(birdstep),
  128. PHP_RINIT(birdstep),
  129. NULL,
  130. PHP_MINFO(birdstep),
  131. NO_VERSION_YET,
  132. STANDARD_MODULE_PROPERTIES
  133. };
  134. #ifdef COMPILE_DL_ODBC
  135. ZEND_GET_MODULE(birdstep)
  136. #endif
  137. THREAD_LS birdstep_module php_birdstep_module;
  138. THREAD_LS static HENV henv;
  139. #define PHP_GET_BIRDSTEP_RES_IDX(id) if (!(res = birdstep_find_result(list, id))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Not result index (%ld)", id); RETURN_FALSE; }
  140. #define PHP_BIRDSTEP_CHK_LNK(id) if (!(conn = birdstep_find_conn(list, id))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Not connection index (%ld)", id); RETURN_FALSE; }
  141. static void _close_birdstep_link(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  142. {
  143. VConn *conn = (VConn *)rsrc->ptr;
  144. if ( conn ) {
  145. efree(conn);
  146. }
  147. }
  148. static void _free_birdstep_result(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  149. {
  150. Vresult *res = (Vresult *)rsrc->ptr;
  151. if ( res && res->values ) {
  152. register int i;
  153. for ( i=0; i < res->numcols; i++ ) {
  154. if ( res->values[i].value )
  155. efree(res->values[i].value);
  156. }
  157. efree(res->values);
  158. }
  159. if ( res ) {
  160. efree(res);
  161. }
  162. }
  163. PHP_MINIT_FUNCTION(birdstep)
  164. {
  165. SQLAllocEnv(&henv);
  166. if ( cfg_get_long("birdstep.max_links",&php_birdstep_module.max_links) == FAILURE ) {
  167. php_birdstep_module.max_links = -1;
  168. }
  169. php_birdstep_module.num_links = 0;
  170. php_birdstep_module.le_link = zend_register_list_destructors_ex(_close_birdstep_link, NULL, "birdstep link", module_number);
  171. php_birdstep_module.le_result = zend_register_list_destructors_ex(_free_birdstep_result, NULL, "birdstep result", module_number);
  172. return SUCCESS;
  173. }
  174. PHP_RINIT_FUNCTION(birdstep)
  175. {
  176. return SUCCESS;
  177. }
  178. PHP_MINFO_FUNCTION(birdstep)
  179. {
  180. php_info_print_table_start();
  181. php_info_print_table_row(2, "RAIMA Birdstep Support", "enabled" );
  182. php_info_print_table_end();
  183. }
  184. PHP_MSHUTDOWN_FUNCTION(birdstep)
  185. {
  186. SQLFreeEnv(henv);
  187. return SUCCESS;
  188. }
  189. /* Some internal functions. Connections and result manupulate */
  190. static int birdstep_add_conn(HashTable *list,VConn *conn,HDBC hdbc TSRMLS_DC)
  191. {
  192. int ind;
  193. ind = zend_list_insert(conn,php_birdstep_module.le_link TSRMLS_CC);
  194. conn->hdbc = hdbc;
  195. conn->index = ind;
  196. return(ind);
  197. }
  198. static VConn * birdstep_find_conn(HashTable *list,int ind)
  199. {
  200. VConn *conn;
  201. int type;
  202. conn = zend_list_find(ind,&type);
  203. if ( !conn || type != php_birdstep_module.le_link ) {
  204. return(NULL);
  205. }
  206. return(conn);
  207. }
  208. static void birdstep_del_conn(HashTable *list,int ind)
  209. {
  210. zend_list_delete(ind);
  211. }
  212. static int birdstep_add_result(HashTable *list,Vresult *res,VConn *conn)
  213. {
  214. int ind;
  215. ind = zend_list_insert(res,php_birdstep_module.le_result);
  216. res->conn = conn;
  217. res->index = ind;
  218. return(ind);
  219. }
  220. static Vresult * birdstep_find_result(HashTable *list,int ind)
  221. {
  222. Vresult *res;
  223. int type;
  224. res = zend_list_find(ind,&type);
  225. if ( !res || type != php_birdstep_module.le_result ) {
  226. return(NULL);
  227. }
  228. return(res);
  229. }
  230. static void birdstep_del_result(HashTable *list,int ind)
  231. {
  232. zend_list_delete(ind);
  233. }
  234. /* Users functions */
  235. /* {{{ proto int birdstep_connect(string server, string user, string pass)
  236. */
  237. PHP_FUNCTION(birdstep_connect)
  238. {
  239. char *serv, *user, *pass;
  240. int serv_len, user_len, pass_len;
  241. RETCODE stat;
  242. HDBC hdbc;
  243. VConn *new;
  244. long ind;
  245. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &serv, &serv_len, &user, &user_len, &pass, &pass_len) == FAILURE) {
  246. return;
  247. }
  248. if ( php_birdstep_module.max_links != -1 && php_birdstep_module.num_links == php_birdstep_module.max_links ) {
  249. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Too many open connections (%d)",php_birdstep_module.num_links);
  250. RETURN_FALSE;
  251. }
  252. stat = SQLAllocConnect(henv,&hdbc);
  253. if ( stat != SQL_SUCCESS ) {
  254. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Could not allocate connection handle");
  255. RETURN_FALSE;
  256. }
  257. stat = SQLConnect(hdbc, serv, SQL_NTS, user, SQL_NTS, pass, SQL_NTS);
  258. if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
  259. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Could not connect to server \"%s\" for %s", serv, user);
  260. SQLFreeConnect(hdbc);
  261. RETURN_FALSE;
  262. }
  263. new = (VConn *)emalloc(sizeof(VConn));
  264. ind = birdstep_add_conn(list,new,hdbc TSRMLS_CC);
  265. php_birdstep_module.num_links++;
  266. RETURN_LONG(ind);
  267. }
  268. /* }}} */
  269. /* {{{ proto bool birdstep_close(int id)
  270. */
  271. PHP_FUNCTION(birdstep_close)
  272. {
  273. long id;
  274. VConn *conn;
  275. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
  276. return;
  277. }
  278. PHP_BIRDSTEP_CHK_LNK(id);
  279. SQLDisconnect(conn->hdbc);
  280. SQLFreeConnect(conn->hdbc);
  281. birdstep_del_conn(list, id);
  282. php_birdstep_module.num_links--;
  283. RETURN_TRUE;
  284. }
  285. /* }}} */
  286. /* {{{ proto int birdstep_exec(int index, string exec_str)
  287. */
  288. PHP_FUNCTION(birdstep_exec)
  289. {
  290. char *query;
  291. long ind;
  292. int query_len, indx;
  293. VConn *conn;
  294. Vresult *res;
  295. RETCODE stat;
  296. SWORD cols,i,colnamelen;
  297. SDWORD rows,coldesc;
  298. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &ind, &query, &query_len) == FAILURE) {
  299. return;
  300. }
  301. PHP_BIRDSTEP_CHK_LNK(ind);
  302. res = (Vresult *)emalloc(sizeof(Vresult));
  303. stat = SQLAllocStmt(conn->hdbc,&res->hstmt);
  304. if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
  305. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLAllocStmt return %d",stat);
  306. efree(res);
  307. RETURN_FALSE;
  308. }
  309. stat = SQLExecDirect(res->hstmt,query,SQL_NTS);
  310. if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
  311. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Cannot execute \"%s\" query",query);
  312. SQLFreeStmt(res->hstmt,SQL_DROP);
  313. efree(res);
  314. RETURN_FALSE;
  315. }
  316. /* Success query */
  317. stat = SQLNumResultCols(res->hstmt,&cols);
  318. if ( stat != SQL_SUCCESS ) {
  319. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLNumResultCols return %d",stat);
  320. SQLFreeStmt(res->hstmt,SQL_DROP);
  321. efree(res);
  322. RETURN_FALSE;
  323. }
  324. if ( !cols ) { /* Was INSERT, UPDATE, DELETE, etc. query */
  325. stat = SQLRowCount(res->hstmt,&rows);
  326. if ( stat != SQL_SUCCESS ) {
  327. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLNumResultCols return %d",stat);
  328. SQLFreeStmt(res->hstmt,SQL_DROP);
  329. efree(res);
  330. RETURN_FALSE;
  331. }
  332. SQLFreeStmt(res->hstmt,SQL_DROP);
  333. efree(res);
  334. RETURN_LONG(rows);
  335. } else { /* Was SELECT query */
  336. res->values = (VResVal *)safe_emalloc(sizeof(VResVal), cols, 0);
  337. res->numcols = cols;
  338. for ( i = 0; i < cols; i++ ) {
  339. SQLColAttributes(res->hstmt,i+1,SQL_COLUMN_NAME,
  340. res->values[i].name,sizeof(res->values[i].name),
  341. &colnamelen,NULL);
  342. SQLColAttributes(res->hstmt,i+1,SQL_COLUMN_TYPE,
  343. NULL,0,NULL,&res->values[i].valtype);
  344. switch ( res->values[i].valtype ) {
  345. case SQL_LONGVARBINARY:
  346. case SQL_LONGVARCHAR:
  347. res->values[i].value = NULL;
  348. continue;
  349. default:
  350. break;
  351. }
  352. SQLColAttributes(res->hstmt,i+1,SQL_COLUMN_DISPLAY_SIZE,
  353. NULL,0,NULL,&coldesc);
  354. res->values[i].value = (char *)emalloc(coldesc+1);
  355. SQLBindCol(res->hstmt,i+1,SQL_C_CHAR, res->values[i].value,coldesc+1, &res->values[i].vallen);
  356. }
  357. }
  358. res->fetched = 0;
  359. indx = birdstep_add_result(list,res,conn);
  360. RETURN_LONG(indx);
  361. }
  362. /* }}} */
  363. /* {{{ proto bool birdstep_fetch(int index)
  364. */
  365. PHP_FUNCTION(birdstep_fetch)
  366. {
  367. long ind;
  368. Vresult *res;
  369. RETCODE stat;
  370. UDWORD row;
  371. UWORD RowStat[1];
  372. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ind) == FAILURE) {
  373. return;
  374. }
  375. PHP_GET_BIRDSTEP_RES_IDX(ind);
  376. stat = SQLExtendedFetch(res->hstmt,SQL_FETCH_NEXT,1,&row,RowStat);
  377. if ( stat == SQL_NO_DATA_FOUND ) {
  378. SQLFreeStmt(res->hstmt,SQL_DROP);
  379. birdstep_del_result(list,Z_LVAL_PP(ind));
  380. RETURN_FALSE;
  381. }
  382. if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
  383. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLFetch return error");
  384. SQLFreeStmt(res->hstmt,SQL_DROP);
  385. birdstep_del_result(list,Z_LVAL_PP(ind));
  386. RETURN_FALSE;
  387. }
  388. res->fetched = 1;
  389. RETURN_TRUE;
  390. }
  391. /* }}} */
  392. /* {{{ proto mixed birdstep_result(int index, mixed col)
  393. */
  394. PHP_FUNCTION(birdstep_result)
  395. {
  396. zval **col;
  397. long ind;
  398. Vresult *res;
  399. RETCODE stat;
  400. int i,sql_c_type;
  401. UDWORD row;
  402. UWORD RowStat[1];
  403. SWORD indx = -1;
  404. char *field = NULL;
  405. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lZ", &ind, &col) == FAILURE) {
  406. return;
  407. }
  408. PHP_GET_BIRDSTEP_RES_IDX(ind);
  409. if ( Z_TYPE_PP(col) == IS_STRING ) {
  410. field = Z_STRVAL_PP(col);
  411. } else {
  412. convert_to_long_ex(col);
  413. indx = Z_LVAL_PP(col);
  414. }
  415. if ( field ) {
  416. for ( i = 0; i < res->numcols; i++ ) {
  417. if ( !strcasecmp(res->values[i].name,field)) {
  418. indx = i;
  419. break;
  420. }
  421. }
  422. if ( indx < 0 ) {
  423. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field %s not found",field);
  424. RETURN_FALSE;
  425. }
  426. } else {
  427. if ( indx < 0 || indx >= res->numcols ) {
  428. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Field index not in range");
  429. RETURN_FALSE;
  430. }
  431. }
  432. if ( !res->fetched ) {
  433. stat = SQLExtendedFetch(res->hstmt,SQL_FETCH_NEXT,1,&row,RowStat);
  434. if ( stat == SQL_NO_DATA_FOUND ) {
  435. SQLFreeStmt(res->hstmt,SQL_DROP);
  436. birdstep_del_result(list,Z_LVAL_PP(ind));
  437. RETURN_FALSE;
  438. }
  439. if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
  440. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLFetch return error");
  441. SQLFreeStmt(res->hstmt,SQL_DROP);
  442. birdstep_del_result(list,Z_LVAL_PP(ind));
  443. RETURN_FALSE;
  444. }
  445. res->fetched = 1;
  446. }
  447. switch ( res->values[indx].valtype ) {
  448. case SQL_LONGVARBINARY:
  449. sql_c_type = SQL_C_BINARY;
  450. goto l1;
  451. case SQL_LONGVARCHAR:
  452. sql_c_type = SQL_C_CHAR;
  453. l1:
  454. if ( !res->values[indx].value ) {
  455. res->values[indx].value = emalloc(4096);
  456. }
  457. stat = SQLGetData(res->hstmt,indx+1,sql_c_type,
  458. res->values[indx].value,4095,&res->values[indx].vallen);
  459. if ( stat == SQL_NO_DATA_FOUND ) {
  460. SQLFreeStmt(res->hstmt,SQL_DROP);
  461. birdstep_del_result(list,Z_LVAL_PP(ind));
  462. RETURN_FALSE;
  463. }
  464. if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
  465. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLGetData return error");
  466. SQLFreeStmt(res->hstmt,SQL_DROP);
  467. birdstep_del_result(list,Z_LVAL_PP(ind));
  468. RETURN_FALSE;
  469. }
  470. if ( res->values[indx].valtype == SQL_LONGVARCHAR ) {
  471. RETURN_STRING(res->values[indx].value,TRUE);
  472. } else {
  473. RETURN_LONG((long)res->values[indx].value);
  474. }
  475. default:
  476. if ( res->values[indx].value != NULL ) {
  477. RETURN_STRING(res->values[indx].value,TRUE);
  478. }
  479. }
  480. }
  481. /* }}} */
  482. /* {{{ proto bool birdstep_freeresult(int index)
  483. */
  484. PHP_FUNCTION(birdstep_freeresult)
  485. {
  486. long ind;
  487. Vresult *res;
  488. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ind) == FAILURE) {
  489. return;
  490. }
  491. PHP_GET_BIRDSTEP_RES_IDX(ind);
  492. SQLFreeStmt(res->hstmt,SQL_DROP);
  493. birdstep_del_result(list, ind);
  494. RETURN_TRUE;
  495. }
  496. /* }}} */
  497. /* {{{ proto bool birdstep_autocommit(int index)
  498. */
  499. PHP_FUNCTION(birdstep_autocommit)
  500. {
  501. long id;
  502. RETCODE stat;
  503. VConn *conn;
  504. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
  505. return;
  506. }
  507. PHP_BIRDSTEP_CHK_LNK(id);
  508. stat = SQLSetConnectOption(conn->hdbc,SQL_AUTOCOMMIT,SQL_AUTOCOMMIT_ON);
  509. if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
  510. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Set autocommit_on option failure");
  511. RETURN_FALSE;
  512. }
  513. RETURN_TRUE;
  514. }
  515. /* }}} */
  516. /* {{{ proto bool birdstep_off_autocommit(int index)
  517. */
  518. PHP_FUNCTION(birdstep_off_autocommit)
  519. {
  520. long id;
  521. RETCODE stat;
  522. VConn *conn;
  523. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
  524. return;
  525. }
  526. PHP_BIRDSTEP_CHK_LNK(id);
  527. stat = SQLSetConnectOption(conn->hdbc,SQL_AUTOCOMMIT,SQL_AUTOCOMMIT_OFF);
  528. if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
  529. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Set autocommit_off option failure");
  530. RETURN_FALSE;
  531. }
  532. RETURN_TRUE;
  533. }
  534. /* }}} */
  535. /* {{{ proto bool birdstep_commit(int index)
  536. */
  537. PHP_FUNCTION(birdstep_commit)
  538. {
  539. long id;
  540. RETCODE stat;
  541. VConn *conn;
  542. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
  543. return;
  544. }
  545. PHP_BIRDSTEP_CHK_LNK(id)
  546. stat = SQLTransact(NULL,conn->hdbc,SQL_COMMIT);
  547. if ( stat != SQL_SUCCESS ) {
  548. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Commit failure");
  549. RETURN_FALSE;
  550. }
  551. RETURN_TRUE;
  552. }
  553. /* }}} */
  554. /* {{{ proto bool birdstep_rollback(int index)
  555. */
  556. PHP_FUNCTION(birdstep_rollback)
  557. {
  558. long id;
  559. RETCODE stat;
  560. VConn *conn;
  561. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
  562. return;
  563. }
  564. PHP_BIRDSTEP_CHK_LNK(id);
  565. stat = SQLTransact(NULL,conn->hdbc,SQL_ROLLBACK);
  566. if ( stat != SQL_SUCCESS ) {
  567. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Rollback failure");
  568. RETURN_FALSE;
  569. }
  570. RETURN_TRUE;
  571. }
  572. /* }}} */
  573. /* {{{ proto string birdstep_fieldname(int index, int col)
  574. */
  575. PHP_FUNCTION(birdstep_fieldname)
  576. {
  577. long ind, col;
  578. Vresult *res;
  579. SWORD indx;
  580. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &ind, &col) == FAILURE) {
  581. return;
  582. }
  583. PHP_GET_BIRDSTEP_RES_IDX(ind);
  584. indx = col;
  585. if ( indx < 0 || indx >= res->numcols ) {
  586. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Field index not in range");
  587. RETURN_FALSE;
  588. }
  589. RETURN_STRING(res->values[indx].name,TRUE);
  590. }
  591. /* }}} */
  592. /* {{{ proto int birdstep_fieldnum(int index)
  593. */
  594. PHP_FUNCTION(birdstep_fieldnum)
  595. {
  596. long ind;
  597. Vresult *res;
  598. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ind) == FAILURE) {
  599. return;
  600. }
  601. PHP_GET_BIRDSTEP_RES_IDX(ind);
  602. RETURN_LONG(res->numcols);
  603. }
  604. /* }}} */
  605. #endif /* HAVE_BIRDSTEP */
  606. /*
  607. * Local variables:
  608. * tab-width: 4
  609. * c-basic-offset: 4
  610. * End:
  611. */