[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-cvs
Subject:    [PHP-CVS] =?utf-8?q?svn:_/php/php-src/_branches/PHP=5F5=5F3/NEWS_branches/PHP=5F5=5F3/ext/sqlite3/sq
From:       Scott_MacVicar <scottmac () php ! net>
Date:       2010-12-31 16:37:12
Message-ID: svn-scottmac-1293813432-306930-104368789 () svn ! php ! net
[Download RAW message or body]

scottmac                                 Fri, 31 Dec 2010 16:37:12 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=306930

Log:
Add SQLite3_Stmt::readOnly for checking if a statement is read only

Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c
    A   php/php-src/branches/PHP_5_3/ext/sqlite3/tests/sqlite3_35_stmt_readonly.phpt
    U   php/php-src/trunk/ext/sqlite3/sqlite3.c
    A   php/php-src/trunk/ext/sqlite3/tests/sqlite3_35_stmt_readonly.phpt


["svn-diffs-306930.txt" (text/x-diff)]

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS	2010-12-31 15:10:43 UTC (rev 306929)
+++ php/php-src/branches/PHP_5_3/NEWS	2010-12-31 16:37:12 UTC (rev 306930)
@@ -1,6 +1,6 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-?? ??? 20??, PHP 5.3.5
+?? ??? 2011, PHP 5.3.5
 - Upgraded bundled Sqlite3 to version 3.7.4. (Ilia)
 - Upgraded bundled PCRE to version 8.11. (Ilia)

@@ -79,8 +79,9 @@
   . Fixed bug #53515 (property_exists incorrect on ArrayObject null and 0
     values). (Felipe)

-- SQLite extension:
+- SQLite3 extension:
   . Fixed memory leaked introduced by the NULL poisoning patch (Mateusz Kocielski, \
Pierre) +  . Add SQlite3_Stmt::readonly() for checking if a statement is read only. \
(Scott)

 - Streams:
   . Implemented FR #26158 (open arbitrary file descriptor with fopen). (Gustavo)

Modified: php/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c	2010-12-31 15:10:43 UTC (rev \
                306929)
+++ php/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c	2010-12-31 16:37:12 UTC (rev \
306930) @@ -1081,10 +1081,9 @@

 static int php_sqlite3_stream_stat(php_stream *stream, php_stream_statbuf *ssb \
TSRMLS_DC)  {
-	/* TODO: fill in details based on Data: and Content-Length: headers, and/or data
-	 * from curl_easy_getinfo().
-	 * For now, return -1 to indicate that it doesn't make sense to stat this stream */
-	return -1;
+	php_stream_sqlite3_data *sqlite3_stream = (php_stream_sqlite3_data *) \
stream->abstract; +	ssb->sb.st_size = sqlite3_stream->size;
+	return 0;
 }

 static php_stream_ops php_stream_sqlite3_ops = {
@@ -1234,6 +1233,27 @@
 }
 /* }}} */

+/* {{{ proto bool SQLite3Stmt::readOnly()
+   Returns true if a statement is definitely read only */
+PHP_METHOD(sqlite3stmt, readOnly)
+{
+	php_sqlite3_stmt *stmt_obj;
+	zval *object = getThis();
+	stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
+
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
+	}
+
+#if SQLITE_VERSION_NUMBER >= 3007004
+	if (sqlite3_stmt_readonly(stmt_obj->stmt)) {
+		RETURN_TRUE;
+	}
+#endif
+	RETURN_FALSE;
+}
+/* }}} */
+
 static int register_bound_parameter_to_sqlite(struct php_sqlite3_bound_param *param, \
php_sqlite3_stmt *stmt TSRMLS_DC) /* {{{ */  {
 	HashTable *hash;
@@ -1804,6 +1824,7 @@
 	PHP_ME(sqlite3stmt, execute,	arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
 	PHP_ME(sqlite3stmt, bindParam,	arginfo_sqlite3stmt_bindparam, ZEND_ACC_PUBLIC)
 	PHP_ME(sqlite3stmt, bindValue,	arginfo_sqlite3stmt_bindvalue, ZEND_ACC_PUBLIC)
+	PHP_ME(sqlite3stmt, readOnly,	arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
 	PHP_ME(sqlite3stmt, __construct, arginfo_sqlite3stmt_construct, \
ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)  {NULL, NULL, NULL}
 };

Added: php/php-src/branches/PHP_5_3/ext/sqlite3/tests/sqlite3_35_stmt_readonly.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/sqlite3/tests/sqlite3_35_stmt_readonly.phpt	     \
                (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/sqlite3/tests/sqlite3_35_stmt_readonly.phpt	2010-12-31 \
16:37:12 UTC (rev 306930) @@ -0,0 +1,53 @@
+--TEST--
+SQLite3_stmt::readOnly check
+--SKIPIF--
+<?php require_once(dirname(__FILE__) . '/skipif.inc');
+$version = SQLite3::version();
+if ($version['versionNumber'] < 3007004) {
+  die("skip");
+}
+?>
+--FILE--
+<?php
+
+require_once(dirname(__FILE__) . '/new_db.inc');
+define('TIMENOW', time());
+
+echo "Creating Table\n";
+var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
+
+echo "INSERT into table\n";
+var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
+var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
+
+echo "Checking select statement\n";
+$stmt = $db->prepare("SELECT * FROM test WHERE id = ? ORDER BY id ASC");
+var_dump($stmt->readOnly());
+
+echo "Checking update statement\n";
+$stmt = $db->prepare("UPDATE test SET id = 'c' WHERE id = ?");
+var_dump($stmt->readOnly());
+
+echo "Checking delete statement\n";
+$stmt = $db->prepare("DELETE FROM test");
+var_dump($stmt->readOnly());
+
+echo "Closing database\n";
+var_dump($db->close());
+echo "Done\n";
+?>
+--EXPECTF--
+Creating Table
+bool(true)
+INSERT into table
+bool(true)
+bool(true)
+Checking select statement
+bool(true)
+Checking update statement
+bool(false)
+Checking delete statement
+bool(false)
+Closing database
+bool(true)
+Done

Modified: php/php-src/trunk/ext/sqlite3/sqlite3.c
===================================================================
--- php/php-src/trunk/ext/sqlite3/sqlite3.c	2010-12-31 15:10:43 UTC (rev 306929)
+++ php/php-src/trunk/ext/sqlite3/sqlite3.c	2010-12-31 16:37:12 UTC (rev 306930)
@@ -1078,10 +1078,9 @@

 static int php_sqlite3_stream_stat(php_stream *stream, php_stream_statbuf *ssb \
TSRMLS_DC)  {
-	/* TODO: fill in details based on Data: and Content-Length: headers, and/or data
-	 * from curl_easy_getinfo().
-	 * For now, return -1 to indicate that it doesn't make sense to stat this stream */
-	return -1;
+	php_stream_sqlite3_data *sqlite3_stream = (php_stream_sqlite3_data *) \
stream->abstract; +	ssb->sb.st_size = sqlite3_stream->size;
+	return 0;
 }

 static php_stream_ops php_stream_sqlite3_ops = {
@@ -1231,6 +1230,27 @@
 }
 /* }}} */

+/* {{{ proto bool SQLite3Stmt::readOnly()
+   Returns true if a statement is definitely read only */
+PHP_METHOD(sqlite3stmt, readOnly)
+{
+	php_sqlite3_stmt *stmt_obj;
+	zval *object = getThis();
+	stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object TSRMLS_CC);
+
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
+	}
+
+#if SQLITE_VERSION_NUMBER >= 3007004
+	if (sqlite3_stmt_readonly(stmt_obj->stmt)) {
+		RETURN_TRUE;
+	}
+#endif
+	RETURN_FALSE;
+}
+/* }}} */
+
 static int register_bound_parameter_to_sqlite(struct php_sqlite3_bound_param *param, \
php_sqlite3_stmt *stmt TSRMLS_DC) /* {{{ */  {
 	HashTable *hash;
@@ -1801,6 +1821,7 @@
 	PHP_ME(sqlite3stmt, execute,	arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
 	PHP_ME(sqlite3stmt, bindParam,	arginfo_sqlite3stmt_bindparam, ZEND_ACC_PUBLIC)
 	PHP_ME(sqlite3stmt, bindValue,	arginfo_sqlite3stmt_bindvalue, ZEND_ACC_PUBLIC)
+	PHP_ME(sqlite3stmt, readOnly,	arginfo_sqlite3_void, ZEND_ACC_PUBLIC)
 	PHP_ME(sqlite3stmt, __construct, arginfo_sqlite3stmt_construct, \
ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)  {NULL, NULL, NULL}
 };

Added: php/php-src/trunk/ext/sqlite3/tests/sqlite3_35_stmt_readonly.phpt
===================================================================
--- php/php-src/trunk/ext/sqlite3/tests/sqlite3_35_stmt_readonly.phpt	                \
                (rev 0)
+++ php/php-src/trunk/ext/sqlite3/tests/sqlite3_35_stmt_readonly.phpt	2010-12-31 \
16:37:12 UTC (rev 306930) @@ -0,0 +1,53 @@
+--TEST--
+SQLite3_stmt::readOnly check
+--SKIPIF--
+<?php require_once(dirname(__FILE__) . '/skipif.inc');
+$version = SQLite3::version();
+if ($version['versionNumber'] < 3007004) {
+  die("skip");
+}
+?>
+--FILE--
+<?php
+
+require_once(dirname(__FILE__) . '/new_db.inc');
+define('TIMENOW', time());
+
+echo "Creating Table\n";
+var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
+
+echo "INSERT into table\n";
+var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
+var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
+
+echo "Checking select statement\n";
+$stmt = $db->prepare("SELECT * FROM test WHERE id = ? ORDER BY id ASC");
+var_dump($stmt->readOnly());
+
+echo "Checking update statement\n";
+$stmt = $db->prepare("UPDATE test SET id = 'c' WHERE id = ?");
+var_dump($stmt->readOnly());
+
+echo "Checking delete statement\n";
+$stmt = $db->prepare("DELETE FROM test");
+var_dump($stmt->readOnly());
+
+echo "Closing database\n";
+var_dump($db->close());
+echo "Done\n";
+?>
+--EXPECTF--
+Creating Table
+bool(true)
+INSERT into table
+bool(true)
+bool(true)
+Checking select statement
+bool(true)
+Checking update statement
+bool(false)
+Checking delete statement
+bool(false)
+Closing database
+bool(true)
+Done



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic