php-src/ext/ovrimos/ovrimos.c

1292 lines
29 KiB
C
Raw Normal View History

2000-11-08 16:16:49 +00:00
/*
+----------------------------------------------------------------------+
2004-01-08 08:18:22 +00:00
| PHP Version 5 |
2000-11-08 16:16:49 +00:00
+----------------------------------------------------------------------+
2004-01-08 08:18:22 +00:00
| Copyright (c) 1997-2004 The PHP Group |
2000-11-08 16:16:49 +00:00
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 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_0.txt. |
2000-11-08 16:16:49 +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 |
2000-11-08 16:16:49 +00:00
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
2001-07-04 13:33:11 +00:00
| Authors: Dimitris Souflis, Nikos Mavroyanopoulos |
| for Ovrimos S.A. |
| |
| Contact support@ovrimos.com for questions regarding this module |
2000-11-08 16:16:49 +00:00
+----------------------------------------------------------------------+
*/
2000-10-11 16:54:23 +00:00
/* $Id$ */
2003-02-17 03:07:33 +00:00
#include "php.h"
#include "php_globals.h"
#include "zend_API.h"
#include "ext/standard/php_standard.h"
2000-10-11 16:54:23 +00:00
#include "ext/standard/info.h"
2003-02-17 03:07:33 +00:00
2001-07-04 13:33:11 +00:00
#include <sqlcli.h> /* ovrimos header
*/
2001-07-25 13:30:36 +00:00
#ifndef WIN32 /* stricmp is defined in sqlcli */
2000-10-11 16:54:23 +00:00
# define stricmp strcasecmp
#endif
2001-07-25 13:30:36 +00:00
2000-10-11 16:54:23 +00:00
2000-11-08 16:16:49 +00:00
PHP_MINFO_FUNCTION(ovrimos)
{
2001-10-06 20:13:39 +00:00
php_printf("&quot;Ovrimos&quot; module<br />\n");
2000-10-11 16:54:23 +00:00
}
2001-07-04 13:33:11 +00:00
/* Main User Functions
*/
/* ovrimos_connect() currently does not support secure (SSL/TLS) connections.
* As an alternative you can use the unixODBC driver available at
2001-07-26 10:11:35 +00:00
* http://www.ovrimos.com/download which supports SSL.
2001-07-04 13:33:11 +00:00
* Contact support@ovrimos.com for more information.
*/
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
/* 2001-07-27: ovrimos_close_all() function was removed in order
* for this module to be reentrant.
*/
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
/* structures introduced in order to support the old ovrimos-php-api with
* the new multi-threaded library (old works with the old library).
* This version is reentrant.
*
* The only limitation is that a connection ( as returned by ovrimos_connect())
* may only be accessed by one thread (but this is the case in php now).
2001-07-25 13:30:36 +00:00
*/
2001-07-26 10:11:35 +00:00
2001-07-25 13:30:36 +00:00
typedef struct {
2001-07-26 10:11:35 +00:00
SQLS statement;
int longreadlen;
struct _CON_STATE* con_state;
} STATEMENT;
typedef struct _CON_STATE {
2001-07-25 13:30:36 +00:00
SQLH connection;
2001-07-26 10:11:35 +00:00
STATEMENT * statements;
2001-07-25 13:30:36 +00:00
int nstatements;
2001-07-26 10:11:35 +00:00
} CON_STATE;
typedef STATEMENT* PSTATEMENT;
typedef CON_STATE* PCON_STATE;
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
static void column_to_string(SQLS stmt, int i, char *buffer, int *len, PSTATEMENT pstmt);
2001-07-25 13:30:36 +00:00
2000-10-11 16:54:23 +00:00
/* {{{ proto int ovrimos_connect(string host, string db, string user, string password)
Connect to an Ovrimos database */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_connect)
{
pval *arg1, *arg2, *arg3, *arg4;
2001-07-26 10:11:35 +00:00
PCON_STATE state;
2000-11-08 16:16:49 +00:00
SQLH conn = 0;
2001-07-26 10:11:35 +00:00
2000-11-08 16:16:49 +00:00
if (ARG_COUNT(ht) != 4
|| getParameters(ht, 4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg1);
convert_to_string(arg2);
convert_to_string(arg3);
convert_to_string(arg4);
2001-07-26 10:11:35 +00:00
2000-11-08 16:16:49 +00:00
if (!sqlConnect
(Z_STRVAL_P(arg1), Z_STRVAL_P(arg2), Z_STRVAL_P(arg3),
Z_STRVAL_P(arg4), &conn, 0)) {
2000-11-08 16:16:49 +00:00
RETURN_LONG(0);
}
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
state = ecalloc( 1, sizeof(CON_STATE));
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
state->connection = conn;
state->statements = NULL;
state->nstatements = 0;
RETURN_LONG( (long)state);
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
/* {{{ proto void ovrimos_close(int connection)
Close a connection */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_close)
{
pval *arg1;
2001-07-26 10:11:35 +00:00
int i;
PCON_STATE state;
2001-07-25 13:30:36 +00:00
2000-11-08 16:16:49 +00:00
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE
|| Z_TYPE_P(arg1) != IS_LONG) {
2000-11-08 16:16:49 +00:00
WRONG_PARAM_COUNT;
}
2001-07-25 13:30:36 +00:00
state = (PCON_STATE) Z_LVAL_P(arg1);
2001-07-25 13:30:36 +00:00
/* free all the statements associated with
* the connection. (called results in php)
*/
2001-07-26 10:11:35 +00:00
for (i=0;i < state->nstatements;i++) {
if ( state->statements[i].statement!=NULL) {
sqlFreeStmt( state->statements[i].statement);
2001-07-25 13:30:36 +00:00
}
}
2001-07-26 10:11:35 +00:00
if (state->statements!=NULL)
efree( state->statements);
2001-07-25 13:30:36 +00:00
/* close the SQL_Handle
*/
2001-07-26 10:11:35 +00:00
sqlDisconnect( state->connection);
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
efree( state);
2001-07-25 13:30:36 +00:00
return;
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
2003-06-22 14:33:09 +00:00
/* {{{ proto bool ovrimos_longreadlen(int result_id, int length)
2000-10-11 16:54:23 +00:00
Handle LONG columns */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_longreadlen)
{
pval *arg1, *arg2;
2001-07-26 10:11:35 +00:00
PSTATEMENT stmt;
2000-11-08 16:16:49 +00:00
if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg1);
convert_to_long(arg2);
2001-07-26 10:11:35 +00:00
stmt = (PSTATEMENT) Z_LVAL_P(arg1);
2001-07-26 10:11:35 +00:00
stmt->longreadlen = Z_LVAL_P(arg2);
2000-11-08 16:16:49 +00:00
RETURN_TRUE;
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
2001-07-26 10:11:35 +00:00
#define DEFAULT_LONGREADLEN 0
/* These two functions are quite expensive. Some optimization may be
* done in a later version.
*/
static int local_sqlAllocStmt( PCON_STATE state, SQLH conn, SQLS *stmt, PSTATEMENT* pstmt) {
int index, ret;
2001-07-25 13:30:36 +00:00
ret = sqlAllocStmt( conn, stmt);
if (!ret) return ret;
2001-07-26 10:11:35 +00:00
state->nstatements++;
state->statements = erealloc(state->statements, state->nstatements*sizeof( STATEMENT));
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
index = state->nstatements - 1;
state->statements[ index].statement = (*stmt);
state->statements[ index].longreadlen = DEFAULT_LONGREADLEN;
state->statements[ index].con_state = state;
*pstmt = &state->statements[ index];
return 1;
2001-07-25 13:30:36 +00:00
}
2001-07-26 10:11:35 +00:00
static int local_sqlFreeStmt( PSTATEMENT statement, SQLS stmt) {
2001-07-25 13:30:36 +00:00
int j, i;
2001-07-26 10:11:35 +00:00
PSTATEMENT new_statements;
PCON_STATE state = statement->con_state;
2001-07-25 13:30:36 +00:00
sqlFreeStmt( stmt);
2001-07-26 10:11:35 +00:00
if (state->nstatements-1 == 0) {
efree( state->statements);
state->statements = NULL;
state->nstatements--;
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
return 1;
}
2001-07-25 13:30:36 +00:00
2003-08-12 00:58:52 +00:00
new_statements = safe_emalloc( (state->nstatements-1), sizeof(STATEMENT), 0);
2001-07-26 10:11:35 +00:00
for (i=j=0;i<state->nstatements;i++) {
if (state->statements->statement != stmt) {
new_statements[j].statement = state->statements[i].statement;
new_statements[j].longreadlen = state->statements[i].longreadlen;
new_statements[j++].con_state = state->statements[i].con_state;
}
}
efree( state->statements);
state->statements = new_statements;
state->nstatements--;
return 1; /* true */
2001-07-25 13:30:36 +00:00
}
2000-10-11 16:54:23 +00:00
/* {{{ proto int ovrimos_prepare(int connection_id, string query)
Prepares a statement for execution */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_prepare)
{
pval *arg1, *arg2;
SQLH conn;
char *query;
SQLS stmt;
2001-07-26 10:11:35 +00:00
PCON_STATE state;
PSTATEMENT pstmt;
2000-11-08 16:16:49 +00:00
if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg1);
convert_to_string(arg2);
2001-07-25 13:30:36 +00:00
state = (PCON_STATE) Z_LVAL_P(arg1);
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
conn = (SQLH) state->connection;
query = Z_STRVAL_P(arg2);
2000-11-08 16:16:49 +00:00
2001-07-26 10:11:35 +00:00
if (!local_sqlAllocStmt( state, conn, &stmt, &pstmt)) {
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
if (!sqlPrepare(stmt, query)) {
2001-07-26 10:11:35 +00:00
local_sqlFreeStmt( pstmt, stmt);
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
if (!sqlGetOutputColDescr(stmt)) {
2001-07-26 10:11:35 +00:00
local_sqlFreeStmt( pstmt, stmt);
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
if (!sqlGetParamDescr(stmt)) {
2001-07-26 10:11:35 +00:00
local_sqlFreeStmt( pstmt, stmt);
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
/* returns a result id which is actually a
* pointer to a STATEMENT structure;
2001-07-25 13:30:36 +00:00
*/
2001-07-26 10:11:35 +00:00
RETURN_LONG( (long)pstmt);
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
/*
* Execute prepared SQL statement. Supports only input parameters.
*/
2003-06-22 14:33:09 +00:00
/* {{{ proto bool ovrimos_execute(int result_id [, array parameters_array])
2000-10-11 16:54:23 +00:00
Execute a prepared statement */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_execute)
{
pval *arg1, *arg2;
SQLS stmt;
int numArgs;
int icol, colnb;
2001-07-26 10:11:35 +00:00
PSTATEMENT pstmt;
2000-11-08 16:16:49 +00:00
2001-07-25 13:30:36 +00:00
numArgs = ARG_COUNT(ht);
2000-11-08 16:16:49 +00:00
if (getParameters(ht, numArgs, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg1);
pstmt = (PSTATEMENT) Z_LVAL_P(arg1);
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
stmt = pstmt->statement;
2000-11-08 16:16:49 +00:00
colnb = sqlGetParamNb(stmt);
if (colnb != 0) {
pval **tmp;
int arr_elem;
if (Z_TYPE_P(arg2) != IS_ARRAY) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not an array in call to ovrimos_execute()");
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
arr_elem = zend_hash_num_elements(Z_ARRVAL_P(arg2));
2000-11-08 16:16:49 +00:00
if (arr_elem < colnb) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not enough parameters in call to ovrimos_execute(): %d instead of %d", arr_elem, colnb);
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
zend_hash_internal_pointer_reset(Z_ARRVAL_P(arg2));
2000-11-08 16:16:49 +00:00
for (icol = 0; icol < colnb; icol++) {
int len;
cvt_error err;
bool ret;
char *msg;
char buffer[10240];
sql_type to_type = sqlGetParamSQLType(stmt, icol);
sql_type from_type;
if (zend_hash_get_current_data
(Z_ARRVAL_P(arg2), (void **) &tmp) == FAILURE) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error getting parameter %d in call to ovrimos_execute()", icol);
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
convert_to_string(*tmp);
if (Z_TYPE_PP(tmp) != IS_STRING) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error converting parameter %d to string in call to ovrimos_execute()", icol);
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
/* PHP data to param type */
Z_TYPE(from_type) = T_VARCHAR;
from_type.u.length = Z_STRLEN_PP(tmp);
2000-11-08 16:16:49 +00:00
*buffer = 0;
memcpy(buffer + 1, Z_STRVAL_PP(tmp),
2000-11-08 16:16:49 +00:00
from_type.u.length);
buffer[from_type.u.length + 1] = 0;
ret =
type_convert(buffer, &from_type, &to_type, 0,
&err);
switch (err) {
case cvt_trunc:
msg = "Data truncated";
break;
case cvt_range:
msg = "Numeric value out of range";
break;
case cvt_prec:
msg = "Precision lost";
break;
case cvt_incomp:
msg =
"Restricted data type attribute violation";
break;
case cvt_no:
msg = "Conversion failed";
break;
2001-07-26 10:11:35 +00:00
default:
msg = "Unknown error";
break;
2000-11-08 16:16:49 +00:00
}
if (!ret) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error converting parameter %d: %s in call to ovrimos_execute()", icol, msg);
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
len = sql_type_size(to_type) - 1;
if (!sqlPutParam(stmt, icol, buffer + 1, len)) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could send parameter %d (%d bytes) in call to ovrimos_execute()", icol, len);
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
}
}
if (!sqlExec(stmt)) {
RETURN_FALSE;
}
RETURN_TRUE;
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
/* {{{ proto string ovrimos_cursor(int result_id)
Get cursor name */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_cursor)
{
char cname[126];
pval *arg1;
SQLS stmt;
2001-07-26 10:11:35 +00:00
PSTATEMENT pstmt;
2001-07-25 13:30:36 +00:00
2000-11-08 16:16:49 +00:00
if (getParameters(ht, 1, &arg1) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg1);
2001-07-25 13:30:36 +00:00
pstmt = (PSTATEMENT) Z_LVAL_P(arg1);
2001-07-26 10:11:35 +00:00
stmt = pstmt->statement;
2001-07-25 13:30:36 +00:00
2000-11-08 16:16:49 +00:00
if (!sqlGetCursorName(stmt, cname)) {
RETURN_FALSE;
}
RETURN_STRING(cname, 1);
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
2001-07-26 10:11:35 +00:00
/* This function returns a result id. The result ID is
* a pointer to a STATEMENT structure.
2001-07-25 13:30:36 +00:00
* Every result is mapped to a statement.
*/
2000-10-11 16:54:23 +00:00
/* {{{ proto int ovrimos_exec(int connection_id, string query)
Prepare and execute an SQL statement */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_exec)
{
pval *arg1, *arg2;
SQLH conn;
SQLS stmt;
int numArgs;
char *query;
2001-07-26 10:11:35 +00:00
PSTATEMENT pstmt;
PCON_STATE state;
2001-07-25 13:30:36 +00:00
2000-11-08 16:16:49 +00:00
numArgs = ARG_COUNT(ht);
if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg1);
convert_to_string(arg2);
2001-07-25 13:30:36 +00:00
state = (PCON_STATE) Z_LVAL_P(arg1);
2001-07-26 10:11:35 +00:00
conn = state->connection;
query = Z_STRVAL_P(arg2);
2000-11-08 16:16:49 +00:00
2001-07-26 10:11:35 +00:00
if (!local_sqlAllocStmt( state, conn, &stmt, &pstmt)) {
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
2001-07-25 13:30:36 +00:00
2000-11-08 16:16:49 +00:00
if (!sqlExecDirect(stmt, query)) {
2001-07-26 10:11:35 +00:00
local_sqlFreeStmt( pstmt, stmt);
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
if (!sqlGetOutputColDescr(stmt)) {
2001-07-26 10:11:35 +00:00
local_sqlFreeStmt( pstmt, stmt);
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
if (!sqlGetParamDescr(stmt)) {
2001-07-26 10:11:35 +00:00
local_sqlFreeStmt( pstmt, stmt);
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
RETURN_LONG( (long)pstmt);
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
/* {{{ column_to_string
*/
2001-07-26 10:11:35 +00:00
static void column_to_string(SQLS stmt, int i, char *buffer, int *len, PSTATEMENT pstmt)
2000-11-08 16:16:49 +00:00
{
const char *bf = sqlColValue(stmt, i, 0);
2001-07-26 10:11:35 +00:00
int longreadlen;
longreadlen = pstmt->longreadlen;
2000-11-08 16:16:49 +00:00
switch (sqlGetOutputColType(stmt, i)) {
case T_BIGINT:
case T_UBIGINT:{
switch (sqlGetOutputColType(stmt, i)) {
case T_BIGINT:
printsint64(Read(sint64, bf), buffer);
break;
case T_UBIGINT:
printuint64(Read(uint64, bf), buffer);
break;
}
*len = strlen(buffer);
}
break;
case T_INTEGER:
2001-07-26 10:11:35 +00:00
sprintf(buffer, "%11d", Read(sint32, bf));
2000-11-08 16:16:49 +00:00
*len = strlen(buffer);
break;
case T_UINTEGER:
2001-07-26 10:11:35 +00:00
sprintf(buffer, "%10u", Read(uint32, bf));
2000-11-08 16:16:49 +00:00
*len = strlen(buffer);
break;
case T_SMALLINT:
sprintf(buffer, "%6hd", Read(sint16, bf));
*len = strlen(buffer);
break;
case T_USMALLINT:
sprintf(buffer, "%5hu", Read(uint16, bf));
*len = strlen(buffer);
break;
case T_TINYINT:
sprintf(buffer, "%4hd", (sint16) Read(sint8, bf));
*len = strlen(buffer);
break;
case T_UTINYINT:
sprintf(buffer, "%3hu", (uint16) Read(uint8, bf));
*len = strlen(buffer);
break;
case T_BIT:
sprintf(buffer, "%s",
(Read(uint8, bf) == 0) ? "off" : "on");
*len = strlen(buffer);
break;
case T_REAL:
sprintf(buffer, "%9.7g", (double) Read(float, bf));
*len = strlen(buffer);
break;
case T_FLOAT:
case T_DOUBLE:
sprintf(buffer, "%19.17g", Read(double, bf));
*len = strlen(buffer);
break;
case T_DECIMAL:
case T_NUMERIC:{
int prec = sqlGetOutputColPrecision(stmt, i);
int scale = sqlGetOutputColScale(stmt, i);
sprintf(buffer, "%*.*f", prec + 2, scale,
Read(double, bf));
*len = strlen(buffer);
} break;
case T_CHAR:
case T_VARCHAR:
strcpy(buffer, bf);
*len = strlen(buffer);
break;
case T_UNI_CHAR:
case T_UNI_VARCHAR:
uni_strcpy((uni_char *) buffer, (uni_char *) bf);
*len = uni_strlen((uni_char *) buffer);
break;
case T_BINARY:{
int sz = sqlGetOutputColLength(stmt, i);
memcpy(buffer, bf, sz);
*len = sz;
} break;
case T_VARBINARY:{
int sz = Read(uint16, bf);
memcpy(buffer, bf + 2, sz);
*len = sz;
} break;
case T_DATE:{
if (!sql_date_to_str((uint32 *) bf, buffer)) {
strcpy(buffer, "Error!");
}
}
break;
case T_TIME:{
int prec = sqlGetOutputColPrecision(stmt, i);
if (!sql_time_to_str
((uint32 *) bf, prec, 0, buffer)) {
strcpy(buffer, "Error!");
}
}
break;
case T_TIMESTAMP:{
int prec = sqlGetOutputColPrecision(stmt, i);
if (!sql_timestamp_to_str
((uint32 *) bf, prec, 0, buffer)) {
strcpy(buffer, "Error!");
}
}
break;
case T_LONGVARCHAR:
case T_LONGVARBINARY:{
if (longreadlen == 0) {
*buffer = 0;
*len = 0;
} else
if (!sqlColValueLong
(stmt, i, 0, 0, longreadlen, buffer, len)) {
strcpy(buffer, "Error!");
}
}
break;
}
2000-10-11 16:54:23 +00:00
}
/* }}} */
2000-10-11 16:54:23 +00:00
2003-06-22 14:33:09 +00:00
/* {{{ proto bool ovrimos_fetch_into(int result_id, array result_array [, string how [, int rownumber]])
2000-10-11 16:54:23 +00:00
Fetch one result row into an array
how: 'Next' (default), 'Prev', 'First', 'Last', 'Absolute'
*/
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_fetch_into)
{
int numArgs;
char *s_how;
typedef enum { h_next = 0, h_prev, h_first, h_last, h_absolute
} h_type;
h_type how = h_next; /* default */
sint32 rownum = 0;
pval *arg_id, *arg_how = 0, *arg_row = 0, *arr, *tmp;
SQLS stmt;
2001-07-26 10:11:35 +00:00
PSTATEMENT pstmt;
2000-11-08 16:16:49 +00:00
int icol, colnb;
2001-07-26 10:11:35 +00:00
bool ret=0;
2000-11-08 16:16:49 +00:00
numArgs = ARG_COUNT(ht);
switch (numArgs) {
case 2:
if (getParameters(ht, 2, &arg_id, &arr) == FAILURE)
WRONG_PARAM_COUNT;
break;
case 3:
if (getParameters(ht, 3, &arg_id, &arr, &arg_how) ==
FAILURE) WRONG_PARAM_COUNT;
break;
case 4:
if (getParameters(ht, 4, &arg_id, &arr, &arg_how, &arg_row)
== FAILURE)
WRONG_PARAM_COUNT;
break;
default:
WRONG_PARAM_COUNT;
}
convert_to_long(arg_id);
pstmt = (PSTATEMENT) Z_LVAL_P(arg_id);
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
stmt = pstmt->statement;
2000-11-08 16:16:49 +00:00
if (arg_how != 0) {
if (Z_TYPE_P(arg_how) != IS_STRING) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Third argument not string in ovrimos_fetch_into()");
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
s_how = Z_STRVAL_P(arg_how);
2000-11-08 16:16:49 +00:00
if (stricmp(s_how, "next") == 0) {
how = h_next;
} else if (stricmp(s_how, "prev") == 0) {
how = h_prev;
} else if (stricmp(s_how, "first") == 0) {
how = h_first;
} else if (stricmp(s_how, "last") == 0) {
how = h_last;
} else if (stricmp(s_how, "absolute") == 0) {
how = h_absolute;
} else {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Third argument not valid in ovrimos_fetch_into()");
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
if (arg_row == 0 && how == h_absolute) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Fourth argument is required for ABSOLUTE in ovrimos_fetch_into()");
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
if (arg_row != 0) {
convert_to_long(arg_row);
rownum = Z_LVAL_P(arg_row);
2000-11-08 16:16:49 +00:00
switch (how) {
case h_next:
case h_prev:
rownum--; /* Next 1 should send FUNC_CURSOR_NEXT(0) */
break;
2001-07-26 10:11:35 +00:00
default:
break;
2000-11-08 16:16:49 +00:00
}
}
}
if (Z_TYPE_P(arr) != IS_ARRAY) {
array_init(arr);
2000-11-08 16:16:49 +00:00
}
switch (how) {
case h_absolute:
case h_first:
ret = sqlCursorFirst(stmt, rownum);
break;
case h_last:
ret = sqlCursorLast(stmt, rownum);
break;
case h_next:
ret = sqlCursorNext(stmt, rownum);
break;
case h_prev:
ret = sqlCursorPrev(stmt, rownum);
break;
}
if (!ret) {
RETURN_FALSE;
}
2001-07-25 13:30:36 +00:00
2000-11-08 16:16:49 +00:00
colnb = sqlGetOutputColNb(stmt);
for (icol = 0; icol < colnb; icol++) {
int len;
char buffer[10240];
tmp = (pval *) emalloc(sizeof(pval));
tmp->refcount = 1;
Z_TYPE_P(tmp) = IS_STRING;
Z_STRLEN_P(tmp) = 0;
2000-11-08 16:16:49 +00:00
/* Produce column value in 'tmp' ... */
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
column_to_string(stmt, icol, buffer, &len, pstmt);
Z_STRLEN_P(tmp) = len;
Z_STRVAL_P(tmp) = estrndup(buffer, len);
2000-11-08 16:16:49 +00:00
zend_hash_index_update(Z_ARRVAL_P(arr), icol, &tmp,
2000-11-08 16:16:49 +00:00
sizeof(pval *), NULL);
}
2001-07-25 13:30:36 +00:00
2000-11-08 16:16:49 +00:00
RETURN_TRUE;
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
2003-06-22 14:33:09 +00:00
/* {{{ proto bool ovrimos_fetch_row(int result_id [, int how [, int row_number]])
2000-10-11 16:54:23 +00:00
how: 'Next' (default), 'Prev', 'First', 'Last', 'Absolute'
Fetch a row */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_fetch_row)
{
2001-07-26 10:11:35 +00:00
int numArgs;
2000-11-08 16:16:49 +00:00
char *s_how;
typedef enum { h_next = 0, h_prev, h_first, h_last, h_absolute
} h_type;
h_type how = h_next; /* default */
sint32 rownum = 0;
pval *arg_id, *arg_how = 0, *arg_row = 0;
SQLS stmt;
2001-07-26 10:11:35 +00:00
PSTATEMENT pstmt;
bool ret = 0;
2000-11-08 16:16:49 +00:00
numArgs = ARG_COUNT(ht);
switch (numArgs) {
case 1:
if (getParameters(ht, 1, &arg_id) == FAILURE)
WRONG_PARAM_COUNT;
break;
case 2:
if (getParameters(ht, 2, &arg_id, &arg_how) == FAILURE)
WRONG_PARAM_COUNT;
break;
case 3:
if (getParameters(ht, 3, &arg_id, &arg_how, &arg_row) ==
FAILURE) WRONG_PARAM_COUNT;
break;
default:
WRONG_PARAM_COUNT;
}
convert_to_long(arg_id);
2001-07-25 13:30:36 +00:00
pstmt = (PSTATEMENT) Z_LVAL_P(arg_id);
2001-07-26 10:11:35 +00:00
stmt = (SQLS) pstmt->statement;
2000-11-08 16:16:49 +00:00
if (arg_how != 0) {
if (Z_TYPE_P(arg_how) != IS_STRING) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second argument not string in ovrimos_fetch_row()");
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
s_how = Z_STRVAL_P(arg_how);
2000-11-08 16:16:49 +00:00
if (stricmp(s_how, "next") == 0) {
how = h_next;
} else if (stricmp(s_how, "prev") == 0) {
how = h_prev;
} else if (stricmp(s_how, "first") == 0) {
how = h_first;
} else if (stricmp(s_how, "last") == 0) {
how = h_last;
} else if (stricmp(s_how, "absolute") == 0) {
how = h_absolute;
} else {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second argument not valid in ovrimos_fetch_row()");
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
if (arg_row == 0 && how == 4) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Third argument is required for ABSOLUTE in ovrimos_fetch_row()");
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
if (arg_row != 0) {
convert_to_long(arg_row);
rownum = Z_LVAL_P(arg_row);
2000-11-08 16:16:49 +00:00
switch (how) {
case h_next:
case h_prev:
rownum--; /* Next 1 should send FUNC_CURSOR_NEXT(0) */
break;
2001-07-26 10:11:35 +00:00
default:
break;
2000-11-08 16:16:49 +00:00
}
}
}
switch (how) {
case h_absolute:
case h_first:
ret = sqlCursorFirst(stmt, rownum);
break;
case h_last:
ret = sqlCursorLast(stmt, rownum);
break;
case h_next:
ret = sqlCursorNext(stmt, rownum);
break;
case h_prev:
ret = sqlCursorPrev(stmt, rownum);
break;
}
if (!ret) {
RETURN_FALSE;
}
RETURN_TRUE;
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
/* {{{ proto string ovrimos_result(int result_id, mixed field)
Get result data */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_result)
{
int numArgs = ARG_COUNT(ht);
pval *arg_id, *arg_field;
2001-07-26 10:11:35 +00:00
int icol=0, colnb;
2000-11-08 16:16:49 +00:00
SQLS stmt;
2001-07-26 10:11:35 +00:00
int len;
PSTATEMENT pstmt;
2000-11-08 16:16:49 +00:00
char buffer[1024];
if (numArgs != 2
|| getParameters(ht, 2, &arg_id,
&arg_field) == FAILURE) WRONG_PARAM_COUNT;
convert_to_long(arg_id);
pstmt = (PSTATEMENT) Z_LVAL_P(arg_id);
2001-07-26 10:11:35 +00:00
stmt = (SQLS) pstmt->statement;
2000-11-08 16:16:49 +00:00
colnb = sqlGetOutputColNb(stmt);
if (Z_TYPE_P(arg_field) == IS_STRING) {
2000-11-08 16:16:49 +00:00
int i;
for (i = 0; i < colnb; i++) {
if (!stricmp
(Z_STRVAL_P(arg_field),
2000-11-08 16:16:49 +00:00
sqlGetOutputColName(stmt, i))) {
icol = i;
break;
}
}
} else if (Z_TYPE_P(arg_field) == IS_LONG) {
icol = Z_LVAL_P(arg_field) - 1;
2000-11-08 16:16:49 +00:00
} else {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second argument neither number nor string in ovrimos_result()");
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
if (icol < 0 || icol > colnb) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown column in ovrimos_result()");
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
2001-07-26 10:11:35 +00:00
column_to_string(stmt, icol, buffer, &len, pstmt);
2000-11-08 16:16:49 +00:00
RETURN_STRINGL(buffer, len, 1);
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
/* {{{ proto int ovrimos_result_all(int result_id [, string format])
Print result as HTML table */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_result_all)
{
long fetched = 0;
pval *arg1, *arg2;
int numArgs;
SQLS stmt;
int icol, colnb;
2001-07-26 10:11:35 +00:00
PSTATEMENT pstmt;
2000-11-08 16:16:49 +00:00
char buffer[1024];
int len;
numArgs = ARG_COUNT(ht);
if (numArgs == 1) {
if (getParameters(ht, 1, &arg1) == FAILURE)
WRONG_PARAM_COUNT;
} else {
if (getParameters(ht, 2, &arg1, &arg2) == FAILURE)
WRONG_PARAM_COUNT;
}
convert_to_long(arg1);
pstmt = (PSTATEMENT) Z_LVAL_P(arg1);
2001-07-26 10:11:35 +00:00
stmt = (SQLS) pstmt->statement;
2000-11-08 16:16:49 +00:00
colnb = sqlGetOutputColNb(stmt);
/* Start table tag */
if (numArgs == 1) {
php_printf("<table><tr>");
} else {
convert_to_string(arg2);
php_printf("<table %s ><tr>", Z_STRVAL_P(arg2));
2000-11-08 16:16:49 +00:00
}
for (icol = 0; icol < colnb; icol++) {
php_printf("<th>%s</th>", sqlGetOutputColName(stmt, icol));
}
php_printf("</tr>\n");
if (sqlCursorFirst(stmt, 0)) {
do {
fetched++;
php_printf("<tr>");
for (icol = 0; icol < colnb; icol++) {
2001-07-26 10:11:35 +00:00
column_to_string(stmt, icol, buffer, &len, pstmt);
2000-11-08 16:16:49 +00:00
php_printf("<td>%s</td>", buffer);
}
php_printf("</tr>\n");
} while (sqlCursorNext(stmt, 0));
}
php_printf("</table>\n");
RETURN_LONG(fetched);
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
2003-06-22 14:33:09 +00:00
/* {{{ proto bool ovrimos_free_result(int result_id)
2000-10-11 16:54:23 +00:00
Free resources associated with a result */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_free_result)
{
pval *arg1;
SQLS stmt;
2001-07-26 10:11:35 +00:00
PSTATEMENT pstmt;
2001-07-25 13:30:36 +00:00
2000-11-08 16:16:49 +00:00
if (getParameters(ht, 1, &arg1) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg1);
pstmt = (PSTATEMENT) Z_LVAL_P(arg1);
2001-07-26 10:11:35 +00:00
stmt = (SQLS) pstmt->statement;
2001-07-25 13:30:36 +00:00
sqlCloseCursor( stmt);
2001-07-26 10:11:35 +00:00
local_sqlFreeStmt( pstmt, stmt);
2000-11-08 16:16:49 +00:00
RETURN_TRUE;
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
/* {{{ proto int ovrimos_num_rows(int result_id)
Get number of rows in a result */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_num_rows)
{
uint32 rows;
pval *arg1;
SQLS stmt;
2001-07-26 10:11:35 +00:00
PSTATEMENT pstmt;
2000-10-11 16:54:23 +00:00
2000-11-08 16:16:49 +00:00
if (getParameters(ht, 1, &arg1) == FAILURE) {
WRONG_PARAM_COUNT;
}
2000-10-11 16:54:23 +00:00
2000-11-08 16:16:49 +00:00
convert_to_long(arg1);
pstmt = (PSTATEMENT) Z_LVAL_P(arg1);
2001-07-26 10:11:35 +00:00
stmt = (SQLS) pstmt->statement;
2001-07-25 13:30:36 +00:00
2000-10-11 16:54:23 +00:00
2000-11-08 16:16:49 +00:00
sqlGetRowCount(stmt, &rows);
RETURN_LONG(rows);
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
/* {{{ proto int ovrimos_num_fields(int result_id)
Get number of columns in a result */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_num_fields)
{
pval *arg1;
SQLS stmt;
2001-07-26 10:11:35 +00:00
PSTATEMENT pstmt;
2000-10-11 16:54:23 +00:00
2000-11-08 16:16:49 +00:00
if (getParameters(ht, 1, &arg1) == FAILURE) {
WRONG_PARAM_COUNT;
}
2000-10-11 16:54:23 +00:00
2000-11-08 16:16:49 +00:00
convert_to_long(arg1);
pstmt = (PSTATEMENT) Z_LVAL_P(arg1);
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
stmt = (SQLS) pstmt->statement;
2000-10-11 16:54:23 +00:00
2000-11-08 16:16:49 +00:00
RETURN_LONG(sqlGetOutputColNb(stmt));
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
/* {{{ proto string ovrimos_field_name(int result_id, int field_number)
Get a column name */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_field_name)
{
pval *arg1, *arg2;
SQLS stmt;
2001-07-26 10:11:35 +00:00
int field;
PSTATEMENT pstmt;
2000-11-08 16:16:49 +00:00
if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg1);
convert_to_long(arg2);
pstmt = (PSTATEMENT) Z_LVAL_P(arg1);
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
stmt = (SQLS) pstmt->statement;
2001-07-25 13:30:36 +00:00
2000-11-08 16:16:49 +00:00
if (Z_LVAL_P(arg2) < 1) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field numbering starts at 1! in call to ovrimos_field_name()");
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
field = Z_LVAL_P(arg2) - 1;
2000-11-08 16:16:49 +00:00
if (field >= sqlGetOutputColNb(stmt)) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No field at this index (%d) in call to ovrimos_field_name()", field);
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
RETURN_STRING((char *) sqlGetOutputColName(stmt, field), 1);
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
2003-06-22 14:33:09 +00:00
/* {{{ proto int ovrimos_field_type(int result_id, int field_number)
2000-10-11 16:54:23 +00:00
Get the datatype of a column */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_field_type)
{
pval *arg1, *arg2;
SQLS stmt;
2001-07-26 10:11:35 +00:00
int field;
PSTATEMENT pstmt;
2000-11-08 16:16:49 +00:00
if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg1);
convert_to_long(arg2);
pstmt = (PSTATEMENT) Z_LVAL_P(arg1);
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
stmt = (SQLS) pstmt->statement;
2000-11-08 16:16:49 +00:00
if (Z_LVAL_P(arg2) < 1) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field numbering starts at 1! in call to ovrimos_field_type()");
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
field = Z_LVAL_P(arg2) - 1;
2000-11-08 16:16:49 +00:00
if (field >= sqlGetOutputColNb(stmt)) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No field at this index (%d) in call to ovrimos_field_type()", field);
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
RETURN_LONG(sqlGetOutputColType(stmt, field));
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
/* {{{ proto int ovrimos_field_len(int result_id, int field_number)
Get the length of a column */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_field_len)
{
pval *arg1, *arg2;
SQLS stmt;
2001-07-26 10:11:35 +00:00
int field;
PSTATEMENT pstmt;
int longreadlen;
2000-11-08 16:16:49 +00:00
if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg1);
convert_to_long(arg2);
pstmt = (PSTATEMENT) Z_LVAL_P(arg1);
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
longreadlen = pstmt->longreadlen;
stmt = (SQLS) pstmt->statement;
2000-11-08 16:16:49 +00:00
if (Z_LVAL_P(arg2) < 1) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field numbering starts at 1! in call to ovrimos_field_len()");
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
field = Z_LVAL_P(arg2) - 1;
2000-11-08 16:16:49 +00:00
if (field >= sqlGetOutputColNb(stmt)) {
2003-01-19 00:45:53 +00:00
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No field at this index (%d) in call to ovrimos_field_len()", field);
2000-11-08 16:16:49 +00:00
RETURN_FALSE;
}
switch (sqlGetOutputColType(stmt, field)) {
case T_LONGVARCHAR:
case T_LONGVARBINARY:
RETURN_LONG(longreadlen);
default:
RETURN_LONG(sqlGetOutputColLength(stmt, field));
}
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
/* {{{ proto int ovrimos_field_num(int result_id, string field_name)
Return column number */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_field_num)
{
pval *arg1, *arg2;
SQLS stmt;
2001-07-26 10:11:35 +00:00
int i, n;
PSTATEMENT pstmt;
2000-11-08 16:16:49 +00:00
if (getParameters(ht, 2, &arg1, &arg2) == FAILURE
|| Z_TYPE_P(arg2) != IS_STRING) {
2000-11-08 16:16:49 +00:00
WRONG_PARAM_COUNT;
}
convert_to_long(arg1);
pstmt = (PSTATEMENT) Z_LVAL_P(arg1);
2001-07-26 10:11:35 +00:00
stmt = (SQLS) pstmt->statement;
2001-07-25 13:30:36 +00:00
2000-11-08 16:16:49 +00:00
n = sqlGetOutputColNb(stmt);
for (i = 0; i < n; i++) {
if (!strcmp
(Z_STRVAL_P(arg2), sqlGetOutputColName(stmt, i))) {
2000-11-08 16:16:49 +00:00
RETURN_LONG(i + 1);
}
}
RETURN_FALSE;
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
#if 0
/* {{{ proto int ovrimos_autocommit(int connection_id, int OnOff)
Toggle autocommit mode
There can be problems with pconnections!*/
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_autocommit)
{
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
#endif
2003-06-22 14:33:09 +00:00
/* {{{ proto bool ovrimos_commit(int connection_id)
2000-10-11 16:54:23 +00:00
Commit an ovrimos transaction */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_commit)
{
pval *arg1;
2001-07-25 13:30:36 +00:00
SQLS stmt;
2001-07-26 10:11:35 +00:00
int i;
PCON_STATE state;
2001-07-25 13:30:36 +00:00
2000-11-08 16:16:49 +00:00
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE
|| Z_TYPE_P(arg1) != IS_LONG) {
2000-11-08 16:16:49 +00:00
WRONG_PARAM_COUNT;
}
2001-07-25 13:30:36 +00:00
2001-07-04 13:33:11 +00:00
convert_to_long( arg1);
state = (PCON_STATE) Z_LVAL_P(arg1);
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
for (i=0;i<state->nstatements;i++) {
stmt = state->statements[ i].statement;
2001-07-25 13:30:36 +00:00
if (stmt==NULL) {
continue;
}
if (!sqlCommit(stmt)) {
RETURN_FALSE;
}
2000-11-08 16:16:49 +00:00
}
RETURN_TRUE;
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
2003-06-22 14:33:09 +00:00
/* {{{ proto bool ovrimos_rollback(int connection_id)
2000-10-11 16:54:23 +00:00
Rollback a transaction */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_rollback)
{
pval *arg1;
2001-07-25 13:30:36 +00:00
SQLS stmt;
2001-07-26 10:11:35 +00:00
int i;
PCON_STATE state;
2001-07-25 13:30:36 +00:00
2000-11-08 16:16:49 +00:00
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE
|| Z_TYPE_P(arg1) != IS_LONG) {
2000-11-08 16:16:49 +00:00
WRONG_PARAM_COUNT;
}
2001-07-25 13:30:36 +00:00
convert_to_long( arg1);
state = (PCON_STATE) Z_LVAL_P(arg1);
2001-07-25 13:30:36 +00:00
2001-07-26 10:11:35 +00:00
for (i=0;i<state->nstatements;i++) {
stmt = (SQLS) state->statements[ i].statement;
2001-07-25 13:30:36 +00:00
if (stmt==NULL) continue;
if (!sqlRollback(stmt)) {
RETURN_FALSE;
}
2000-11-08 16:16:49 +00:00
}
RETURN_TRUE;
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
#if 0
/* {{{ proto int ovrimos_setoption(int conn_id|result_id, int which, int option, int value)
Sets connection or statement options */
2000-11-08 16:16:49 +00:00
PHP_FUNCTION(ovrimos_setoption)
{
2000-10-11 16:54:23 +00:00
}
2000-11-08 16:16:49 +00:00
2000-10-11 16:54:23 +00:00
/* }}} */
#endif
/* {{{ ovrimos_functions[]
*/
2000-10-11 16:54:23 +00:00
function_entry ovrimos_functions[] = {
/* PHP_FE(ovrimos_setoption, NULL)*/
/* PHP_FE(ovrimos_autocommit, NULL)*/
2000-11-08 16:16:49 +00:00
PHP_FE(ovrimos_close, NULL)
PHP_FE(ovrimos_commit, NULL)
PHP_FE(ovrimos_connect, NULL)
PHP_FE(ovrimos_cursor, NULL)
PHP_FE(ovrimos_exec, NULL)
PHP_FE(ovrimos_prepare, NULL)
PHP_FE(ovrimos_execute, NULL)
PHP_FE(ovrimos_fetch_row, NULL)
2001-07-30 05:36:18 +00:00
PHP_FE(ovrimos_fetch_into, second_arg_force_ref)
2000-11-08 16:16:49 +00:00
PHP_FE(ovrimos_field_len, NULL)
PHP_FE(ovrimos_field_name, NULL)
PHP_FE(ovrimos_field_type, NULL)
PHP_FE(ovrimos_field_num, NULL)
PHP_FE(ovrimos_free_result, NULL)
PHP_FE(ovrimos_num_fields, NULL)
PHP_FE(ovrimos_num_rows, NULL)
PHP_FE(ovrimos_result, NULL)
PHP_FE(ovrimos_result_all, NULL)
PHP_FE(ovrimos_rollback, NULL)
2000-10-11 16:54:23 +00:00
/* PHP_FE(ovrimos_binmode, NULL)*/
2000-11-08 16:16:49 +00:00
PHP_FE(ovrimos_longreadlen, NULL)
PHP_FALIAS(ovrimos_do, ovrimos_exec, NULL) {NULL, NULL, NULL}
2000-10-11 16:54:23 +00:00
};
/* }}} */
2000-10-11 16:54:23 +00:00
zend_module_entry ovrimos_module_entry = {
STANDARD_MODULE_HEADER,
"ovrimos",
2000-11-08 16:16:49 +00:00
ovrimos_functions,
NULL,
NULL,
NULL,
NULL,
PHP_MINFO(ovrimos),
NO_VERSION_YET,
2000-11-08 16:16:49 +00:00
STANDARD_MODULE_PROPERTIES
2000-10-11 16:54:23 +00:00
};
2000-11-08 16:16:49 +00:00
DLEXPORT zend_module_entry *get_module()
{
return &ovrimos_module_entry;
};
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/