version 1.1.1.2, 2012/05/29 12:34:41
|
version 1.1.1.3, 2013/07/22 01:31:58
|
Line 2
|
Line 2
|
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| PHP Version 5 | |
| PHP Version 5 | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| Copyright (c) 1997-2012 The PHP Group | | | Copyright (c) 1997-2013 The PHP Group | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| This source file is subject to version 3.01 of the PHP license, | |
| This source file is subject to version 3.01 of the PHP license, | |
| that is bundled with this package in the file LICENSE, and is | |
| that is bundled with this package in the file LICENSE, and is | |
Line 75 static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt TSRMLS
|
Line 75 static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt TSRMLS
|
efree(S->in_length); |
efree(S->in_length); |
} |
} |
|
|
if (S->bound_result) | if (S->bound_result) |
{ |
{ |
int i; |
int i; |
for (i = 0; i < stmt->column_count; i++) { |
for (i = 0; i < stmt->column_count; i++) { |
pdo_free_bound_result(S->bound_result[i]); |
pdo_free_bound_result(S->bound_result[i]); |
} |
} |
| |
efree(S->bound_result); |
efree(S->bound_result); |
efree(S->out_null); |
efree(S->out_null); |
efree(S->out_length); |
efree(S->out_length); |
Line 95 static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt TSRMLS
|
Line 95 static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt TSRMLS
|
if (mysql_next_result(S->H->server) != 0) { |
if (mysql_next_result(S->H->server) != 0) { |
break; |
break; |
} |
} |
| |
res = mysql_store_result(S->H->server); |
res = mysql_store_result(S->H->server); |
if (res) { |
if (res) { |
mysql_free_result(res); |
mysql_free_result(res); |
Line 134 static int pdo_mysql_fill_stmt_from_result(pdo_stmt_t
|
Line 134 static int pdo_mysql_fill_stmt_from_result(pdo_stmt_t
|
|
|
row_count = mysql_affected_rows(H->server); |
row_count = mysql_affected_rows(H->server); |
if (row_count == (my_ulonglong)-1) { |
if (row_count == (my_ulonglong)-1) { |
/* we either have a query that returned a result set or an error occured | /* we either have a query that returned a result set or an error occurred |
lets see if we have access to a result set */ |
lets see if we have access to a result set */ |
if (!H->buffered) { |
if (!H->buffered) { |
S->result = mysql_use_result(H->server); |
S->result = mysql_use_result(H->server); |
Line 180 static int pdo_mysql_stmt_execute_prepared_libmysql(pd
|
Line 180 static int pdo_mysql_stmt_execute_prepared_libmysql(pd
|
} |
} |
|
|
if (!S->result) { |
if (!S->result) { |
int i; | int i; |
|
|
/* figure out the result set format, if any */ | /* figure out the result set format, if any */ |
S->result = mysql_stmt_result_metadata(S->stmt); | S->result = mysql_stmt_result_metadata(S->stmt); |
if (S->result) { | if (S->result) { |
int calc_max_length = H->buffered && S->max_length == 1; | int calc_max_length = H->buffered && S->max_length == 1; |
S->fields = mysql_fetch_fields(S->result); | S->fields = mysql_fetch_fields(S->result); |
if (S->bound_result) { | if (S->bound_result) { |
int i; | int i; |
for (i = 0; i < stmt->column_count; i++) { | for (i = 0; i < stmt->column_count; i++) { |
efree(S->bound_result[i].buffer); | efree(S->bound_result[i].buffer); |
} | } |
efree(S->bound_result); | efree(S->bound_result); |
efree(S->out_null); | efree(S->out_null); |
efree(S->out_length); | efree(S->out_length); |
} |
} |
| |
stmt->column_count = (int)mysql_num_fields(S->result); |
stmt->column_count = (int)mysql_num_fields(S->result); |
S->bound_result = ecalloc(stmt->column_count, sizeof(MYSQL_BIND)); |
S->bound_result = ecalloc(stmt->column_count, sizeof(MYSQL_BIND)); |
S->out_null = ecalloc(stmt->column_count, sizeof(my_bool)); |
S->out_null = ecalloc(stmt->column_count, sizeof(my_bool)); |
Line 262 static int pdo_mysql_stmt_execute_prepared_libmysql(pd
|
Line 262 static int pdo_mysql_stmt_execute_prepared_libmysql(pd
|
} |
} |
} |
} |
} |
} |
| |
pdo_mysql_stmt_set_row_count(stmt TSRMLS_CC); |
pdo_mysql_stmt_set_row_count(stmt TSRMLS_CC); |
PDO_DBG_RETURN(1); |
PDO_DBG_RETURN(1); |
} |
} |
Line 275 static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo
|
Line 275 static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo
|
pdo_mysql_stmt *S = stmt->driver_data; |
pdo_mysql_stmt *S = stmt->driver_data; |
pdo_mysql_db_handle *H = S->H; |
pdo_mysql_db_handle *H = S->H; |
int i; |
int i; |
| |
PDO_DBG_ENTER("pdo_mysql_stmt_execute_prepared_mysqlnd"); |
PDO_DBG_ENTER("pdo_mysql_stmt_execute_prepared_mysqlnd"); |
| |
if (mysql_stmt_execute(S->stmt)) { |
if (mysql_stmt_execute(S->stmt)) { |
pdo_mysql_error_stmt(stmt); |
pdo_mysql_error_stmt(stmt); |
PDO_DBG_RETURN(0); |
PDO_DBG_RETURN(0); |
Line 305 static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo
|
Line 305 static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo
|
} |
} |
} |
} |
} |
} |
| |
pdo_mysql_stmt_set_row_count(stmt TSRMLS_CC); |
pdo_mysql_stmt_set_row_count(stmt TSRMLS_CC); |
PDO_DBG_RETURN(1); |
PDO_DBG_RETURN(1); |
} |
} |
Line 322 static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt TSR
|
Line 322 static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt TSR
|
if (S->stmt) { |
if (S->stmt) { |
PDO_DBG_RETURN(pdo_mysql_stmt_execute_prepared(stmt)); |
PDO_DBG_RETURN(pdo_mysql_stmt_execute_prepared(stmt)); |
} |
} |
| |
/* ensure that we free any previous unfetched results */ |
/* ensure that we free any previous unfetched results */ |
if (S->result) { |
if (S->result) { |
mysql_free_result(S->result); |
mysql_free_result(S->result); |
Line 343 static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt
|
Line 343 static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt
|
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data; |
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data; |
pdo_mysql_db_handle *H = S->H; |
pdo_mysql_db_handle *H = S->H; |
long row_count; |
long row_count; |
int ret; |
|
PDO_DBG_ENTER("pdo_mysql_stmt_next_rowset"); |
PDO_DBG_ENTER("pdo_mysql_stmt_next_rowset"); |
PDO_DBG_INF_FMT("stmt=%p", S->stmt); |
PDO_DBG_INF_FMT("stmt=%p", S->stmt); |
|
|
Line 357 static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt
|
Line 356 static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt
|
} |
} |
|
|
if (!mysqlnd_stmt_more_results(S->stmt)) { |
if (!mysqlnd_stmt_more_results(S->stmt)) { |
/* | /* |
MySQL gives us n + 1 result sets for | MySQL gives us n + 1 result sets for |
CALL proc() and n result sets returned by the proc itself. |
CALL proc() and n result sets returned by the proc itself. |
Result set n + 1 is about the procedure call itself. |
Result set n + 1 is about the procedure call itself. |
As the PDO emulation does not return it, we skip it as well |
As the PDO emulation does not return it, we skip it as well |
Line 412 static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt
|
Line 411 static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt
|
S->result = NULL; |
S->result = NULL; |
} |
} |
|
|
ret = mysql_next_result(H->server); | if (!mysql_more_results(H->server)) { |
| /* No more results */ |
if (ret > 0) { | PDO_DBG_RETURN(0); |
| } |
| #if PDO_USE_MYSQLND |
| if (mysql_next_result(H->server) == FAIL) { |
pdo_mysql_error_stmt(stmt); |
pdo_mysql_error_stmt(stmt); |
PDO_DBG_RETURN(0); |
PDO_DBG_RETURN(0); |
} else if (ret < 0) { | } else { |
/* No more results */ | PDO_DBG_RETURN(pdo_mysql_fill_stmt_from_result(stmt TSRMLS_CC)); |
| } |
| #else |
| if (mysql_next_result(H->server) > 0) { |
| pdo_mysql_error_stmt(stmt); |
PDO_DBG_RETURN(0); |
PDO_DBG_RETURN(0); |
} else { |
} else { |
PDO_DBG_RETURN(pdo_mysql_fill_stmt_from_result(stmt TSRMLS_CC)); |
PDO_DBG_RETURN(pdo_mysql_fill_stmt_from_result(stmt TSRMLS_CC)); |
} |
} |
|
#endif |
} |
} |
/* }}} */ |
/* }}} */ |
|
|
Line 444 static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt,
|
Line 451 static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt,
|
#ifndef PDO_USE_MYSQLND |
#ifndef PDO_USE_MYSQLND |
PDO_MYSQL_PARAM_BIND *b; |
PDO_MYSQL_PARAM_BIND *b; |
#endif |
#endif |
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data; | pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data; |
|
|
PDO_DBG_ENTER("pdo_mysql_stmt_param_hook"); |
PDO_DBG_ENTER("pdo_mysql_stmt_param_hook"); |
PDO_DBG_INF_FMT("stmt=%p", S->stmt); |
PDO_DBG_INF_FMT("stmt=%p", S->stmt); |
Line 484 static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt,
|
Line 491 static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt,
|
} |
} |
#else |
#else |
b = (PDO_MYSQL_PARAM_BIND*)param->driver_data; |
b = (PDO_MYSQL_PARAM_BIND*)param->driver_data; |
*b->is_null = 0; | *b->is_null = 0; |
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_NULL || | if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_NULL || |
Z_TYPE_P(param->parameter) == IS_NULL) { | Z_TYPE_P(param->parameter) == IS_NULL) { |
*b->is_null = 1; | *b->is_null = 1; |
b->buffer_type = MYSQL_TYPE_STRING; | b->buffer_type = MYSQL_TYPE_STRING; |
b->buffer = NULL; | b->buffer = NULL; |
b->buffer_length = 0; | b->buffer_length = 0; |
*b->length = 0; | *b->length = 0; |
PDO_DBG_RETURN(1); |
PDO_DBG_RETURN(1); |
} | } |
#endif /* PDO_USE_MYSQLND */ |
#endif /* PDO_USE_MYSQLND */ |
| |
switch (PDO_PARAM_TYPE(param->param_type)) { |
switch (PDO_PARAM_TYPE(param->param_type)) { |
case PDO_PARAM_STMT: |
case PDO_PARAM_STMT: |
PDO_DBG_RETURN(0); |
PDO_DBG_RETURN(0); |
Line 519 static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt,
|
Line 526 static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt,
|
default: |
default: |
; |
; |
} |
} |
| |
#if PDO_USE_MYSQLND |
#if PDO_USE_MYSQLND |
/* Is it really correct to check the zval's type? - But well, that's what the old code below does, too */ |
/* Is it really correct to check the zval's type? - But well, that's what the old code below does, too */ |
PDO_DBG_INF_FMT("param->parameter->type=%d", Z_TYPE_P(param->parameter)); |
PDO_DBG_INF_FMT("param->parameter->type=%d", Z_TYPE_P(param->parameter)); |
Line 540 static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt,
|
Line 547 static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt,
|
default: |
default: |
PDO_DBG_RETURN(0); |
PDO_DBG_RETURN(0); |
} |
} |
| |
PDO_DBG_RETURN(1); |
PDO_DBG_RETURN(1); |
#else | #else |
PDO_DBG_INF_FMT("param->parameter->type=%d", Z_TYPE_P(param->parameter)); |
PDO_DBG_INF_FMT("param->parameter->type=%d", Z_TYPE_P(param->parameter)); |
switch (Z_TYPE_P(param->parameter)) { |
switch (Z_TYPE_P(param->parameter)) { |
case IS_STRING: |
case IS_STRING: |
Line 597 static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum
|
Line 604 static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum
|
} |
} |
#else |
#else |
int ret; |
int ret; |
| |
if (S->stmt) { |
if (S->stmt) { |
ret = mysql_stmt_fetch(S->stmt); |
ret = mysql_stmt_fetch(S->stmt); |
|
|
Line 617 static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum
|
Line 624 static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum
|
PDO_DBG_RETURN(1); |
PDO_DBG_RETURN(1); |
} |
} |
#endif /* PDO_USE_MYSQLND */ |
#endif /* PDO_USE_MYSQLND */ |
| |
if (!S->result) { |
if (!S->result) { |
strcpy(stmt->error_code, "HY000"); |
strcpy(stmt->error_code, "HY000"); |
PDO_DBG_RETURN(0); |
PDO_DBG_RETURN(0); |
Line 637 static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum
|
Line 644 static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum
|
pdo_mysql_error_stmt(stmt); |
pdo_mysql_error_stmt(stmt); |
} |
} |
PDO_DBG_RETURN(0); |
PDO_DBG_RETURN(0); |
} | } |
|
|
S->current_lengths = mysql_fetch_lengths(S->result); |
S->current_lengths = mysql_fetch_lengths(S->result); |
PDO_DBG_RETURN(1); |
PDO_DBG_RETURN(1); |
Line 661 static int pdo_mysql_stmt_describe(pdo_stmt_t *stmt, i
|
Line 668 static int pdo_mysql_stmt_describe(pdo_stmt_t *stmt, i
|
PDO_DBG_RETURN(0); |
PDO_DBG_RETURN(0); |
} |
} |
|
|
/* fetch all on demand, this seems easiest | /* fetch all on demand, this seems easiest |
** if we've been here before bail out | ** if we've been here before bail out |
*/ |
*/ |
if (cols[0].name) { |
if (cols[0].name) { |
PDO_DBG_RETURN(1); |
PDO_DBG_RETURN(1); |
Line 678 static int pdo_mysql_stmt_describe(pdo_stmt_t *stmt, i
|
Line 685 static int pdo_mysql_stmt_describe(pdo_stmt_t *stmt, i
|
cols[i].namelen = namelen; |
cols[i].namelen = namelen; |
cols[i].name = estrndup(S->fields[i].name, namelen); |
cols[i].name = estrndup(S->fields[i].name, namelen); |
} |
} |
| |
cols[i].precision = S->fields[i].decimals; |
cols[i].precision = S->fields[i].decimals; |
cols[i].maxlen = S->fields[i].length; |
cols[i].maxlen = S->fields[i].length; |
| |
#ifdef PDO_USE_MYSQLND |
#ifdef PDO_USE_MYSQLND |
if (S->stmt) { |
if (S->stmt) { |
cols[i].param_type = PDO_PARAM_ZVAL; |
cols[i].param_type = PDO_PARAM_ZVAL; |
Line 754 static char *type_to_name_native(int type) /* {{{ */
|
Line 761 static char *type_to_name_native(int type) /* {{{ */
|
switch (type) { |
switch (type) { |
PDO_MYSQL_NATIVE_TYPE_NAME(STRING) |
PDO_MYSQL_NATIVE_TYPE_NAME(STRING) |
PDO_MYSQL_NATIVE_TYPE_NAME(VAR_STRING) |
PDO_MYSQL_NATIVE_TYPE_NAME(VAR_STRING) |
#ifdef MYSQL_HAS_TINY | #ifdef FIELD_TYPE_TINY |
PDO_MYSQL_NATIVE_TYPE_NAME(TINY) |
PDO_MYSQL_NATIVE_TYPE_NAME(TINY) |
#endif |
#endif |
|
#ifdef FIELD_TYPE_BIT |
|
PDO_MYSQL_NATIVE_TYPE_NAME(BIT) |
|
#endif |
PDO_MYSQL_NATIVE_TYPE_NAME(SHORT) |
PDO_MYSQL_NATIVE_TYPE_NAME(SHORT) |
PDO_MYSQL_NATIVE_TYPE_NAME(LONG) |
PDO_MYSQL_NATIVE_TYPE_NAME(LONG) |
PDO_MYSQL_NATIVE_TYPE_NAME(LONGLONG) |
PDO_MYSQL_NATIVE_TYPE_NAME(LONGLONG) |
Line 771 static char *type_to_name_native(int type) /* {{{ */
|
Line 781 static char *type_to_name_native(int type) /* {{{ */
|
PDO_MYSQL_NATIVE_TYPE_NAME(GEOMETRY) |
PDO_MYSQL_NATIVE_TYPE_NAME(GEOMETRY) |
#endif |
#endif |
PDO_MYSQL_NATIVE_TYPE_NAME(TIMESTAMP) |
PDO_MYSQL_NATIVE_TYPE_NAME(TIMESTAMP) |
#ifdef MYSQL_HAS_YEAR | #ifdef FIELD_TYPE_YEAR |
PDO_MYSQL_NATIVE_TYPE_NAME(YEAR) |
PDO_MYSQL_NATIVE_TYPE_NAME(YEAR) |
#endif |
#endif |
PDO_MYSQL_NATIVE_TYPE_NAME(SET) |
PDO_MYSQL_NATIVE_TYPE_NAME(SET) |
Line 799 static int pdo_mysql_stmt_col_meta(pdo_stmt_t *stmt, l
|
Line 809 static int pdo_mysql_stmt_col_meta(pdo_stmt_t *stmt, l
|
const MYSQL_FIELD *F; |
const MYSQL_FIELD *F; |
zval *flags; |
zval *flags; |
char *str; |
char *str; |
| |
PDO_DBG_ENTER("pdo_mysql_stmt_col_meta"); |
PDO_DBG_ENTER("pdo_mysql_stmt_col_meta"); |
PDO_DBG_INF_FMT("stmt=%p", S->stmt); |
PDO_DBG_INF_FMT("stmt=%p", S->stmt); |
if (!S->result) { |
if (!S->result) { |
Line 857 static int pdo_mysql_stmt_col_meta(pdo_stmt_t *stmt, l
|
Line 867 static int pdo_mysql_stmt_col_meta(pdo_stmt_t *stmt, l
|
break; |
break; |
} |
} |
#endif |
#endif |
| |
add_assoc_zval(return_value, "flags", flags); |
add_assoc_zval(return_value, "flags", flags); |
add_assoc_string(return_value, "table", (char *) (F->table?F->table:""), 1); |
add_assoc_string(return_value, "table", (char *) (F->table?F->table:""), 1); |
PDO_DBG_RETURN(SUCCESS); |
PDO_DBG_RETURN(SUCCESS); |