php-src/ext/odbc/birdstep.c

711 lines
18 KiB
C
Raw Normal View History

1999-04-19 15:04:11 +00:00
/*
+----------------------------------------------------------------------+
2014-09-19 16:33:14 +00:00
| PHP Version 7 |
1999-04-19 15:04:11 +00:00
+----------------------------------------------------------------------+
| Copyright (c) 1997-2016 The PHP Group |
1999-04-19 15:04:11 +00:00
+----------------------------------------------------------------------+
2006-01-01 12:51:34 +00:00
| This source file is subject to version 3.01 of the PHP license, |
1999-07-16 13:13:16 +00:00
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
2006-01-01 12:51:34 +00:00
| http://www.php.net/license/3_01.txt |
1999-07-16 13:13:16 +00:00
| 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. |
1999-04-19 15:04:11 +00:00
+----------------------------------------------------------------------+
| Authors: Nikolay P. Romanyuk <mag@redcom.ru> |
1999-04-19 15:04:11 +00:00
+----------------------------------------------------------------------+
*/
/* $Id$ */
/*
* TODO:
* birdstep_fetch_into(),
1999-04-19 15:04:11 +00:00
* Check all on real life apps.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
1999-04-19 15:04:11 +00:00
#include "php.h"
1999-09-05 13:01:42 +00:00
#if WIN32
# include "config.w32.h"
# include "win95nt.h"
# ifdef PHP_EXPORTS
2015-01-03 09:22:58 +00:00
# define PHPAPI __declspec(dllexport)
1999-09-05 13:01:42 +00:00
# else
2015-01-03 09:22:58 +00:00
# define PHPAPI __declspec(dllimport)
1999-09-05 13:01:42 +00:00
# endif
#else
# include <php_config.h>
1999-09-05 13:01:42 +00:00
# define PHPAPI
# define THREAD_LS
#endif
#ifdef HAVE_BIRDSTEP
#include "php_birdstep.h"
2000-04-06 21:07:44 +00:00
#include "ext/standard/info.h"
2007-08-31 07:42:05 +00:00
#include "php_ini.h"
1999-04-19 15:04:11 +00:00
2008-07-20 14:28:41 +00:00
/* {{{ 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[] = {
2008-07-20 14:28:41 +00:00
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)
2002-03-05 06:15:01 +00:00
/*
2015-01-03 09:22:58 +00:00
* 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
2002-03-05 06:15:01 +00:00
* deprecated.
*/
2008-07-20 14:28:41 +00:00
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)
2002-03-05 06:15:01 +00:00
/* End temporary aliases */
1999-04-19 15:04:11 +00:00
{NULL, NULL, NULL}
};
zend_module_entry birdstep_module_entry = {
STANDARD_MODULE_HEADER,
2002-04-08 22:54:06 +00:00
"birdstep",
birdstep_functions,
PHP_MINIT(birdstep),
PHP_MSHUTDOWN(birdstep),
PHP_RINIT(birdstep),
NULL,
PHP_MINFO(birdstep),
2015-03-23 19:54:55 +00:00
PHP_BIRDSTEP_VERSION,
2002-04-08 22:54:06 +00:00
STANDARD_MODULE_PROPERTIES
1999-04-19 15:04:11 +00:00
};
2000-05-23 09:33:51 +00:00
#ifdef COMPILE_DL_ODBC
ZEND_GET_MODULE(birdstep)
1999-04-19 15:04:11 +00:00
#endif
THREAD_LS birdstep_module php_birdstep_module;
1999-04-19 15:04:11 +00:00
THREAD_LS static HENV henv;
2015-01-03 09:22:58 +00:00
#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; }
2014-12-13 22:06:14 +00:00
#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; }
2015-01-03 09:22:58 +00:00
2014-12-13 22:06:14 +00:00
static void _close_birdstep_link(zend_rsrc_list_entry *rsrc)
1999-04-19 15:04:11 +00:00
{
VConn *conn = (VConn *)rsrc->ptr;
2001-07-31 05:44:11 +00:00
1999-04-19 15:04:11 +00:00
if ( conn ) {
efree(conn);
}
}
2014-12-13 22:06:14 +00:00
static void _free_birdstep_result(zend_rsrc_list_entry *rsrc)
1999-04-19 15:04:11 +00:00
{
Vresult *res = (Vresult *)rsrc->ptr;
2001-07-31 05:44:11 +00:00
1999-04-19 15:04:11 +00:00
if ( res && res->values ) {
register int i;
for ( i=0; i < res->numcols; i++ ) {
if ( res->values[i].value )
2002-04-08 22:54:06 +00:00
efree(res->values[i].value);
1999-04-19 15:04:11 +00:00
}
efree(res->values);
}
if ( res ) {
efree(res);
}
}
PHP_MINIT_FUNCTION(birdstep)
1999-04-19 15:04:11 +00:00
{
SQLAllocEnv(&henv);
2014-08-25 17:24:55 +00:00
if ( cfg_get_long("birdstep.max_links",&php_birdstep_module.max_links) == FAILURE ) {
php_birdstep_module.max_links = -1;
1999-04-19 15:04:11 +00:00
}
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);
1999-04-19 15:04:11 +00:00
return SUCCESS;
}
PHP_RINIT_FUNCTION(birdstep)
1999-04-19 15:04:11 +00:00
{
return SUCCESS;
}
PHP_MINFO_FUNCTION(birdstep)
1999-04-19 15:04:11 +00:00
{
2000-04-06 21:07:44 +00:00
php_info_print_table_start();
php_info_print_table_row(2, "RAIMA Birdstep Support", "enabled" );
2000-04-06 21:07:44 +00:00
php_info_print_table_end();
1999-04-19 15:04:11 +00:00
}
PHP_MSHUTDOWN_FUNCTION(birdstep)
1999-04-19 15:04:11 +00:00
{
SQLFreeEnv(henv);
return SUCCESS;
}
/* Some internal functions. Connections and result manupulate */
2014-12-13 22:06:14 +00:00
static int birdstep_add_conn(HashTable *list,VConn *conn,HDBC hdbc)
1999-04-19 15:04:11 +00:00
{
int ind;
2014-12-13 22:06:14 +00:00
ind = zend_list_insert(conn,php_birdstep_module.le_link);
1999-04-19 15:04:11 +00:00
conn->hdbc = hdbc;
conn->index = ind;
return(ind);
}
2002-04-08 22:54:06 +00:00
static VConn * birdstep_find_conn(HashTable *list,int ind)
1999-04-19 15:04:11 +00:00
{
VConn *conn;
int type;
1999-12-17 19:51:39 +00:00
conn = zend_list_find(ind,&type);
if ( !conn || type != php_birdstep_module.le_link ) {
1999-04-19 15:04:11 +00:00
return(NULL);
}
return(conn);
}
2002-04-08 22:54:06 +00:00
static void birdstep_del_conn(HashTable *list,int ind)
1999-04-19 15:04:11 +00:00
{
1999-12-17 19:51:39 +00:00
zend_list_delete(ind);
1999-04-19 15:04:11 +00:00
}
2002-04-08 22:54:06 +00:00
static int birdstep_add_result(HashTable *list,Vresult *res,VConn *conn)
1999-04-19 15:04:11 +00:00
{
int ind;
ind = zend_list_insert(res,php_birdstep_module.le_result);
1999-04-19 15:04:11 +00:00
res->conn = conn;
res->index = ind;
return(ind);
}
2002-04-08 22:54:06 +00:00
static Vresult * birdstep_find_result(HashTable *list,int ind)
1999-04-19 15:04:11 +00:00
{
Vresult *res;
int type;
1999-12-17 19:51:39 +00:00
res = zend_list_find(ind,&type);
if ( !res || type != php_birdstep_module.le_result ) {
1999-04-19 15:04:11 +00:00
return(NULL);
}
return(res);
}
2002-04-08 22:54:06 +00:00
static void birdstep_del_result(HashTable *list,int ind)
1999-04-19 15:04:11 +00:00
{
1999-12-17 19:51:39 +00:00
zend_list_delete(ind);
1999-04-19 15:04:11 +00:00
}
/* Users functions */
/* {{{ proto int birdstep_connect(string server, string user, string pass)
2001-12-07 07:21:05 +00:00
*/
PHP_FUNCTION(birdstep_connect)
1999-04-19 15:04:11 +00:00
{
2008-06-25 16:18:55 +00:00
char *serv, *user, *pass;
size_t serv_len, user_len, pass_len;
1999-04-19 15:04:11 +00:00
RETCODE stat;
HDBC hdbc;
VConn *new;
2014-08-25 17:24:55 +00:00
zend_long ind;
1999-04-19 15:04:11 +00:00
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss", &serv, &serv_len, &user, &user_len, &pass, &pass_len) == FAILURE) {
2008-06-25 16:18:55 +00:00
return;
}
2015-01-03 09:22:58 +00:00
if ( php_birdstep_module.max_links != -1 && php_birdstep_module.num_links == php_birdstep_module.max_links ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: Too many open connections (%d)",php_birdstep_module.num_links);
1999-04-19 15:04:11 +00:00
RETURN_FALSE;
}
2008-06-25 16:18:55 +00:00
1999-04-19 15:04:11 +00:00
stat = SQLAllocConnect(henv,&hdbc);
if ( stat != SQL_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: Could not allocate connection handle");
1999-04-19 15:04:11 +00:00
RETURN_FALSE;
}
2008-06-25 16:18:55 +00:00
stat = SQLConnect(hdbc, serv, SQL_NTS, user, SQL_NTS, pass, SQL_NTS);
1999-04-19 15:04:11 +00:00
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: Could not connect to server \"%s\" for %s", serv, user);
1999-04-19 15:04:11 +00:00
SQLFreeConnect(hdbc);
RETURN_FALSE;
}
new = (VConn *)emalloc(sizeof(VConn));
2014-12-13 22:06:14 +00:00
ind = birdstep_add_conn(list,new,hdbc);
php_birdstep_module.num_links++;
2014-08-25 17:24:55 +00:00
RETURN_LONG(ind);
1999-04-19 15:04:11 +00:00
}
2001-12-07 07:21:05 +00:00
/* }}} */
1999-04-19 15:04:11 +00:00
/* {{{ proto bool birdstep_close(int id)
2001-12-07 07:21:05 +00:00
*/
PHP_FUNCTION(birdstep_close)
1999-04-19 15:04:11 +00:00
{
2014-08-25 17:24:55 +00:00
zend_long id;
1999-04-19 15:04:11 +00:00
VConn *conn;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &id) == FAILURE) {
2008-06-25 16:18:55 +00:00
return;
1999-04-19 15:04:11 +00:00
}
2008-06-25 16:18:55 +00:00
PHP_BIRDSTEP_CHK_LNK(id);
1999-04-19 15:04:11 +00:00
SQLDisconnect(conn->hdbc);
SQLFreeConnect(conn->hdbc);
2008-06-25 16:18:55 +00:00
birdstep_del_conn(list, id);
php_birdstep_module.num_links--;
1999-04-19 15:04:11 +00:00
RETURN_TRUE;
}
2001-12-07 07:21:05 +00:00
/* }}} */
1999-04-19 15:04:11 +00:00
/* {{{ proto int birdstep_exec(int index, string exec_str)
2001-12-07 07:21:05 +00:00
*/
PHP_FUNCTION(birdstep_exec)
1999-04-19 15:04:11 +00:00
{
2008-06-25 16:18:55 +00:00
char *query;
2014-08-25 17:24:55 +00:00
zend_long ind;
size_t query_len, indx;
1999-04-19 15:04:11 +00:00
VConn *conn;
Vresult *res;
RETCODE stat;
SWORD cols,i,colnamelen;
SDWORD rows,coldesc;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &ind, &query, &query_len) == FAILURE) {
2008-06-25 16:18:55 +00:00
return;
1999-04-19 15:04:11 +00:00
}
2008-06-25 16:18:55 +00:00
PHP_BIRDSTEP_CHK_LNK(ind);
1999-04-19 15:04:11 +00:00
res = (Vresult *)emalloc(sizeof(Vresult));
stat = SQLAllocStmt(conn->hdbc,&res->hstmt);
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: SQLAllocStmt return %d",stat);
1999-04-19 15:04:11 +00:00
efree(res);
RETURN_FALSE;
}
stat = SQLExecDirect(res->hstmt,query,SQL_NTS);
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: Cannot execute \"%s\" query",query);
1999-04-19 15:04:11 +00:00
SQLFreeStmt(res->hstmt,SQL_DROP);
efree(res);
RETURN_FALSE;
}
/* Success query */
stat = SQLNumResultCols(res->hstmt,&cols);
if ( stat != SQL_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: SQLNumResultCols return %d",stat);
1999-04-19 15:04:11 +00:00
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 ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: SQLNumResultCols return %d",stat);
1999-04-19 15:04:11 +00:00
SQLFreeStmt(res->hstmt,SQL_DROP);
efree(res);
RETURN_FALSE;
}
SQLFreeStmt(res->hstmt,SQL_DROP);
efree(res);
2014-08-25 17:24:55 +00:00
RETURN_LONG(rows);
1999-04-19 15:04:11 +00:00
} else { /* Was SELECT query */
2003-08-18 04:41:48 +00:00
res->values = (VResVal *)safe_emalloc(sizeof(VResVal), cols, 0);
1999-04-19 15:04:11 +00:00
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);
1999-04-19 15:04:11 +00:00
}
}
res->fetched = 0;
indx = birdstep_add_result(list,res,conn);
2014-08-25 17:24:55 +00:00
RETURN_LONG(indx);
1999-04-19 15:04:11 +00:00
}
2001-12-07 07:21:05 +00:00
/* }}} */
1999-04-19 15:04:11 +00:00
/* {{{ proto bool birdstep_fetch(int index)
2001-12-07 07:21:05 +00:00
*/
PHP_FUNCTION(birdstep_fetch)
1999-04-19 15:04:11 +00:00
{
2014-08-25 17:24:55 +00:00
zend_long ind;
1999-04-19 15:04:11 +00:00
Vresult *res;
RETCODE stat;
UDWORD row;
UWORD RowStat[1];
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &ind) == FAILURE) {
2008-06-25 16:18:55 +00:00
return;
1999-04-19 15:04:11 +00:00
}
2008-06-25 16:18:55 +00:00
PHP_GET_BIRDSTEP_RES_IDX(ind);
1999-04-19 15:04:11 +00:00
stat = SQLExtendedFetch(res->hstmt,SQL_FETCH_NEXT,1,&row,RowStat);
if ( stat == SQL_NO_DATA_FOUND ) {
SQLFreeStmt(res->hstmt,SQL_DROP);
2014-08-25 17:24:55 +00:00
birdstep_del_result(list,Z_LVAL_PP(ind));
1999-04-19 15:04:11 +00:00
RETURN_FALSE;
}
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: SQLFetch return error");
1999-04-19 15:04:11 +00:00
SQLFreeStmt(res->hstmt,SQL_DROP);
2014-08-25 17:24:55 +00:00
birdstep_del_result(list,Z_LVAL_PP(ind));
1999-04-19 15:04:11 +00:00
RETURN_FALSE;
}
res->fetched = 1;
RETURN_TRUE;
}
2001-12-07 07:21:05 +00:00
/* }}} */
1999-04-19 15:04:11 +00:00
2008-06-25 16:18:55 +00:00
/* {{{ proto mixed birdstep_result(int index, mixed col)
2001-12-07 07:21:05 +00:00
*/
PHP_FUNCTION(birdstep_result)
1999-04-19 15:04:11 +00:00
{
2008-06-25 16:18:55 +00:00
zval **col;
2014-08-25 17:24:55 +00:00
zend_long ind;
1999-04-19 15:04:11 +00:00
Vresult *res;
RETCODE stat;
int i,sql_c_type;
UDWORD row;
UWORD RowStat[1];
SWORD indx = -1;
char *field = NULL;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lZ", &ind, &col) == FAILURE) {
2008-06-25 16:18:55 +00:00
return;
1999-04-19 15:04:11 +00:00
}
2008-06-25 16:18:55 +00:00
PHP_GET_BIRDSTEP_RES_IDX(ind);
if ( Z_TYPE_PP(col) == IS_STRING ) {
field = Z_STRVAL_PP(col);
1999-04-19 15:04:11 +00:00
} else {
2014-08-25 19:51:49 +00:00
convert_to_long_ex(col);
2014-08-25 17:24:55 +00:00
indx = Z_LVAL_PP(col);
1999-04-19 15:04:11 +00:00
}
if ( field ) {
for ( i = 0; i < res->numcols; i++ ) {
if ( !strcasecmp(res->values[i].name,field)) {
indx = i;
break;
}
}
if ( indx < 0 ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Field %s not found",field);
1999-04-19 15:04:11 +00:00
RETURN_FALSE;
}
} else {
if ( indx < 0 || indx >= res->numcols ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: Field index not in range");
1999-04-19 15:04:11 +00:00
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);
2014-08-25 17:24:55 +00:00
birdstep_del_result(list,Z_LVAL_PP(ind));
1999-04-19 15:04:11 +00:00
RETURN_FALSE;
}
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: SQLFetch return error");
1999-04-19 15:04:11 +00:00
SQLFreeStmt(res->hstmt,SQL_DROP);
2014-08-25 17:24:55 +00:00
birdstep_del_result(list,Z_LVAL_PP(ind));
1999-04-19 15:04:11 +00:00
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);
2014-08-25 17:24:55 +00:00
birdstep_del_result(list,Z_LVAL_PP(ind));
1999-04-19 15:04:11 +00:00
RETURN_FALSE;
}
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: SQLGetData return error");
1999-04-19 15:04:11 +00:00
SQLFreeStmt(res->hstmt,SQL_DROP);
2014-08-25 17:24:55 +00:00
birdstep_del_result(list,Z_LVAL_PP(ind));
1999-04-19 15:04:11 +00:00
RETURN_FALSE;
}
if ( res->values[indx].valtype == SQL_LONGVARCHAR ) {
RETURN_STRING(res->values[indx].value,TRUE);
} else {
2014-08-26 09:23:25 +00:00
RETURN_LONG((zend_long)res->values[indx].value);
1999-04-19 15:04:11 +00:00
}
default:
if ( res->values[indx].value != NULL ) {
RETURN_STRING(res->values[indx].value,TRUE);
}
}
}
2001-12-07 07:21:05 +00:00
/* }}} */
1999-04-19 15:04:11 +00:00
/* {{{ proto bool birdstep_freeresult(int index)
2001-12-07 07:21:05 +00:00
*/
PHP_FUNCTION(birdstep_freeresult)
1999-04-19 15:04:11 +00:00
{
2014-08-25 17:24:55 +00:00
zend_long ind;
1999-04-19 15:04:11 +00:00
Vresult *res;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &ind) == FAILURE) {
2008-06-25 16:18:55 +00:00
return;
1999-04-19 15:04:11 +00:00
}
2008-06-25 16:18:55 +00:00
PHP_GET_BIRDSTEP_RES_IDX(ind);
1999-04-19 15:04:11 +00:00
SQLFreeStmt(res->hstmt,SQL_DROP);
2008-06-25 16:18:55 +00:00
birdstep_del_result(list, ind);
1999-04-19 15:04:11 +00:00
RETURN_TRUE;
}
2001-12-07 07:21:05 +00:00
/* }}} */
1999-04-19 15:04:11 +00:00
/* {{{ proto bool birdstep_autocommit(int index)
2001-12-07 07:21:05 +00:00
*/
PHP_FUNCTION(birdstep_autocommit)
1999-04-19 15:04:11 +00:00
{
2014-08-25 17:24:55 +00:00
zend_long id;
1999-04-19 15:04:11 +00:00
RETCODE stat;
VConn *conn;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &id) == FAILURE) {
2008-06-25 16:18:55 +00:00
return;
1999-04-19 15:04:11 +00:00
}
2008-06-25 16:18:55 +00:00
PHP_BIRDSTEP_CHK_LNK(id);
1999-04-19 15:04:11 +00:00
stat = SQLSetConnectOption(conn->hdbc,SQL_AUTOCOMMIT,SQL_AUTOCOMMIT_ON);
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: Set autocommit_on option failure");
1999-04-19 15:04:11 +00:00
RETURN_FALSE;
}
RETURN_TRUE;
}
2001-12-07 07:21:05 +00:00
/* }}} */
1999-04-19 15:04:11 +00:00
/* {{{ proto bool birdstep_off_autocommit(int index)
2001-12-07 07:21:05 +00:00
*/
PHP_FUNCTION(birdstep_off_autocommit)
1999-04-19 15:04:11 +00:00
{
2014-08-25 17:24:55 +00:00
zend_long id;
1999-04-19 15:04:11 +00:00
RETCODE stat;
VConn *conn;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &id) == FAILURE) {
2008-06-25 16:18:55 +00:00
return;
1999-04-19 15:04:11 +00:00
}
2008-06-25 16:18:55 +00:00
PHP_BIRDSTEP_CHK_LNK(id);
1999-04-19 15:04:11 +00:00
stat = SQLSetConnectOption(conn->hdbc,SQL_AUTOCOMMIT,SQL_AUTOCOMMIT_OFF);
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: Set autocommit_off option failure");
1999-04-19 15:04:11 +00:00
RETURN_FALSE;
}
RETURN_TRUE;
}
2001-12-07 07:21:05 +00:00
/* }}} */
1999-04-19 15:04:11 +00:00
/* {{{ proto bool birdstep_commit(int index)
2001-12-07 07:21:05 +00:00
*/
PHP_FUNCTION(birdstep_commit)
1999-04-19 15:04:11 +00:00
{
zend_long id;
1999-04-19 15:04:11 +00:00
RETCODE stat;
VConn *conn;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &id) == FAILURE) {
2008-06-25 16:18:55 +00:00
return;
1999-04-19 15:04:11 +00:00
}
2008-06-25 16:18:55 +00:00
PHP_BIRDSTEP_CHK_LNK(id)
1999-04-19 15:04:11 +00:00
stat = SQLTransact(NULL,conn->hdbc,SQL_COMMIT);
if ( stat != SQL_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: Commit failure");
1999-04-19 15:04:11 +00:00
RETURN_FALSE;
}
RETURN_TRUE;
}
2001-12-07 07:21:05 +00:00
/* }}} */
1999-04-19 15:04:11 +00:00
/* {{{ proto bool birdstep_rollback(int index)
2001-12-07 07:21:05 +00:00
*/
PHP_FUNCTION(birdstep_rollback)
1999-04-19 15:04:11 +00:00
{
2014-08-25 17:24:55 +00:00
zend_long id;
1999-04-19 15:04:11 +00:00
RETCODE stat;
VConn *conn;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &id) == FAILURE) {
2008-06-25 16:18:55 +00:00
return;
1999-04-19 15:04:11 +00:00
}
2008-06-25 16:18:55 +00:00
PHP_BIRDSTEP_CHK_LNK(id);
1999-04-19 15:04:11 +00:00
stat = SQLTransact(NULL,conn->hdbc,SQL_ROLLBACK);
if ( stat != SQL_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: Rollback failure");
1999-04-19 15:04:11 +00:00
RETURN_FALSE;
}
RETURN_TRUE;
}
2001-12-07 07:21:05 +00:00
/* }}} */
1999-04-19 15:04:11 +00:00
/* {{{ proto string birdstep_fieldname(int index, int col)
2001-12-07 07:21:05 +00:00
*/
PHP_FUNCTION(birdstep_fieldname)
1999-04-19 15:04:11 +00:00
{
2014-08-25 17:24:55 +00:00
zend_long ind, col;
1999-04-19 15:04:11 +00:00
Vresult *res;
SWORD indx;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &ind, &col) == FAILURE) {
2008-06-25 16:18:55 +00:00
return;
1999-04-19 15:04:11 +00:00
}
2008-06-25 16:18:55 +00:00
PHP_GET_BIRDSTEP_RES_IDX(ind);
2008-06-25 16:18:55 +00:00
indx = col;
1999-04-19 15:04:11 +00:00
if ( indx < 0 || indx >= res->numcols ) {
2014-12-13 22:06:14 +00:00
php_error_docref(NULL, E_WARNING, "Birdstep: Field index not in range");
1999-04-19 15:04:11 +00:00
RETURN_FALSE;
}
RETURN_STRING(res->values[indx].name,TRUE);
}
2001-12-07 07:21:05 +00:00
/* }}} */
1999-04-19 15:04:11 +00:00
/* {{{ proto int birdstep_fieldnum(int index)
2001-12-07 07:21:05 +00:00
*/
PHP_FUNCTION(birdstep_fieldnum)
1999-04-19 15:04:11 +00:00
{
2014-08-25 17:24:55 +00:00
zend_long ind;
1999-04-19 15:04:11 +00:00
Vresult *res;
2014-12-13 22:06:14 +00:00
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &ind) == FAILURE) {
2008-06-25 16:18:55 +00:00
return;
1999-04-19 15:04:11 +00:00
}
2008-06-25 16:18:55 +00:00
PHP_GET_BIRDSTEP_RES_IDX(ind);
2014-08-25 17:24:55 +00:00
RETURN_LONG(res->numcols);
1999-04-19 15:04:11 +00:00
}
2001-12-07 07:21:05 +00:00
/* }}} */
1999-04-19 15:04:11 +00:00
#endif /* HAVE_BIRDSTEP */
1999-04-19 15:04:11 +00:00
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/