2005-01-07 22:59:59 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| PHP Version 5 |
|
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
| Copyright (c) 1997-2006 The PHP Group |
|
2005-01-07 22:59:59 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2005-01-07 22:59:59 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 20:51:34 +08:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
2005-01-07 22:59:59 +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. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Author: Georg Richter <georg@php.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "php_ini.h"
|
|
|
|
#include "ext/standard/info.h"
|
|
|
|
#include "php_mysqli.h"
|
|
|
|
|
|
|
|
/* {{{ void php_clear_warnings() */
|
|
|
|
void php_clear_warnings(MYSQLI_WARNING *w)
|
|
|
|
{
|
2005-06-22 17:12:43 +08:00
|
|
|
MYSQLI_WARNING *n;
|
|
|
|
|
|
|
|
while (w) {
|
|
|
|
n = w;
|
|
|
|
efree(w->reason);
|
|
|
|
w = w->next;
|
|
|
|
efree(n);
|
|
|
|
}
|
2005-01-07 22:59:59 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
/* {{{ MYSQLI_WARNING *php_new_warning */
|
|
|
|
MYSQLI_WARNING *php_new_warning(char *reason, char *sqlstate, int errorno)
|
2005-01-07 22:59:59 +08:00
|
|
|
{
|
2005-06-22 17:12:43 +08:00
|
|
|
MYSQLI_WARNING *w;
|
2005-01-07 22:59:59 +08:00
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
w = (MYSQLI_WARNING *)ecalloc(1, sizeof(MYSQLI_WARNING));
|
2005-01-07 22:59:59 +08:00
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
w->reason = safe_estrdup(reason);
|
|
|
|
if (sqlstate) {
|
|
|
|
strcpy(w->sqlstate, sqlstate);
|
|
|
|
} else {
|
|
|
|
strcpy(w->sqlstate, "00000");
|
2005-01-07 22:59:59 +08:00
|
|
|
}
|
2005-06-22 17:12:43 +08:00
|
|
|
w->errorno = errorno;
|
2005-01-07 22:59:59 +08:00
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
/* {{{ MYSQLI_WARNING *php_get_warnings(MYSQL *mysql) */
|
|
|
|
MYSQLI_WARNING *php_get_warnings(MYSQL *mysql)
|
2005-01-07 22:59:59 +08:00
|
|
|
{
|
2005-06-22 17:12:43 +08:00
|
|
|
MYSQLI_WARNING *w, *first = NULL, *prev = NULL;
|
|
|
|
MYSQL_RES *result;
|
|
|
|
MYSQL_ROW row;
|
2005-01-07 22:59:59 +08:00
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
if (mysql_query(mysql, "SHOW WARNINGS")) {
|
|
|
|
return NULL;
|
2005-01-07 22:59:59 +08:00
|
|
|
}
|
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
result = mysql_store_result(mysql);
|
|
|
|
while ((row = mysql_fetch_row(result))) {
|
|
|
|
w = php_new_warning(row[2], "HY000", atoi(row[1]));
|
|
|
|
if (!first) {
|
|
|
|
first = w;
|
|
|
|
}
|
|
|
|
if (prev) {
|
|
|
|
prev->next = (void *)w;
|
|
|
|
}
|
|
|
|
prev = w;
|
2005-01-07 22:59:59 +08:00
|
|
|
}
|
2005-06-22 17:12:43 +08:00
|
|
|
mysql_free_result(result);
|
|
|
|
return first;
|
2005-01-07 22:59:59 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
/* {{{ bool mysqli_warning::next() */
|
|
|
|
PHP_METHOD(mysqli_warning, next)
|
|
|
|
{
|
2005-01-07 22:59:59 +08:00
|
|
|
MYSQLI_WARNING *w;
|
2005-06-22 17:12:43 +08:00
|
|
|
zval *mysqli_warning;
|
2005-01-07 22:59:59 +08:00
|
|
|
mysqli_object *obj = (mysqli_object *)zend_objects_get_address(getThis() TSRMLS_CC);
|
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
if (obj->ptr) {
|
2005-01-07 22:59:59 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
|
2005-06-22 17:12:43 +08:00
|
|
|
&mysqli_warning, mysqli_warning_class_entry) == FAILURE) {
|
2005-01-07 22:59:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(w, MYSQLI_WARNING *, &mysqli_warning, "mysqli_warning");
|
2005-01-07 22:59:59 +08:00
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
if (w->next) {
|
|
|
|
w = w->next;
|
|
|
|
((MYSQLI_RESOURCE *)(obj->ptr))->ptr = w;
|
2005-01-07 22:59:59 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
/* {{{ property mysqli_warning_message */
|
|
|
|
int mysqli_warning_message(mysqli_object *obj, zval **retval TSRMLS_DC)
|
2005-01-07 22:59:59 +08:00
|
|
|
{
|
|
|
|
MYSQLI_WARNING *w;
|
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
2005-01-07 22:59:59 +08:00
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
w = (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
|
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
if (w->reason) {
|
|
|
|
ZVAL_STRING(*retval, w->reason, 1);
|
2005-01-07 22:59:59 +08:00
|
|
|
} else {
|
|
|
|
ZVAL_NULL(*retval);
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
/* {{{ property mysqli_warning_sqlstate */
|
|
|
|
int mysqli_warning_sqlstate(mysqli_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
MYSQLI_WARNING *w;
|
|
|
|
|
|
|
|
if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
|
|
|
|
ALLOC_ZVAL(*retval);
|
|
|
|
ZVAL_STRING(*retval, w->sqlstate, 1);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-01-07 22:59:59 +08:00
|
|
|
/* {{{ property mysqli_warning_error */
|
|
|
|
int mysqli_warning_errno(mysqli_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
MYSQLI_WARNING *w;
|
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
w = (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
|
2005-01-07 22:59:59 +08:00
|
|
|
ALLOC_ZVAL(*retval);
|
2005-06-22 17:12:43 +08:00
|
|
|
ZVAL_LONG(*retval, w->errorno);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ mysqli_warning_construct(object obj) */
|
|
|
|
PHP_METHOD(mysqli_warning, __construct)
|
|
|
|
{
|
2005-10-11 04:03:00 +08:00
|
|
|
zval *z;
|
2005-06-22 17:12:43 +08:00
|
|
|
mysqli_object *obj;
|
|
|
|
MYSQL *hdl;
|
|
|
|
MYSQLI_WARNING *w;
|
|
|
|
MYSQLI_RESOURCE *mysqli_resource;
|
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() != 1) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2005-10-12 21:31:46 +08:00
|
|
|
if (zend_parse_parameters(1 TSRMLS_CC, "o", &z)==FAILURE) {
|
2005-06-22 17:12:43 +08:00
|
|
|
return;
|
|
|
|
}
|
2005-10-11 04:03:00 +08:00
|
|
|
obj = (mysqli_object *)zend_object_store_get_object(z TSRMLS_CC);\
|
2005-01-07 22:59:59 +08:00
|
|
|
|
2005-06-22 17:12:43 +08:00
|
|
|
if (obj->zo.ce == mysqli_link_class_entry) {
|
|
|
|
MY_MYSQL *mysql;
|
2005-10-11 04:03:00 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &z, "mysqli_link");
|
2005-06-22 17:12:43 +08:00
|
|
|
hdl = mysql->mysql;
|
|
|
|
} else if (obj->zo.ce == mysqli_stmt_class_entry) {
|
|
|
|
MY_STMT *stmt;
|
2005-10-11 04:03:00 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &z, "mysqli_stmt");
|
2005-06-22 17:12:43 +08:00
|
|
|
hdl = stmt->stmt->mysql;
|
2005-01-07 22:59:59 +08:00
|
|
|
} else {
|
2005-06-22 17:12:43 +08:00
|
|
|
RETURN_FALSE;
|
2005-01-07 22:59:59 +08:00
|
|
|
}
|
2005-06-22 17:12:43 +08:00
|
|
|
|
|
|
|
if (mysql_warning_count(hdl)) {
|
|
|
|
w = php_get_warnings(hdl);
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
|
|
|
|
mysqli_resource->ptr = mysqli_resource->info = (void *)w;
|
|
|
|
|
2005-10-10 20:57:55 +08:00
|
|
|
if (!getThis() || !instanceof_function(Z_OBJCE_P(getThis()), mysqli_warning_class_entry TSRMLS_CC)) {
|
|
|
|
MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_warning_class_entry);
|
2005-06-22 17:12:43 +08:00
|
|
|
} else {
|
|
|
|
((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
|
|
|
|
((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->valid = 1;
|
|
|
|
}
|
|
|
|
|
2005-01-07 22:59:59 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-12-06 09:40:06 +08:00
|
|
|
zend_function_entry mysqli_warning_methods[] = {
|
2005-06-22 17:12:43 +08:00
|
|
|
PHP_ME(mysqli_warning, __construct, NULL, ZEND_ACC_PROTECTED)
|
|
|
|
PHP_ME(mysqli_warning, next, NULL, ZEND_ACC_PUBLIC)
|
2005-01-07 22:59:59 +08:00
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
mysqli_property_entry mysqli_warning_property_entries[] = {
|
2005-06-22 17:12:43 +08:00
|
|
|
{"message", mysqli_warning_message, NULL},
|
|
|
|
{"sqlstate", mysqli_warning_sqlstate, NULL},
|
2005-01-07 22:59:59 +08:00
|
|
|
{"errno", mysqli_warning_errno, NULL},
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
2005-01-17 03:28:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
* vim600: noet sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: noet sw=4 ts=4
|
|
|
|
*/
|