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