1999-04-19 23:04:11 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
| PHP version 4.0 |
|
1999-04-19 23:04:11 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-01-01 09:32:05 +08:00
|
|
|
| Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
|
1999-04-19 23:04:11 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-02-20 07:41:32 +08:00
|
|
|
| This source file is subject to version 2.01 of the PHP license, |
|
1999-07-16 21:13:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-02-20 07:41:32 +08:00
|
|
|
| http://www.php.net/license/2_01.txt. |
|
1999-07-16 21:13:16 +08: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 23:04:11 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Nikolay P. Romanyuk <mag@redcom.ru> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
* velocis_fetch_into(),
|
|
|
|
* Check all on real life apps.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
|
1999-09-05 21:01:42 +08:00
|
|
|
#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
|
|
|
|
|
1999-11-09 22:28:59 +08:00
|
|
|
#ifdef HAVE_VELOCIS
|
1999-12-05 03:19:57 +08:00
|
|
|
#include "php_velocis.h"
|
2000-04-07 05:07:44 +08:00
|
|
|
#include "ext/standard/info.h"
|
1999-04-19 23:04:11 +08:00
|
|
|
|
|
|
|
function_entry velocis_functions[] = {
|
1999-08-03 00:06:13 +08:00
|
|
|
PHP_FE(velocis_connect, NULL)
|
|
|
|
PHP_FE(velocis_close, NULL)
|
|
|
|
PHP_FE(velocis_exec, NULL)
|
|
|
|
PHP_FE(velocis_fetch, NULL)
|
|
|
|
PHP_FE(velocis_result, NULL)
|
|
|
|
PHP_FE(velocis_freeresult, NULL)
|
|
|
|
PHP_FE(velocis_autocommit, NULL)
|
|
|
|
PHP_FE(velocis_off_autocommit, NULL)
|
|
|
|
PHP_FE(velocis_commit, NULL)
|
|
|
|
PHP_FE(velocis_rollback, NULL)
|
|
|
|
PHP_FE(velocis_fieldnum, NULL)
|
|
|
|
PHP_FE(velocis_fieldname, NULL)
|
1999-04-19 23:04:11 +08:00
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
1999-12-18 04:55:31 +08:00
|
|
|
zend_module_entry velocis_module_entry = {
|
2000-03-07 02:44:01 +08:00
|
|
|
"velocis", velocis_functions, PHP_MINIT(velocis), PHP_MSHUTDOWN(velocis),
|
1999-08-03 00:06:13 +08:00
|
|
|
PHP_RINIT(velocis), NULL, PHP_MINFO(velocis), STANDARD_MODULE_PROPERTIES
|
1999-04-19 23:04:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-05-02 08:44:35 +08:00
|
|
|
#if defined(COMPILE_DL) || defined(COMPILE_DL_ODBC)
|
2000-05-02 08:30:36 +08:00
|
|
|
ZEND_GET_MODULE(velocis)
|
1999-04-19 23:04:11 +08:00
|
|
|
#endif
|
|
|
|
|
1999-12-18 06:34:04 +08:00
|
|
|
THREAD_LS velocis_module php_velocis_module;
|
1999-04-19 23:04:11 +08:00
|
|
|
THREAD_LS static HENV henv;
|
|
|
|
|
|
|
|
static void _close_velocis_link(VConn *conn)
|
|
|
|
{
|
|
|
|
if ( conn ) {
|
|
|
|
efree(conn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _free_velocis_result(Vresult *res)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-03 00:06:13 +08:00
|
|
|
PHP_MINIT_FUNCTION(velocis)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
SQLAllocEnv(&henv);
|
1999-12-18 06:34:04 +08:00
|
|
|
if ( cfg_get_long("velocis.max_links",&php_velocis_module.max_links) == FAILURE ) {
|
|
|
|
php_velocis_module.max_links = -1;
|
1999-04-19 23:04:11 +08:00
|
|
|
}
|
1999-12-18 06:34:04 +08:00
|
|
|
php_velocis_module.num_links = 0;
|
|
|
|
php_velocis_module.le_link = register_list_destructors(_close_velocis_link,NULL);
|
|
|
|
php_velocis_module.le_result = register_list_destructors(_free_velocis_result,NULL);
|
1999-04-19 23:04:11 +08:00
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-08-03 00:06:13 +08:00
|
|
|
PHP_RINIT_FUNCTION(velocis)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-03 00:06:13 +08:00
|
|
|
PHP_MINFO_FUNCTION(velocis)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
2000-04-07 05:07:44 +08:00
|
|
|
php_info_print_table_start();
|
|
|
|
php_info_print_table_row(2, "RAIMA Velocis Support", "enabled" );
|
|
|
|
php_info_print_table_end();
|
1999-04-19 23:04:11 +08:00
|
|
|
}
|
|
|
|
|
1999-08-03 00:06:13 +08:00
|
|
|
PHP_MSHUTDOWN_FUNCTION(velocis)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
SQLFreeEnv(henv);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Some internal functions. Connections and result manupulate */
|
|
|
|
|
|
|
|
static int
|
|
|
|
velocis_add_conn(HashTable *list,VConn *conn,HDBC hdbc)
|
|
|
|
{
|
|
|
|
int ind;
|
|
|
|
|
1999-12-18 06:34:04 +08:00
|
|
|
ind = zend_list_insert(conn,php_velocis_module.le_link);
|
1999-04-19 23:04:11 +08:00
|
|
|
conn->hdbc = hdbc;
|
|
|
|
conn->index = ind;
|
|
|
|
|
|
|
|
return(ind);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VConn *
|
|
|
|
velocis_find_conn(HashTable *list,int ind)
|
|
|
|
{
|
|
|
|
VConn *conn;
|
|
|
|
int type;
|
|
|
|
|
1999-12-18 03:51:39 +08:00
|
|
|
conn = zend_list_find(ind,&type);
|
1999-12-18 06:34:04 +08:00
|
|
|
if ( !conn || type != php_velocis_module.le_link ) {
|
1999-04-19 23:04:11 +08:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
return(conn);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
velocis_del_conn(HashTable *list,int ind)
|
|
|
|
{
|
1999-12-18 03:51:39 +08:00
|
|
|
zend_list_delete(ind);
|
1999-04-19 23:04:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
velocis_add_result(HashTable *list,Vresult *res,VConn *conn)
|
|
|
|
{
|
|
|
|
int ind;
|
|
|
|
|
1999-12-18 06:34:04 +08:00
|
|
|
ind = zend_list_insert(res,php_velocis_module.le_result);
|
1999-04-19 23:04:11 +08:00
|
|
|
res->conn = conn;
|
|
|
|
res->index = ind;
|
|
|
|
|
|
|
|
return(ind);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Vresult *
|
|
|
|
velocis_find_result(HashTable *list,int ind)
|
|
|
|
{
|
|
|
|
Vresult *res;
|
|
|
|
int type;
|
|
|
|
|
1999-12-18 03:51:39 +08:00
|
|
|
res = zend_list_find(ind,&type);
|
1999-12-18 06:34:04 +08:00
|
|
|
if ( !res || type != php_velocis_module.le_result ) {
|
1999-04-19 23:04:11 +08:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
return(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
velocis_del_result(HashTable *list,int ind)
|
|
|
|
{
|
1999-12-18 03:51:39 +08:00
|
|
|
zend_list_delete(ind);
|
1999-04-19 23:04:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Users functions */
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
PHP_FUNCTION(velocis_connect)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
pval *serv,*user,*pass;
|
|
|
|
char *Serv = NULL;
|
|
|
|
char *User = NULL;
|
|
|
|
char *Pass = NULL;
|
|
|
|
RETCODE stat;
|
|
|
|
HDBC hdbc;
|
|
|
|
VConn *new;
|
|
|
|
long ind;
|
|
|
|
|
1999-12-18 06:34:04 +08:00
|
|
|
if ( php_velocis_module.max_links != -1 && php_velocis_module.num_links == php_velocis_module.max_links ) {
|
|
|
|
php_error(E_WARNING,"Velocis: Too many open connections (%d)",php_velocis_module.num_links);
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
if ( ARG_COUNT(ht) != 3 ||
|
|
|
|
getParameters(ht,3,&serv,&user,&pass) == FAILURE ) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_string(serv);
|
|
|
|
convert_to_string(user);
|
|
|
|
convert_to_string(pass);
|
|
|
|
Serv = serv->value.str.val;
|
|
|
|
User = user->value.str.val;
|
|
|
|
Pass = pass->value.str.val;
|
|
|
|
stat = SQLAllocConnect(henv,&hdbc);
|
|
|
|
if ( stat != SQL_SUCCESS ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Could not allocate connection handle");
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
stat = SQLConnect(hdbc,Serv,SQL_NTS,User,SQL_NTS,Pass,SQL_NTS);
|
|
|
|
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Could not connect to server \"%s\" for %s",Serv,User);
|
1999-04-19 23:04:11 +08:00
|
|
|
SQLFreeConnect(hdbc);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
new = (VConn *)emalloc(sizeof(VConn));
|
|
|
|
if ( new == NULL ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Out of memory for store connection");
|
1999-04-19 23:04:11 +08:00
|
|
|
SQLFreeConnect(hdbc);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
ind = velocis_add_conn(list,new,hdbc);
|
1999-12-18 06:34:04 +08:00
|
|
|
php_velocis_module.num_links++;
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_LONG(ind);
|
|
|
|
}
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
PHP_FUNCTION(velocis_close)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
pval *id;
|
|
|
|
VConn *conn;
|
|
|
|
|
|
|
|
if ( ARG_COUNT(ht) != 1 || getParameters(ht,1,&id) == FAILURE ) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_long(id);
|
|
|
|
conn = velocis_find_conn(list,id->value.lval);
|
|
|
|
if ( !conn ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Not connection index (%d)",id->value.lval);
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
SQLDisconnect(conn->hdbc);
|
|
|
|
SQLFreeConnect(conn->hdbc);
|
|
|
|
velocis_del_conn(list,id->value.lval);
|
1999-12-18 06:34:04 +08:00
|
|
|
php_velocis_module.num_links--;
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
PHP_FUNCTION(velocis_exec)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
pval *ind,*exec_str;
|
|
|
|
char *query = NULL;
|
|
|
|
int indx;
|
|
|
|
VConn *conn;
|
|
|
|
Vresult *res;
|
|
|
|
RETCODE stat;
|
|
|
|
SWORD cols,i,colnamelen;
|
|
|
|
SDWORD rows,coldesc;
|
|
|
|
|
|
|
|
if ( ARG_COUNT(ht) != 2 || getParameters(ht,2,&ind,&exec_str) == FAILURE ) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_long(ind);
|
|
|
|
conn = velocis_find_conn(list,ind->value.lval);
|
|
|
|
if ( !conn ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Not connection index (%d)",ind->value.lval);
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
convert_to_string(exec_str);
|
|
|
|
query = exec_str->value.str.val;
|
|
|
|
|
|
|
|
res = (Vresult *)emalloc(sizeof(Vresult));
|
|
|
|
if ( res == NULL ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Out of memory for result");
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
stat = SQLAllocStmt(conn->hdbc,&res->hstmt);
|
|
|
|
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: SQLAllocStmt return %d",stat);
|
1999-04-19 23:04:11 +08:00
|
|
|
efree(res);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
stat = SQLExecDirect(res->hstmt,query,SQL_NTS);
|
|
|
|
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Can not execute \"%s\" query",query);
|
1999-04-19 23:04:11 +08:00
|
|
|
SQLFreeStmt(res->hstmt,SQL_DROP);
|
|
|
|
efree(res);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
/* Success query */
|
|
|
|
stat = SQLNumResultCols(res->hstmt,&cols);
|
|
|
|
if ( stat != SQL_SUCCESS ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: SQLNumResultCols return %d",stat);
|
1999-04-19 23:04:11 +08: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 ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: SQLNumResultCols return %d",stat);
|
1999-04-19 23:04:11 +08:00
|
|
|
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 *)emalloc(sizeof(VResVal)*cols);
|
|
|
|
if ( res->values == NULL ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Out of memory for result columns");
|
1999-04-19 23:04:11 +08:00
|
|
|
SQLFreeStmt(res->hstmt,SQL_DROP);
|
|
|
|
efree(res);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
if ( res->values[i].value != NULL ) {
|
|
|
|
SQLBindCol(res->hstmt,i+1,SQL_C_CHAR,
|
|
|
|
res->values[i].value,coldesc+1,
|
|
|
|
&res->values[i].vallen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res->fetched = 0;
|
|
|
|
indx = velocis_add_result(list,res,conn);
|
|
|
|
RETURN_LONG(indx);
|
|
|
|
}
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
PHP_FUNCTION(velocis_fetch)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
pval *ind;
|
|
|
|
Vresult *res;
|
|
|
|
RETCODE stat;
|
|
|
|
UDWORD row;
|
|
|
|
UWORD RowStat[1];
|
|
|
|
|
|
|
|
if ( ARG_COUNT(ht) != 1 || getParameters(ht,1,&ind) == FAILURE ) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_long(ind);
|
|
|
|
res = velocis_find_result(list,ind->value.lval);
|
|
|
|
if ( !res ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Not result index (%d)",ind->value.lval);
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
stat = SQLExtendedFetch(res->hstmt,SQL_FETCH_NEXT,1,&row,RowStat);
|
|
|
|
if ( stat == SQL_NO_DATA_FOUND ) {
|
|
|
|
SQLFreeStmt(res->hstmt,SQL_DROP);
|
|
|
|
velocis_del_result(list,ind->value.lval);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: SQLFetch return error");
|
1999-04-19 23:04:11 +08:00
|
|
|
SQLFreeStmt(res->hstmt,SQL_DROP);
|
|
|
|
velocis_del_result(list,ind->value.lval);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
res->fetched = 1;
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
PHP_FUNCTION(velocis_result)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
pval *ind,*col;
|
|
|
|
Vresult *res;
|
|
|
|
RETCODE stat;
|
|
|
|
int i,sql_c_type;
|
|
|
|
UDWORD row;
|
|
|
|
UWORD RowStat[1];
|
|
|
|
SWORD indx = -1;
|
|
|
|
char *field = NULL;
|
|
|
|
|
|
|
|
if ( ARG_COUNT(ht) != 2 || getParameters(ht,2,&ind,&col) == FAILURE ) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_long(ind);
|
|
|
|
res = velocis_find_result(list,ind->value.lval);
|
|
|
|
if ( !res ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Not result index (%d),ind->value.lval");
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
if ( col->type == IS_STRING ) {
|
|
|
|
field = col->value.str.val;
|
|
|
|
} else {
|
|
|
|
convert_to_long(col);
|
|
|
|
indx = col->value.lval;
|
|
|
|
}
|
|
|
|
if ( field ) {
|
|
|
|
for ( i = 0; i < res->numcols; i++ ) {
|
|
|
|
if ( !strcasecmp(res->values[i].name,field)) {
|
|
|
|
indx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( indx < 0 ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "Field %s not found",field);
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( indx < 0 || indx >= res->numcols ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Field index not in range");
|
1999-04-19 23:04:11 +08: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);
|
|
|
|
velocis_del_result(list,ind->value.lval);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: SQLFetch return error");
|
1999-04-19 23:04:11 +08:00
|
|
|
SQLFreeStmt(res->hstmt,SQL_DROP);
|
|
|
|
velocis_del_result(list,ind->value.lval);
|
|
|
|
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);
|
|
|
|
if ( !res->values[indx].value ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Out of memory");
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
velocis_del_result(list,ind->value.lval);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: SQLGetData return error");
|
1999-04-19 23:04:11 +08:00
|
|
|
SQLFreeStmt(res->hstmt,SQL_DROP);
|
|
|
|
velocis_del_result(list,ind->value.lval);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
if ( res->values[indx].valtype == SQL_LONGVARCHAR ) {
|
|
|
|
RETURN_STRING(res->values[indx].value,TRUE);
|
|
|
|
} else {
|
|
|
|
RETURN_LONG((long)res->values[indx].value);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
if ( res->values[indx].value != NULL ) {
|
|
|
|
RETURN_STRING(res->values[indx].value,TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
PHP_FUNCTION(velocis_freeresult)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
pval *ind;
|
|
|
|
Vresult *res;
|
|
|
|
|
|
|
|
if ( ARG_COUNT(ht) != 1 || getParameters(ht,1,&ind) == FAILURE ) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_long(ind);
|
|
|
|
res = velocis_find_result(list,ind->value.lval);
|
|
|
|
if ( !res ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Not result index (%d)",ind->value.lval);
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
SQLFreeStmt(res->hstmt,SQL_DROP);
|
|
|
|
velocis_del_result(list,ind->value.lval);
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
PHP_FUNCTION(velocis_autocommit)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
pval *id;
|
|
|
|
RETCODE stat;
|
|
|
|
VConn *conn;
|
|
|
|
|
|
|
|
if ( ARG_COUNT(ht) != 1 || getParameters(ht,1,&id) == FAILURE ) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_long(id);
|
|
|
|
conn = velocis_find_conn(list,id->value.lval);
|
|
|
|
if ( !conn ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Not connection index (%d)",id->value.lval);
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
stat = SQLSetConnectOption(conn->hdbc,SQL_AUTOCOMMIT,SQL_AUTOCOMMIT_ON);
|
|
|
|
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Set autocommit_on option failure");
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
PHP_FUNCTION(velocis_off_autocommit)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
pval *id;
|
|
|
|
RETCODE stat;
|
|
|
|
VConn *conn;
|
|
|
|
|
|
|
|
if ( ARG_COUNT(ht) != 1 || getParameters(ht,1,&id) == FAILURE ) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_long(id);
|
|
|
|
conn = velocis_find_conn(list,id->value.lval);
|
|
|
|
if ( !conn ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Not connection index (%d)",id->value.lval);
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
stat = SQLSetConnectOption(conn->hdbc,SQL_AUTOCOMMIT,SQL_AUTOCOMMIT_OFF);
|
|
|
|
if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Set autocommit_off option failure");
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
PHP_FUNCTION(velocis_commit)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
pval *id;
|
|
|
|
RETCODE stat;
|
|
|
|
VConn *conn;
|
|
|
|
|
|
|
|
if ( ARG_COUNT(ht) != 1 || getParameters(ht,1,&id) == FAILURE ) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_long(id);
|
|
|
|
conn = velocis_find_conn(list,id->value.lval);
|
|
|
|
if ( !conn ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Not connection index (%d)",id->value.lval);
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
stat = SQLTransact(NULL,conn->hdbc,SQL_COMMIT);
|
|
|
|
if ( stat != SQL_SUCCESS ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Commit failure");
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
PHP_FUNCTION(velocis_rollback)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
pval *id;
|
|
|
|
RETCODE stat;
|
|
|
|
VConn *conn;
|
|
|
|
|
|
|
|
if ( ARG_COUNT(ht) != 1 || getParameters(ht,1,&id) == FAILURE ) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_long(id);
|
|
|
|
conn = velocis_find_conn(list,id->value.lval);
|
|
|
|
if ( !conn ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Not connection index (%d)",id->value.lval);
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
stat = SQLTransact(NULL,conn->hdbc,SQL_ROLLBACK);
|
|
|
|
if ( stat != SQL_SUCCESS ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Rollback failure");
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
PHP_FUNCTION(velocis_fieldname)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
pval *ind,*col;
|
|
|
|
Vresult *res;
|
|
|
|
SWORD indx;
|
|
|
|
|
|
|
|
if ( ARG_COUNT(ht) != 2 || getParameters(ht,2,&ind,&col) == FAILURE ) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_long(ind);
|
|
|
|
res = velocis_find_result(list,ind->value.lval);
|
|
|
|
if ( !res ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Not result index (%d),ind->value.lval");
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
convert_to_long(col);
|
|
|
|
indx = col->value.lval;
|
|
|
|
if ( indx < 0 || indx >= res->numcols ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Field index not in range");
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_STRING(res->values[indx].name,TRUE);
|
|
|
|
}
|
|
|
|
|
1999-05-21 18:06:25 +08:00
|
|
|
PHP_FUNCTION(velocis_fieldnum)
|
1999-04-19 23:04:11 +08:00
|
|
|
{
|
|
|
|
pval *ind;
|
|
|
|
Vresult *res;
|
|
|
|
|
|
|
|
if ( ARG_COUNT(ht) != 1 || getParameters(ht,1,&ind) == FAILURE ) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_long(ind);
|
|
|
|
res = velocis_find_result(list,ind->value.lval);
|
|
|
|
if ( !res ) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Velocis: Not result index (%d),ind->value.lval");
|
1999-04-19 23:04:11 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_LONG(res->numcols);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_VELOCIS */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
*/
|