sqlite3_openblob_wrongparams.phpt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. --TEST--
  2. SQLite3::blobOpen test, testing stream with wrong parameter count
  3. --CREDITS--
  4. Michelangelo van Dam
  5. # Belgian PHP Testfest 2009
  6. --SKIPIF--
  7. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  8. --FILE--
  9. <?php
  10. class SQLite3_Test_Stream
  11. {
  12. private $position;
  13. public static $string_length = 10;
  14. public static $string = "abcdefg\0hi";
  15. public function stream_open($path, $mode, $options, &$opened_path)
  16. {
  17. $this->position = 0;
  18. return true;
  19. }
  20. public function stream_read($count)
  21. {
  22. $ret = substr(self::$string, $this->position, $count);
  23. $this->position += strlen($ret);
  24. return $ret;
  25. }
  26. public function stream_write($data)
  27. {
  28. return 0;
  29. }
  30. public function stream_stat()
  31. {
  32. return array('size' => self::$string_length);
  33. }
  34. public function stream_tell()
  35. {
  36. return $this->position;
  37. }
  38. public function stream_eof()
  39. {
  40. return ($this->position >= self::$string_length);
  41. }
  42. }
  43. $db = new SQLite3(':memory:');
  44. stream_wrapper_register('sqliteBlobTest', "SQLite3_Test_Stream") or die("Unable to register sqliteBlobTest stream");
  45. echo "Creating table: " . var_export($db->exec('CREATE TABLE test (id STRING, data BLOB)'),true) . "\n";
  46. echo "PREPARING insert\n";
  47. $insert_stmt = $db->prepare("INSERT INTO test (id, data) VALUES (?, ?)");
  48. echo "BINDING Parameters:\n";
  49. var_dump($insert_stmt->bindValue(1, 'a', SQLITE3_TEXT));
  50. var_dump($insert_stmt->bindValue(2, 'TEST TEST', SQLITE3_BLOB));
  51. $insert_stmt->execute();
  52. echo "Closing statement: " . var_export($insert_stmt->close(), true) . "\n";
  53. echo "Open BLOB with wrong parameter count\n";
  54. $stream = $db->openBlob();
  55. var_dump($stream);
  56. echo "Done\n";
  57. ?>
  58. --EXPECTF--
  59. Creating table: true
  60. PREPARING insert
  61. BINDING Parameters:
  62. bool(true)
  63. bool(true)
  64. Closing statement: true
  65. Open BLOB with wrong parameter count
  66. Warning: SQLite3::openBlob() expects at least 3 parameters, 0 given in %s on line %d
  67. NULL
  68. Done