com php-src: Change flags to use SQLITE3_OPEN_READ* con stants instead of a fake-boolean, add tests on errors: ext/sqlite3/sqlite3.c ext/sqlite3/test
s/sqlite3_30_blobopen.phpt

From: Date: Wed, 07 Jun 2017 23:25:00 +0000
Subject: com php-src: Change flags to use SQLITE3_OPEN_READ* con stants instead of a fake-boolean, add tests on errors: ext/sqlite3/sqlite3.c ext/sqlite3/test
s/sqlite3_30_blobopen.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-98099@lists.php.net to get a copy of this message
Commit: 626ee74ee8c45f22c096b6e5f6bfd9a032999333 Author: BohwaZ <bohwaz@github.com> Thu, 8 Jun 2017 11:25:00 +1200 Parents: 208aea1e85964cab59d5c54984278cbb87c71006 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=626ee74ee8c45f22c096b6e5f6bfd9a032999333 Log: Change flags to use SQLITE3_OPEN_READ* constants instead of a fake-boolean, add tests on errors Changed paths: M ext/sqlite3/sqlite3.c M ext/sqlite3/tests/sqlite3_30_blobopen.phpt Diff: diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 485c7bd..b56c238 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -1064,7 +1064,7 @@ static size_t php_sqlite3_stream_write(php_stream *stream, const char *buf, size { php_stream_sqlite3_data *sqlite3_stream = (php_stream_sqlite3_data *) stream->abstract; - if (sqlite3_stream->flags == 0) { + if (sqlite3_stream->flags & SQLITE_OPEN_READONLY) { php_error_docref(NULL, E_WARNING, "Can't write to blob stream: is open as read only"); return 0; } @@ -1221,7 +1221,7 @@ PHP_METHOD(sqlite3, openBlob) zval *object = getThis(); char *table, *column, *dbname = "main", *mode = "rb"; size_t table_len, column_len, dbname_len; - zend_long rowid, flags = 0; + zend_long rowid, flags = SQLITE_OPEN_READONLY, sqlite_flags = 0; sqlite3_blob *blob = NULL; php_stream_sqlite3_data *sqlite3_stream; php_stream *stream; @@ -1234,7 +1234,9 @@ PHP_METHOD(sqlite3, openBlob) return; } - if (sqlite3_blob_open(db_obj->db, dbname, table, column, rowid, flags, &blob) != SQLITE_OK) { + sqlite_flags = (flags & SQLITE_OPEN_READWRITE) ? 1 : 0; + + if (sqlite3_blob_open(db_obj->db, dbname, table, column, rowid, sqlite_flags, &blob) != SQLITE_OK) { php_sqlite3_error(db_obj, "Unable to open blob: %s", sqlite3_errmsg(db_obj->db)); RETURN_FALSE; } @@ -1245,7 +1247,7 @@ PHP_METHOD(sqlite3, openBlob) sqlite3_stream->position = 0; sqlite3_stream->size = sqlite3_blob_bytes(blob); - if (flags != 0) { + if (sqlite_flags != 0) { mode = "r+b"; } diff --git a/ext/sqlite3/tests/sqlite3_30_blobopen.phpt b/ext/sqlite3/tests/sqlite3_30_blobopen.phpt index b581abc..2e9a9f2 100644 --- a/ext/sqlite3/tests/sqlite3_30_blobopen.phpt +++ b/ext/sqlite3/tests/sqlite3_30_blobopen.phpt @@ -25,16 +25,20 @@ $stream = $db->openBlob('test', 'data', 1); var_dump($stream); echo "Stream Contents\n"; var_dump(stream_get_contents($stream)); +echo "Writing to read-only stream\n"; +var_dump(fwrite($stream, 'ABCD')); echo "Closing Stream\n"; var_dump(fclose($stream)); echo "Opening stream in write mode\n"; -$stream = $db->openBlob('test', 'data', 1, 'main', 1); +$stream = $db->openBlob('test', 'data', 1, 'main', SQLITE3_OPEN_READWRITE); var_dump($stream); echo "Writing to blob\n"; var_dump(fwrite($stream, 'ABCD')); echo "Stream Contents\n"; fseek($stream, 0); var_dump(stream_get_contents($stream)); +echo "Expanding blob size\n"; +var_dump(fwrite($stream, 'ABCD ABCD ABCD')); echo "Closing Stream\n"; var_dump(fclose($stream)); echo "Closing database\n"; @@ -53,6 +57,10 @@ bool(true) resource(%d) of type (stream) Stream Contents string(9) "TEST TEST" +Writing to read-only stream + +Warning: fwrite(): Can't write to blob stream: is open as read only in %s on line %d +int(0) Closing Stream bool(true) Opening stream in write mode @@ -61,6 +69,10 @@ Writing to blob int(4) Stream Contents string(9) "ABCD TEST" +Expanding blob size + +Warning: fwrite(): It is not possible to increase the size of a BLOB in %s on line %d +int(0) Closing Stream bool(true) Closing database

« previous php.cvs (#98099) next »