2004-05-17 23:43:01 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2014-09-20 00:33:14 +08:00
|
|
|
| PHP Version 7 |
|
2004-05-17 23:43:01 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2016-01-02 01:19:27 +08:00
|
|
|
| Copyright (c) 1997-2016 The PHP Group |
|
2004-05-17 23:43:01 +08: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. |
|
|
|
|
| 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. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Author: Wez Furlong <wez@php.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "php_ini.h"
|
|
|
|
#include "ext/standard/info.h"
|
|
|
|
#include "pdo/php_pdo.h"
|
|
|
|
#include "pdo/php_pdo_driver.h"
|
|
|
|
#include "php_pdo_odbc.h"
|
|
|
|
#include "php_pdo_odbc_int.h"
|
|
|
|
|
2008-03-14 00:55:09 +08:00
|
|
|
enum pdo_odbc_conv_result {
|
|
|
|
PDO_ODBC_CONV_NOT_REQUIRED,
|
|
|
|
PDO_ODBC_CONV_OK,
|
|
|
|
PDO_ODBC_CONV_FAIL
|
|
|
|
};
|
|
|
|
|
|
|
|
static int pdo_odbc_sqltype_is_unicode(pdo_odbc_stmt *S, SWORD sqltype)
|
|
|
|
{
|
|
|
|
if (!S->assume_utf8) return 0;
|
|
|
|
switch (sqltype) {
|
|
|
|
#ifdef SQL_WCHAR
|
|
|
|
case SQL_WCHAR:
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
#ifdef SQL_WLONGVARCHAR
|
|
|
|
case SQL_WLONGVARCHAR:
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
#ifdef SQL_WVARCHAR
|
|
|
|
case SQL_WVARCHAR:
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-03 17:22:58 +08:00
|
|
|
static int pdo_odbc_utf82ucs2(pdo_stmt_t *stmt, int is_unicode, const char *buf,
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_ulong buflen, zend_ulong *outlen)
|
2008-03-14 00:55:09 +08:00
|
|
|
{
|
|
|
|
#ifdef PHP_WIN32
|
|
|
|
if (is_unicode && buflen) {
|
|
|
|
pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
ret = MultiByteToWideChar(CP_UTF8, 0, buf, buflen, NULL, 0);
|
|
|
|
if (ret == 0) {
|
2008-08-03 20:15:55 +08:00
|
|
|
/*printf("%s:%d %d [%d] %.*s\n", __FILE__, __LINE__, GetLastError(), buflen, buflen, buf);*/
|
2008-03-14 00:55:09 +08:00
|
|
|
return PDO_ODBC_CONV_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret *= sizeof(WCHAR);
|
|
|
|
|
|
|
|
if (S->convbufsize <= ret) {
|
|
|
|
S->convbufsize = ret + sizeof(WCHAR);
|
|
|
|
S->convbuf = erealloc(S->convbuf, S->convbufsize);
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2008-03-14 00:55:09 +08:00
|
|
|
ret = MultiByteToWideChar(CP_UTF8, 0, buf, buflen, (LPWSTR)S->convbuf, S->convbufsize / sizeof(WCHAR));
|
|
|
|
if (ret == 0) {
|
2008-08-03 20:15:55 +08:00
|
|
|
/*printf("%s:%d %d [%d] %.*s\n", __FILE__, __LINE__, GetLastError(), buflen, buflen, buf);*/
|
2008-03-14 00:55:09 +08:00
|
|
|
return PDO_ODBC_CONV_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret *= sizeof(WCHAR);
|
|
|
|
*outlen = ret;
|
|
|
|
return PDO_ODBC_CONV_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return PDO_ODBC_CONV_NOT_REQUIRED;
|
|
|
|
}
|
|
|
|
|
2015-01-03 17:22:58 +08:00
|
|
|
static int pdo_odbc_ucs22utf8(pdo_stmt_t *stmt, int is_unicode, const char *buf,
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_ulong buflen, zend_ulong *outlen)
|
2008-03-14 00:55:09 +08:00
|
|
|
{
|
|
|
|
#ifdef PHP_WIN32
|
|
|
|
if (is_unicode && buflen) {
|
|
|
|
pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
ret = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)buf, buflen/sizeof(WCHAR), NULL, 0, NULL, NULL);
|
|
|
|
if (ret == 0) {
|
|
|
|
return PDO_ODBC_CONV_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (S->convbufsize <= ret) {
|
|
|
|
S->convbufsize = ret + 1;
|
|
|
|
S->convbuf = erealloc(S->convbuf, S->convbufsize);
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2008-03-14 00:55:09 +08:00
|
|
|
ret = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)buf, buflen/sizeof(WCHAR), S->convbuf, S->convbufsize, NULL, NULL);
|
|
|
|
if (ret == 0) {
|
|
|
|
return PDO_ODBC_CONV_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*outlen = ret;
|
|
|
|
S->convbuf[*outlen] = '\0';
|
|
|
|
return PDO_ODBC_CONV_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return PDO_ODBC_CONV_NOT_REQUIRED;
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void free_cols(pdo_stmt_t *stmt, pdo_odbc_stmt *S)
|
2005-01-19 09:13:39 +08:00
|
|
|
{
|
|
|
|
if (S->cols) {
|
2005-04-20 04:55:02 +08:00
|
|
|
int i;
|
|
|
|
|
2005-01-19 09:13:39 +08:00
|
|
|
for (i = 0; i < stmt->column_count; i++) {
|
|
|
|
if (S->cols[i].data) {
|
|
|
|
efree(S->cols[i].data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
efree(S->cols);
|
|
|
|
S->cols = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static int odbc_stmt_dtor(pdo_stmt_t *stmt)
|
2004-05-17 23:43:01 +08:00
|
|
|
{
|
|
|
|
pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;
|
|
|
|
|
|
|
|
if (S->stmt != SQL_NULL_HANDLE) {
|
|
|
|
if (stmt->executed) {
|
2005-07-07 22:20:04 +08:00
|
|
|
SQLCloseCursor(S->stmt);
|
2004-05-17 23:43:01 +08:00
|
|
|
}
|
|
|
|
SQLFreeHandle(SQL_HANDLE_STMT, S->stmt);
|
|
|
|
S->stmt = SQL_NULL_HANDLE;
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
free_cols(stmt, S);
|
2008-03-14 00:55:09 +08:00
|
|
|
if (S->convbuf) {
|
|
|
|
efree(S->convbuf);
|
|
|
|
}
|
2004-05-17 23:43:01 +08:00
|
|
|
efree(S);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static int odbc_stmt_execute(pdo_stmt_t *stmt)
|
2004-05-17 23:43:01 +08:00
|
|
|
{
|
|
|
|
RETCODE rc;
|
|
|
|
pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;
|
2005-02-07 11:27:54 +08:00
|
|
|
char *buf = NULL;
|
2011-06-27 09:36:39 +08:00
|
|
|
SQLLEN row_count = -1;
|
2004-05-17 23:43:01 +08:00
|
|
|
|
|
|
|
if (stmt->executed) {
|
2005-07-07 22:20:04 +08:00
|
|
|
SQLCloseCursor(S->stmt);
|
2004-05-17 23:43:01 +08:00
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
|
|
|
rc = SQLExecute(S->stmt);
|
2004-05-17 23:43:01 +08:00
|
|
|
|
2005-02-07 11:27:54 +08:00
|
|
|
while (rc == SQL_NEED_DATA) {
|
|
|
|
struct pdo_bound_param_data *param;
|
2008-03-14 00:55:09 +08:00
|
|
|
|
2005-02-07 12:13:32 +08:00
|
|
|
rc = SQLParamData(S->stmt, (SQLPOINTER*)¶m);
|
2005-02-07 11:27:54 +08:00
|
|
|
if (rc == SQL_NEED_DATA) {
|
|
|
|
php_stream *stm;
|
|
|
|
int len;
|
2008-03-14 00:55:09 +08:00
|
|
|
pdo_odbc_param *P;
|
2014-08-12 15:00:06 +08:00
|
|
|
zval *parameter;
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2008-03-14 00:55:09 +08:00
|
|
|
P = (pdo_odbc_param*)param->driver_data;
|
2014-08-12 15:00:06 +08:00
|
|
|
if (Z_ISREF(param->parameter)) {
|
|
|
|
parameter = Z_REFVAL(param->parameter);
|
|
|
|
} else {
|
|
|
|
parameter = ¶m->parameter;
|
|
|
|
}
|
|
|
|
if (Z_TYPE_P(parameter) != IS_RESOURCE) {
|
2005-02-07 11:27:54 +08:00
|
|
|
/* they passed in a string */
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_ulong ulen;
|
2014-08-12 15:00:06 +08:00
|
|
|
convert_to_string(parameter);
|
2008-03-14 00:55:09 +08:00
|
|
|
|
2015-01-03 17:22:58 +08:00
|
|
|
switch (pdo_odbc_utf82ucs2(stmt, P->is_unicode,
|
2014-08-12 15:00:06 +08:00
|
|
|
Z_STRVAL_P(parameter),
|
2014-08-26 01:24:55 +08:00
|
|
|
Z_STRLEN_P(parameter),
|
2008-03-14 00:55:09 +08:00
|
|
|
&ulen)) {
|
|
|
|
case PDO_ODBC_CONV_NOT_REQUIRED:
|
2014-08-12 15:00:06 +08:00
|
|
|
SQLPutData(S->stmt, Z_STRVAL_P(parameter),
|
2014-08-26 01:24:55 +08:00
|
|
|
Z_STRLEN_P(parameter));
|
2008-03-14 00:55:09 +08:00
|
|
|
break;
|
|
|
|
case PDO_ODBC_CONV_OK:
|
|
|
|
SQLPutData(S->stmt, S->convbuf, ulen);
|
|
|
|
break;
|
|
|
|
case PDO_ODBC_CONV_FAIL:
|
|
|
|
pdo_odbc_stmt_error("error converting input string");
|
|
|
|
SQLCloseCursor(S->stmt);
|
|
|
|
if (buf) {
|
|
|
|
efree(buf);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2005-02-07 11:27:54 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-03-14 00:55:09 +08:00
|
|
|
/* we assume that LOBs are binary and don't need charset
|
|
|
|
* conversion */
|
|
|
|
|
2014-08-12 15:00:06 +08:00
|
|
|
php_stream_from_zval_no_verify(stm, parameter);
|
2005-02-07 11:27:54 +08:00
|
|
|
if (!stm) {
|
|
|
|
/* shouldn't happen either */
|
|
|
|
pdo_odbc_stmt_error("input LOB is no longer a stream");
|
2005-07-07 22:20:04 +08:00
|
|
|
SQLCloseCursor(S->stmt);
|
2005-02-07 12:13:32 +08:00
|
|
|
if (buf) {
|
|
|
|
efree(buf);
|
|
|
|
}
|
|
|
|
return 0;
|
2005-02-07 11:27:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* now suck data from the stream and stick it into the database */
|
|
|
|
if (buf == NULL) {
|
|
|
|
buf = emalloc(8192);
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
len = php_stream_read(stm, buf, 8192);
|
|
|
|
if (len == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SQLPutData(S->stmt, buf, len);
|
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
efree(buf);
|
|
|
|
}
|
|
|
|
|
2004-05-17 23:43:01 +08:00
|
|
|
switch (rc) {
|
|
|
|
case SQL_SUCCESS:
|
|
|
|
break;
|
|
|
|
case SQL_NO_DATA_FOUND:
|
|
|
|
case SQL_SUCCESS_WITH_INFO:
|
2004-05-22 08:30:00 +08:00
|
|
|
pdo_odbc_stmt_error("SQLExecute");
|
2004-05-17 23:43:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-05-22 08:30:00 +08:00
|
|
|
pdo_odbc_stmt_error("SQLExecute");
|
2004-05-17 23:43:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-30 12:19:24 +08:00
|
|
|
SQLRowCount(S->stmt, &row_count);
|
|
|
|
stmt->row_count = row_count;
|
|
|
|
|
2004-05-17 23:43:01 +08:00
|
|
|
if (!stmt->executed) {
|
|
|
|
/* do first-time-only definition of bind/mapping stuff */
|
|
|
|
SQLSMALLINT colcount;
|
|
|
|
|
|
|
|
/* how many columns do we have ? */
|
|
|
|
SQLNumResultCols(S->stmt, &colcount);
|
|
|
|
|
|
|
|
stmt->column_count = (int)colcount;
|
|
|
|
S->cols = ecalloc(colcount, sizeof(pdo_odbc_column));
|
2006-03-28 05:04:12 +08:00
|
|
|
S->going_long = 0;
|
2004-05-17 23:43:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *param,
|
2014-12-14 06:06:14 +08:00
|
|
|
enum pdo_param_event event_type)
|
2004-05-17 23:43:01 +08:00
|
|
|
{
|
|
|
|
pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;
|
|
|
|
RETCODE rc;
|
2005-07-07 20:49:21 +08:00
|
|
|
SWORD sqltype = 0, ctype = 0, scale = 0, nullable = 0;
|
2014-02-25 01:01:58 +08:00
|
|
|
SQLULEN precision = 0;
|
2005-02-07 11:27:54 +08:00
|
|
|
pdo_odbc_param *P;
|
2014-08-12 15:00:06 +08:00
|
|
|
zval *parameter;
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2004-05-17 23:43:01 +08:00
|
|
|
/* we're only interested in parameters for prepared SQL right now */
|
|
|
|
if (param->is_param) {
|
|
|
|
|
|
|
|
switch (event_type) {
|
2013-08-21 01:33:00 +08:00
|
|
|
case PDO_PARAM_EVT_FETCH_PRE:
|
|
|
|
case PDO_PARAM_EVT_FETCH_POST:
|
|
|
|
case PDO_PARAM_EVT_NORMALIZE:
|
|
|
|
/* Do nothing */
|
|
|
|
break;
|
|
|
|
|
2005-02-07 11:27:54 +08:00
|
|
|
case PDO_PARAM_EVT_FREE:
|
|
|
|
P = param->driver_data;
|
|
|
|
if (P) {
|
|
|
|
efree(P);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-05-17 23:43:01 +08:00
|
|
|
case PDO_PARAM_EVT_ALLOC:
|
2005-02-07 11:27:54 +08:00
|
|
|
{
|
2004-05-17 23:43:01 +08:00
|
|
|
/* figure out what we're doing */
|
2005-02-07 09:16:16 +08:00
|
|
|
switch (PDO_PARAM_TYPE(param->param_type)) {
|
2004-05-17 23:43:01 +08:00
|
|
|
case PDO_PARAM_LOB:
|
2005-02-07 11:27:54 +08:00
|
|
|
break;
|
|
|
|
|
2004-05-17 23:43:01 +08:00
|
|
|
case PDO_PARAM_STMT:
|
|
|
|
return 0;
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2004-05-17 23:43:01 +08:00
|
|
|
default:
|
2005-07-07 20:49:21 +08:00
|
|
|
break;
|
2004-05-17 23:43:01 +08:00
|
|
|
}
|
|
|
|
|
2009-05-19 18:25:53 +08:00
|
|
|
rc = SQLDescribeParam(S->stmt, (SQLUSMALLINT) param->paramno+1, &sqltype, &precision, &scale, &nullable);
|
2005-07-07 20:49:21 +08:00
|
|
|
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
|
|
|
|
/* MS Access, for instance, doesn't support SQLDescribeParam,
|
|
|
|
* so we need to guess */
|
|
|
|
sqltype = PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB ?
|
|
|
|
SQL_LONGVARBINARY :
|
|
|
|
SQL_LONGVARCHAR;
|
|
|
|
precision = 4000;
|
|
|
|
scale = 5;
|
|
|
|
nullable = 1;
|
|
|
|
|
|
|
|
if (param->max_value_len > 0) {
|
|
|
|
precision = param->max_value_len;
|
|
|
|
}
|
|
|
|
}
|
2004-05-17 23:43:01 +08:00
|
|
|
if (sqltype == SQL_BINARY || sqltype == SQL_VARBINARY || sqltype == SQL_LONGVARBINARY) {
|
|
|
|
ctype = SQL_C_BINARY;
|
|
|
|
} else {
|
|
|
|
ctype = SQL_C_CHAR;
|
|
|
|
}
|
2005-02-07 11:27:54 +08:00
|
|
|
|
|
|
|
P = emalloc(sizeof(*P));
|
|
|
|
param->driver_data = P;
|
|
|
|
|
|
|
|
P->len = 0; /* is re-populated each EXEC_PRE */
|
2005-07-07 20:49:21 +08:00
|
|
|
P->outbuf = NULL;
|
2005-02-07 11:27:54 +08:00
|
|
|
|
2008-03-14 00:55:09 +08:00
|
|
|
P->is_unicode = pdo_odbc_sqltype_is_unicode(S, sqltype);
|
|
|
|
if (P->is_unicode) {
|
|
|
|
/* avoid driver auto-translation: we'll do it ourselves */
|
|
|
|
ctype = SQL_C_BINARY;
|
|
|
|
}
|
|
|
|
|
2005-02-07 11:27:54 +08:00
|
|
|
if ((param->param_type & PDO_PARAM_INPUT_OUTPUT) == PDO_PARAM_INPUT_OUTPUT) {
|
|
|
|
P->paramtype = SQL_PARAM_INPUT_OUTPUT;
|
|
|
|
} else if (param->max_value_len <= 0) {
|
|
|
|
P->paramtype = SQL_PARAM_INPUT;
|
|
|
|
} else {
|
|
|
|
P->paramtype = SQL_PARAM_OUTPUT;
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2005-07-07 20:49:21 +08:00
|
|
|
if (P->paramtype != SQL_PARAM_INPUT) {
|
|
|
|
if (PDO_PARAM_TYPE(param->param_type) != PDO_PARAM_NULL) {
|
|
|
|
/* need an explicit buffer to hold result */
|
|
|
|
P->len = param->max_value_len > 0 ? param->max_value_len : precision;
|
2008-03-14 00:55:09 +08:00
|
|
|
if (P->is_unicode) {
|
|
|
|
P->len *= 2;
|
|
|
|
}
|
|
|
|
P->outbuf = emalloc(P->len + (P->is_unicode ? 2:1));
|
2005-07-07 20:49:21 +08:00
|
|
|
}
|
2005-02-07 12:13:32 +08:00
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2005-02-07 11:27:54 +08:00
|
|
|
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB && P->paramtype != SQL_PARAM_INPUT) {
|
2005-02-13 14:27:03 +08:00
|
|
|
pdo_odbc_stmt_error("Can't bind a lob for output");
|
2005-02-07 11:27:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-19 18:25:53 +08:00
|
|
|
rc = SQLBindParameter(S->stmt, (SQLUSMALLINT) param->paramno+1,
|
2005-02-07 11:27:54 +08:00
|
|
|
P->paramtype, ctype, sqltype, precision, scale,
|
2015-01-03 17:22:58 +08:00
|
|
|
P->paramtype == SQL_PARAM_INPUT ?
|
2005-07-07 20:49:21 +08:00
|
|
|
(SQLPOINTER)param :
|
|
|
|
P->outbuf,
|
|
|
|
P->len,
|
2005-02-07 11:27:54 +08:00
|
|
|
&P->len
|
2004-05-17 23:43:01 +08:00
|
|
|
);
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2005-01-21 14:11:10 +08:00
|
|
|
if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
pdo_odbc_stmt_error("SQLBindParameter");
|
|
|
|
return 0;
|
2005-02-07 11:27:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case PDO_PARAM_EVT_EXEC_PRE:
|
|
|
|
P = param->driver_data;
|
2014-08-12 15:00:06 +08:00
|
|
|
if (!Z_ISREF(param->parameter)) {
|
|
|
|
parameter = ¶m->parameter;
|
|
|
|
} else {
|
|
|
|
parameter = Z_REFVAL(param->parameter);
|
|
|
|
}
|
|
|
|
|
2005-02-07 11:27:54 +08:00
|
|
|
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB) {
|
2014-08-12 15:00:06 +08:00
|
|
|
if (Z_TYPE_P(parameter) == IS_RESOURCE) {
|
2005-02-07 11:27:54 +08:00
|
|
|
php_stream *stm;
|
|
|
|
php_stream_statbuf sb;
|
|
|
|
|
2014-08-12 15:00:06 +08:00
|
|
|
php_stream_from_zval_no_verify(stm, parameter);
|
2005-02-07 11:27:54 +08:00
|
|
|
|
|
|
|
if (!stm) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == php_stream_stat(stm, &sb)) {
|
2005-07-07 20:49:21 +08:00
|
|
|
if (P->outbuf) {
|
|
|
|
int len, amount;
|
|
|
|
char *ptr = P->outbuf;
|
|
|
|
char *end = P->outbuf + P->len;
|
|
|
|
|
|
|
|
P->len = 0;
|
|
|
|
do {
|
|
|
|
amount = end - ptr;
|
|
|
|
if (amount == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (amount > 8192)
|
|
|
|
amount = 8192;
|
|
|
|
len = php_stream_read(stm, ptr, amount);
|
|
|
|
if (len == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ptr += len;
|
|
|
|
P->len += len;
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
P->len = SQL_LEN_DATA_AT_EXEC(sb.sb.st_size);
|
|
|
|
}
|
2005-02-07 11:27:54 +08:00
|
|
|
} else {
|
2005-07-07 20:49:21 +08:00
|
|
|
if (P->outbuf) {
|
|
|
|
P->len = 0;
|
|
|
|
} else {
|
|
|
|
P->len = SQL_LEN_DATA_AT_EXEC(0);
|
|
|
|
}
|
2005-02-07 11:27:54 +08:00
|
|
|
}
|
|
|
|
} else {
|
2014-08-12 15:00:06 +08:00
|
|
|
convert_to_string(parameter);
|
2005-07-07 20:49:21 +08:00
|
|
|
if (P->outbuf) {
|
2014-08-26 01:24:55 +08:00
|
|
|
P->len = Z_STRLEN_P(parameter);
|
2014-08-12 15:00:06 +08:00
|
|
|
memcpy(P->outbuf, Z_STRVAL_P(parameter), P->len);
|
2005-07-07 20:49:21 +08:00
|
|
|
} else {
|
2014-08-26 01:24:55 +08:00
|
|
|
P->len = SQL_LEN_DATA_AT_EXEC(Z_STRLEN_P(parameter));
|
2005-07-07 20:49:21 +08:00
|
|
|
}
|
2005-02-07 11:27:54 +08:00
|
|
|
}
|
2014-08-12 15:00:06 +08:00
|
|
|
} else if (Z_TYPE_P(parameter) == IS_NULL || PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_NULL) {
|
2005-07-07 20:49:21 +08:00
|
|
|
P->len = SQL_NULL_DATA;
|
2005-02-07 11:27:54 +08:00
|
|
|
} else {
|
2014-08-12 15:00:06 +08:00
|
|
|
convert_to_string(parameter);
|
2005-07-07 20:49:21 +08:00
|
|
|
if (P->outbuf) {
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_ulong ulen;
|
2008-03-14 00:55:09 +08:00
|
|
|
switch (pdo_odbc_utf82ucs2(stmt, P->is_unicode,
|
2014-08-12 15:00:06 +08:00
|
|
|
Z_STRVAL_P(parameter),
|
2014-08-26 01:24:55 +08:00
|
|
|
Z_STRLEN_P(parameter),
|
2008-03-14 00:55:09 +08:00
|
|
|
&ulen)) {
|
|
|
|
case PDO_ODBC_CONV_FAIL:
|
|
|
|
case PDO_ODBC_CONV_NOT_REQUIRED:
|
2014-08-26 01:24:55 +08:00
|
|
|
P->len = Z_STRLEN_P(parameter);
|
2014-08-12 15:00:06 +08:00
|
|
|
memcpy(P->outbuf, Z_STRVAL_P(parameter), P->len);
|
2008-03-14 00:55:09 +08:00
|
|
|
break;
|
|
|
|
case PDO_ODBC_CONV_OK:
|
|
|
|
P->len = ulen;
|
|
|
|
memcpy(P->outbuf, S->convbuf, P->len);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-07 20:49:21 +08:00
|
|
|
} else {
|
2014-08-26 01:24:55 +08:00
|
|
|
P->len = SQL_LEN_DATA_AT_EXEC(Z_STRLEN_P(parameter));
|
2005-07-07 20:49:21 +08:00
|
|
|
}
|
2005-02-07 11:27:54 +08:00
|
|
|
}
|
|
|
|
return 1;
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2005-02-07 11:27:54 +08:00
|
|
|
case PDO_PARAM_EVT_EXEC_POST:
|
2005-07-07 20:49:21 +08:00
|
|
|
P = param->driver_data;
|
2014-08-12 15:00:06 +08:00
|
|
|
|
2005-07-07 20:49:21 +08:00
|
|
|
if (P->outbuf) {
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_ulong ulen;
|
2014-08-12 15:00:06 +08:00
|
|
|
char *srcbuf;
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_ulong srclen = 0;
|
2008-03-14 00:55:09 +08:00
|
|
|
|
2014-08-12 15:00:06 +08:00
|
|
|
if (Z_ISREF(param->parameter)) {
|
|
|
|
parameter = Z_REFVAL(param->parameter);
|
|
|
|
} else {
|
|
|
|
parameter = ¶m->parameter;
|
|
|
|
}
|
|
|
|
zval_ptr_dtor(parameter);
|
|
|
|
ZVAL_NULL(parameter);
|
|
|
|
|
|
|
|
switch (P->len) {
|
|
|
|
case SQL_NULL_DATA:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
switch (pdo_odbc_ucs22utf8(stmt, P->is_unicode, P->outbuf, P->len, &ulen)) {
|
|
|
|
case PDO_ODBC_CONV_FAIL:
|
|
|
|
/* something fishy, but allow it to come back as binary */
|
|
|
|
case PDO_ODBC_CONV_NOT_REQUIRED:
|
|
|
|
srcbuf = P->outbuf;
|
|
|
|
srclen = P->len;
|
|
|
|
break;
|
|
|
|
case PDO_ODBC_CONV_OK:
|
|
|
|
srcbuf = S->convbuf;
|
|
|
|
srclen = ulen;
|
|
|
|
break;
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-08-26 01:24:55 +08:00
|
|
|
ZVAL_NEW_STR(parameter, zend_string_alloc(srclen, 0));
|
2014-08-12 15:00:06 +08:00
|
|
|
memcpy(Z_STRVAL_P(parameter), srcbuf, srclen);
|
2014-08-26 01:24:55 +08:00
|
|
|
Z_STRVAL_P(parameter)[Z_STRLEN_P(parameter)] = '\0';
|
2005-07-07 20:49:21 +08:00
|
|
|
}
|
2005-02-07 12:13:32 +08:00
|
|
|
}
|
|
|
|
return 1;
|
2004-05-17 23:43:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-01-12 13:58:19 +08:00
|
|
|
static int odbc_stmt_fetch(pdo_stmt_t *stmt,
|
2014-12-14 06:06:14 +08:00
|
|
|
enum pdo_fetch_orientation ori, zend_long offset)
|
2004-05-17 23:43:01 +08:00
|
|
|
{
|
|
|
|
RETCODE rc;
|
2005-01-12 13:58:19 +08:00
|
|
|
SQLSMALLINT odbcori;
|
2008-03-14 00:55:09 +08:00
|
|
|
pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;
|
2005-02-13 15:00:29 +08:00
|
|
|
|
2005-01-12 13:58:19 +08:00
|
|
|
switch (ori) {
|
|
|
|
case PDO_FETCH_ORI_NEXT: odbcori = SQL_FETCH_NEXT; break;
|
|
|
|
case PDO_FETCH_ORI_PRIOR: odbcori = SQL_FETCH_PRIOR; break;
|
|
|
|
case PDO_FETCH_ORI_FIRST: odbcori = SQL_FETCH_FIRST; break;
|
|
|
|
case PDO_FETCH_ORI_LAST: odbcori = SQL_FETCH_LAST; break;
|
|
|
|
case PDO_FETCH_ORI_ABS: odbcori = SQL_FETCH_ABSOLUTE; break;
|
|
|
|
case PDO_FETCH_ORI_REL: odbcori = SQL_FETCH_RELATIVE; break;
|
2015-01-03 17:22:58 +08:00
|
|
|
default:
|
2005-02-13 15:00:29 +08:00
|
|
|
strcpy(stmt->error_code, "HY106");
|
|
|
|
return 0;
|
2005-01-12 13:58:19 +08:00
|
|
|
}
|
|
|
|
rc = SQLFetchScroll(S->stmt, odbcori, offset);
|
2004-05-17 23:43:01 +08:00
|
|
|
|
2006-10-11 11:07:29 +08:00
|
|
|
if (rc == SQL_SUCCESS) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (rc == SQL_SUCCESS_WITH_INFO) {
|
2005-07-07 20:49:21 +08:00
|
|
|
pdo_odbc_stmt_error("SQLFetchScroll");
|
2004-05-17 23:43:01 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc == SQL_NO_DATA) {
|
2005-07-07 22:20:04 +08:00
|
|
|
/* pdo_odbc_stmt_error("SQLFetchScroll"); */
|
2004-05-17 23:43:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-01-17 13:28:13 +08:00
|
|
|
pdo_odbc_stmt_error("SQLFetchScroll");
|
2004-05-17 23:43:01 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static int odbc_stmt_describe(pdo_stmt_t *stmt, int colno)
|
2004-05-17 23:43:01 +08:00
|
|
|
{
|
|
|
|
pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;
|
|
|
|
struct pdo_column_data *col = &stmt->columns[colno];
|
|
|
|
RETCODE rc;
|
|
|
|
SWORD colnamelen;
|
2014-02-25 01:01:58 +08:00
|
|
|
SQLULEN colsize;
|
2013-12-22 19:42:45 +08:00
|
|
|
SQLLEN displaysize;
|
2004-05-17 23:43:01 +08:00
|
|
|
|
|
|
|
rc = SQLDescribeCol(S->stmt, colno+1, S->cols[colno].colname,
|
|
|
|
sizeof(S->cols[colno].colname)-1, &colnamelen,
|
|
|
|
&S->cols[colno].coltype, &colsize, NULL, NULL);
|
|
|
|
|
2005-07-07 20:49:21 +08:00
|
|
|
if (rc != SQL_SUCCESS) {
|
2006-10-11 11:07:29 +08:00
|
|
|
pdo_odbc_stmt_error("SQLDescribeCol");
|
|
|
|
if (rc != SQL_SUCCESS_WITH_INFO) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = SQLColAttribute(S->stmt, colno+1,
|
|
|
|
SQL_DESC_DISPLAY_SIZE,
|
|
|
|
NULL, 0, NULL, &displaysize);
|
|
|
|
|
|
|
|
if (rc != SQL_SUCCESS) {
|
|
|
|
pdo_odbc_stmt_error("SQLColAttribute");
|
|
|
|
if (rc != SQL_SUCCESS_WITH_INFO) {
|
|
|
|
return 0;
|
|
|
|
}
|
2005-07-07 20:49:21 +08:00
|
|
|
}
|
2006-10-11 11:07:29 +08:00
|
|
|
colsize = displaysize;
|
2005-07-07 20:49:21 +08:00
|
|
|
|
2004-05-17 23:43:01 +08:00
|
|
|
col->maxlen = S->cols[colno].datalen = colsize;
|
2015-05-05 21:19:51 +08:00
|
|
|
col->name = zend_string_init(S->cols[colno].colname, colnamelen, 0);
|
2008-03-14 00:55:09 +08:00
|
|
|
S->cols[colno].is_unicode = pdo_odbc_sqltype_is_unicode(S, S->cols[colno].coltype);
|
2004-05-17 23:43:01 +08:00
|
|
|
|
|
|
|
/* returning data as a string */
|
|
|
|
col->param_type = PDO_PARAM_STR;
|
|
|
|
|
2005-07-19 23:26:16 +08:00
|
|
|
/* tell ODBC to put it straight into our buffer, but only if it
|
2006-03-28 05:04:12 +08:00
|
|
|
* isn't "long" data, and only if we haven't already bound a long
|
|
|
|
* column. */
|
|
|
|
if (colsize < 256 && !S->going_long) {
|
2005-07-19 23:26:16 +08:00
|
|
|
S->cols[colno].data = emalloc(colsize+1);
|
2006-10-11 10:10:56 +08:00
|
|
|
S->cols[colno].is_long = 0;
|
2005-07-19 23:26:16 +08:00
|
|
|
|
2008-03-14 00:55:09 +08:00
|
|
|
rc = SQLBindCol(S->stmt, colno+1,
|
|
|
|
S->cols[colno].is_unicode ? SQL_C_BINARY : SQL_C_CHAR,
|
|
|
|
S->cols[colno].data,
|
|
|
|
S->cols[colno].datalen+1, &S->cols[colno].fetched_len);
|
2005-07-07 20:49:21 +08:00
|
|
|
|
2005-07-19 23:26:16 +08:00
|
|
|
if (rc != SQL_SUCCESS) {
|
|
|
|
pdo_odbc_stmt_error("SQLBindCol");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* allocate a smaller buffer to keep around for smaller
|
|
|
|
* "long" columns */
|
|
|
|
S->cols[colno].data = emalloc(256);
|
2006-03-28 05:04:12 +08:00
|
|
|
S->going_long = 1;
|
2006-10-11 10:10:56 +08:00
|
|
|
S->cols[colno].is_long = 1;
|
2005-07-07 20:49:21 +08:00
|
|
|
}
|
|
|
|
|
2004-05-17 23:43:01 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, zend_ulong *len, int *caller_frees)
|
2004-05-17 23:43:01 +08:00
|
|
|
{
|
|
|
|
pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;
|
|
|
|
pdo_odbc_column *C = &S->cols[colno];
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_ulong ulen;
|
2004-05-17 23:43:01 +08:00
|
|
|
|
2005-07-19 23:26:16 +08:00
|
|
|
/* if it is a column containing "long" data, perform late binding now */
|
2006-10-11 10:10:56 +08:00
|
|
|
if (C->is_long) {
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_ulong used = 0;
|
2005-07-19 23:26:16 +08:00
|
|
|
char *buf;
|
|
|
|
RETCODE rc;
|
|
|
|
|
|
|
|
/* fetch it into C->data, which is allocated with a length
|
|
|
|
* of 256 bytes; if there is more to be had, we then allocate
|
|
|
|
* bigger buffer for the caller to free */
|
|
|
|
|
2008-03-14 00:55:09 +08:00
|
|
|
rc = SQLGetData(S->stmt, colno+1, C->is_unicode ? SQL_C_BINARY : SQL_C_CHAR, C->data,
|
|
|
|
256, &C->fetched_len);
|
2005-07-19 23:26:16 +08:00
|
|
|
|
|
|
|
if (rc == SQL_SUCCESS) {
|
|
|
|
/* all the data fit into our little buffer;
|
|
|
|
* jump down to the generic bound data case */
|
|
|
|
goto in_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc == SQL_SUCCESS_WITH_INFO) {
|
2012-07-13 21:34:00 +08:00
|
|
|
/* this is a 'long column'
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2012-07-13 21:34:00 +08:00
|
|
|
read the column in 255 byte blocks until the end of the column is reached, reassembling those blocks
|
|
|
|
in order into the output buffer
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2012-07-13 21:34:00 +08:00
|
|
|
this loop has to work whether or not SQLGetData() provides the total column length.
|
|
|
|
calling SQLDescribeCol() or other, specifically to get the column length, then doing a single read
|
|
|
|
for that size would be slower except maybe for extremely long columns.*/
|
|
|
|
char *buf2;
|
|
|
|
|
|
|
|
buf2 = emalloc(256);
|
|
|
|
buf = estrndup(C->data, 256);
|
|
|
|
used = 255; /* not 256; the driver NUL terminated the buffer */
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2005-07-19 23:26:16 +08:00
|
|
|
do {
|
|
|
|
C->fetched_len = 0;
|
2012-07-13 21:34:00 +08:00
|
|
|
/* read block. 256 bytes => 255 bytes are actually read, the last 1 is NULL */
|
|
|
|
rc = SQLGetData(S->stmt, colno+1, SQL_C_CHAR, buf2, 256, &C->fetched_len);
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2012-07-13 21:34:00 +08:00
|
|
|
/* resize output buffer and reassemble block */
|
|
|
|
if (rc==SQL_SUCCESS_WITH_INFO) {
|
|
|
|
/* point 5, in section "Retrieving Data with SQLGetData" in http://msdn.microsoft.com/en-us/library/windows/desktop/ms715441(v=vs.85).aspx
|
|
|
|
states that if SQL_SUCCESS_WITH_INFO, fetched_len will be > 255 (greater than buf2's size)
|
|
|
|
(if a driver fails to follow that and wrote less than 255 bytes to buf2, this will AV or read garbage into buf) */
|
|
|
|
buf = erealloc(buf, used + 255+1);
|
|
|
|
memcpy(buf + used, buf2, 255);
|
|
|
|
used = used + 255;
|
|
|
|
} else if (rc==SQL_SUCCESS) {
|
|
|
|
buf = erealloc(buf, used + C->fetched_len+1);
|
|
|
|
memcpy(buf + used, buf2, C->fetched_len);
|
|
|
|
used = used + C->fetched_len;
|
2005-07-19 23:26:16 +08:00
|
|
|
} else {
|
2012-07-13 21:34:00 +08:00
|
|
|
/* includes SQL_NO_DATA */
|
2006-10-11 10:10:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2005-07-19 23:26:16 +08:00
|
|
|
} while (1);
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2012-07-13 21:34:00 +08:00
|
|
|
efree(buf2);
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2012-07-13 21:34:00 +08:00
|
|
|
/* NULL terminate the buffer once, when finished, for use with the rest of PHP */
|
2005-07-19 23:26:16 +08:00
|
|
|
buf[used] = '\0';
|
2012-07-13 21:34:00 +08:00
|
|
|
|
2005-07-19 23:26:16 +08:00
|
|
|
*ptr = buf;
|
|
|
|
*caller_frees = 1;
|
|
|
|
*len = used;
|
2008-03-14 00:55:09 +08:00
|
|
|
if (C->is_unicode) {
|
|
|
|
goto unicode_conv;
|
|
|
|
}
|
2005-07-19 23:26:16 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* something went caca */
|
|
|
|
*ptr = NULL;
|
|
|
|
*len = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
in_data:
|
2004-05-17 23:43:01 +08:00
|
|
|
/* check the indicator to ensure that the data is intact */
|
|
|
|
if (C->fetched_len == SQL_NULL_DATA) {
|
|
|
|
/* A NULL value */
|
|
|
|
*ptr = NULL;
|
|
|
|
*len = 0;
|
|
|
|
return 1;
|
|
|
|
} else if (C->fetched_len >= 0) {
|
|
|
|
/* it was stored perfectly */
|
|
|
|
*ptr = C->data;
|
|
|
|
*len = C->fetched_len;
|
2008-03-14 00:55:09 +08:00
|
|
|
if (C->is_unicode) {
|
|
|
|
goto unicode_conv;
|
|
|
|
}
|
2004-05-17 23:43:01 +08:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
/* no data? */
|
|
|
|
*ptr = NULL;
|
|
|
|
*len = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
2008-03-14 00:55:09 +08:00
|
|
|
|
|
|
|
unicode_conv:
|
|
|
|
switch (pdo_odbc_ucs22utf8(stmt, C->is_unicode, *ptr, *len, &ulen)) {
|
|
|
|
case PDO_ODBC_CONV_FAIL:
|
|
|
|
/* oh well. They can have the binary version of it */
|
|
|
|
case PDO_ODBC_CONV_NOT_REQUIRED:
|
|
|
|
/* shouldn't happen... */
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case PDO_ODBC_CONV_OK:
|
|
|
|
if (*caller_frees) {
|
|
|
|
efree(*ptr);
|
|
|
|
}
|
|
|
|
*ptr = emalloc(ulen + 1);
|
|
|
|
*len = ulen;
|
|
|
|
memcpy(*ptr, S->convbuf, ulen+1);
|
|
|
|
*caller_frees = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 1;
|
2004-05-17 23:43:01 +08:00
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static int odbc_stmt_set_param(pdo_stmt_t *stmt, zend_long attr, zval *val)
|
2004-05-26 02:33:51 +08:00
|
|
|
{
|
|
|
|
SQLRETURN rc;
|
|
|
|
pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;
|
|
|
|
|
|
|
|
switch (attr) {
|
|
|
|
case PDO_ATTR_CURSOR_NAME:
|
|
|
|
convert_to_string(val);
|
2014-08-26 01:24:55 +08:00
|
|
|
rc = SQLSetCursorName(S->stmt, Z_STRVAL_P(val), Z_STRLEN_P(val));
|
2004-05-26 02:33:51 +08:00
|
|
|
|
|
|
|
if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) {
|
|
|
|
return 1;
|
|
|
|
}
|
2004-05-26 02:34:46 +08:00
|
|
|
pdo_odbc_stmt_error("SQLSetCursorName");
|
2004-05-26 02:33:51 +08:00
|
|
|
return 0;
|
|
|
|
|
2008-03-14 00:55:09 +08:00
|
|
|
case PDO_ODBC_ATTR_ASSUME_UTF8:
|
|
|
|
S->assume_utf8 = zval_is_true(val);
|
|
|
|
return 0;
|
2004-05-26 02:33:51 +08:00
|
|
|
default:
|
|
|
|
strcpy(S->einfo.last_err_msg, "Unknown Attribute");
|
|
|
|
S->einfo.what = "setAttribute";
|
2009-07-15 10:32:43 +08:00
|
|
|
strcpy(S->einfo.last_state, "IM001");
|
2004-05-26 02:33:51 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2005-01-19 09:13:39 +08:00
|
|
|
}
|
2004-05-26 02:33:51 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static int odbc_stmt_get_attr(pdo_stmt_t *stmt, zend_long attr, zval *val)
|
2005-02-07 01:49:48 +08:00
|
|
|
{
|
|
|
|
SQLRETURN rc;
|
|
|
|
pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;
|
|
|
|
|
|
|
|
switch (attr) {
|
|
|
|
case PDO_ATTR_CURSOR_NAME:
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
SQLSMALLINT len = 0;
|
|
|
|
rc = SQLGetCursorName(S->stmt, buf, sizeof(buf), &len);
|
|
|
|
|
|
|
|
if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) {
|
2014-08-12 15:00:06 +08:00
|
|
|
ZVAL_STRINGL(val, buf, len);
|
2005-02-07 01:49:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
pdo_odbc_stmt_error("SQLGetCursorName");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-14 00:55:09 +08:00
|
|
|
case PDO_ODBC_ATTR_ASSUME_UTF8:
|
|
|
|
ZVAL_BOOL(val, S->assume_utf8 ? 1 : 0);
|
|
|
|
return 0;
|
|
|
|
|
2005-02-07 01:49:48 +08:00
|
|
|
default:
|
|
|
|
strcpy(S->einfo.last_err_msg, "Unknown Attribute");
|
|
|
|
S->einfo.what = "getAttribute";
|
2009-07-15 10:32:43 +08:00
|
|
|
strcpy(S->einfo.last_state, "IM001");
|
2005-02-07 01:49:48 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static int odbc_stmt_next_rowset(pdo_stmt_t *stmt)
|
2005-01-19 09:13:39 +08:00
|
|
|
{
|
|
|
|
SQLRETURN rc;
|
|
|
|
SQLSMALLINT colcount;
|
|
|
|
pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;
|
|
|
|
|
2005-07-07 20:49:21 +08:00
|
|
|
/* NOTE: can't guarantee that output or input/output parameters
|
|
|
|
* are set until this fella returns SQL_NO_DATA, according to
|
|
|
|
* MSDN ODBC docs */
|
2005-01-19 09:13:39 +08:00
|
|
|
rc = SQLMoreResults(S->stmt);
|
|
|
|
|
|
|
|
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
|
|
|
|
return 0;
|
|
|
|
}
|
2004-05-26 02:33:51 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
free_cols(stmt, S);
|
2005-01-19 09:13:39 +08:00
|
|
|
/* how many columns do we have ? */
|
|
|
|
SQLNumResultCols(S->stmt, &colcount);
|
|
|
|
stmt->column_count = (int)colcount;
|
|
|
|
S->cols = ecalloc(colcount, sizeof(pdo_odbc_column));
|
2006-03-28 05:04:12 +08:00
|
|
|
S->going_long = 0;
|
2005-01-19 09:13:39 +08:00
|
|
|
|
|
|
|
return 1;
|
2004-05-26 02:33:51 +08:00
|
|
|
}
|
|
|
|
|
2004-05-17 23:43:01 +08:00
|
|
|
struct pdo_stmt_methods odbc_stmt_methods = {
|
|
|
|
odbc_stmt_dtor,
|
|
|
|
odbc_stmt_execute,
|
|
|
|
odbc_stmt_fetch,
|
|
|
|
odbc_stmt_describe,
|
|
|
|
odbc_stmt_get_col,
|
2004-05-26 02:33:51 +08:00
|
|
|
odbc_stmt_param_hook,
|
|
|
|
odbc_stmt_set_param,
|
2005-02-07 01:49:48 +08:00
|
|
|
odbc_stmt_get_attr, /* get attr */
|
2005-01-19 09:13:39 +08:00
|
|
|
NULL, /* get column meta */
|
|
|
|
odbc_stmt_next_rowset
|
2004-05-17 23:43:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
* vim600: noet sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: noet sw=4 ts=4
|
|
|
|
*/
|