004.phpt 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. --TEST--
  2. InterBase: BLOB test
  3. --SKIPIF--
  4. <?php include("skipif.inc"); ?>
  5. --FILE--
  6. <?php
  7. require("interbase.inc");
  8. $link = ibase_connect($test_base);
  9. ibase_query(
  10. "CREATE TABLE test4 (
  11. v_integer integer,
  12. v_blob blob)");
  13. ibase_commit();
  14. /* create 100k blob file */
  15. $blob_str = rand_binstr(100*1024);
  16. $name = tempnam(dirname(__FILE__),"blob.tmp");
  17. $ftmp = fopen($name,"w");
  18. fwrite($ftmp,$blob_str);
  19. fclose($ftmp);
  20. echo "import blob 1\n";
  21. $ftmp = fopen($name,"r");
  22. $bl_s = ibase_blob_import($ftmp);
  23. ibase_query("INSERT INTO test4 (v_integer, v_blob) VALUES (1, ?)", $bl_s);
  24. $bl_s = ibase_blob_import($link,$ftmp);
  25. ibase_query($link, "INSERT INTO test4 (v_integer, v_blob) VALUES (1, ?)", $bl_s);
  26. fclose($ftmp);
  27. echo "test blob 1\n";
  28. $q = ibase_query("SELECT v_blob FROM test4 WHERE v_integer = 1");
  29. $row = ibase_fetch_object($q);
  30. $bl_h = ibase_blob_open($row->V_BLOB);
  31. $blob = '';
  32. while($piece = ibase_blob_get($bl_h, 1 + rand() % 1024))
  33. $blob .= $piece;
  34. if($blob != $blob_str)
  35. echo " BLOB 1 fail (1)\n";
  36. ibase_blob_close($bl_h);
  37. $bl_h = ibase_blob_open($link,$row->V_BLOB);
  38. $blob = '';
  39. while($piece = ibase_blob_get($bl_h, 100 * 1024))
  40. $blob .= $piece;
  41. if($blob != $blob_str)
  42. echo " BLOB 1 fail (2)\n";
  43. ibase_blob_close($bl_h);
  44. ibase_free_result($q);
  45. unset($blob);
  46. echo "create blob 2\n";
  47. ibase_query("INSERT INTO test4 (v_integer, v_blob) VALUES (2, ?)", $blob_str);
  48. echo "test blob 2\n";
  49. $q = ibase_query("SELECT v_blob FROM test4 WHERE v_integer = 2");
  50. $row = ibase_fetch_object($q,IBASE_TEXT);
  51. if($row->V_BLOB != $blob_str)
  52. echo " BLOB 2 fail\n";
  53. ibase_free_result($q);
  54. unset($blob);
  55. echo "create blob 3\n";
  56. $bl_h = ibase_blob_create($link);
  57. ibase_blob_add($bl_h, "+----------------------------------------------------------------------+\n");
  58. ibase_blob_add($bl_h, "| PHP HTML Embedded Scripting Language Version 3.0 |\n");
  59. ibase_blob_add($bl_h, "+----------------------------------------------------------------------+\n");
  60. ibase_blob_add($bl_h, "| Copyright (c) 1997-2000 PHP Development Team (See Credits file) |\n");
  61. ibase_blob_add($bl_h, "+----------------------------------------------------------------------+\n");
  62. ibase_blob_add($bl_h, "| This program is free software; you can redistribute it and/or modify |\n");
  63. ibase_blob_add($bl_h, "| it under the terms of one of the following licenses: |\n");
  64. ibase_blob_add($bl_h, "| |\n");
  65. ibase_blob_add($bl_h, "| A) the GNU General Public License as published by the Free Software |\n");
  66. ibase_blob_add($bl_h, "| Foundation; either version 2 of the License, or (at your option) |\n");
  67. ibase_blob_add($bl_h, "| any later version. |\n");
  68. ibase_blob_add($bl_h, "| |\n");
  69. ibase_blob_add($bl_h, "| B) the PHP License as published by the PHP Development Team and |\n");
  70. ibase_blob_add($bl_h, "| included in the distribution in the file: LICENSE |\n");
  71. ibase_blob_add($bl_h, "| |\n");
  72. ibase_blob_add($bl_h, "| This program is distributed in the hope that it will be useful, |\n");
  73. ibase_blob_add($bl_h, "| but WITHOUT ANY WARRANTY; without even the implied warranty of |\n");
  74. ibase_blob_add($bl_h, "| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |\n");
  75. ibase_blob_add($bl_h, "| GNU General Public License for more details. |\n");
  76. ibase_blob_add($bl_h, "| |\n");
  77. ibase_blob_add($bl_h, "| You should have received a copy of both licenses referred to here. |\n");
  78. ibase_blob_add($bl_h, "| If you did not, or have any questions about PHP licensing, please |\n");
  79. ibase_blob_add($bl_h, "| contact core@php.net. |\n");
  80. ibase_blob_add($bl_h, "+----------------------------------------------------------------------+\n");
  81. $bl_s = ibase_blob_close($bl_h);
  82. ibase_query("INSERT INTO test4 (v_integer, v_blob) VALUES (3, ?)", $bl_s);
  83. ibase_commit();
  84. echo "echo blob 3\n";
  85. $q = ibase_query("SELECT v_blob FROM test4 WHERE v_integer = 3");
  86. $row = ibase_fetch_object($q);
  87. ibase_commit();
  88. ibase_close();
  89. $link = ibase_connect($test_base);
  90. ibase_blob_echo($link, $row->V_BLOB);
  91. ibase_free_result($q);
  92. echo "fetch blob 3\n";
  93. $q = ibase_query("SELECT v_blob FROM test4 WHERE v_integer = 3");
  94. $row = ibase_fetch_object($q,IBASE_TEXT);
  95. echo $row->V_BLOB;
  96. ibase_free_result($q);
  97. ibase_close();
  98. unlink($name);
  99. echo "end of test\n";
  100. ?>
  101. --EXPECT--
  102. import blob 1
  103. test blob 1
  104. create blob 2
  105. test blob 2
  106. create blob 3
  107. echo blob 3
  108. +----------------------------------------------------------------------+
  109. | PHP HTML Embedded Scripting Language Version 3.0 |
  110. +----------------------------------------------------------------------+
  111. | Copyright (c) 1997-2000 PHP Development Team (See Credits file) |
  112. +----------------------------------------------------------------------+
  113. | This program is free software; you can redistribute it and/or modify |
  114. | it under the terms of one of the following licenses: |
  115. | |
  116. | A) the GNU General Public License as published by the Free Software |
  117. | Foundation; either version 2 of the License, or (at your option) |
  118. | any later version. |
  119. | |
  120. | B) the PHP License as published by the PHP Development Team and |
  121. | included in the distribution in the file: LICENSE |
  122. | |
  123. | This program is distributed in the hope that it will be useful, |
  124. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  125. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  126. | GNU General Public License for more details. |
  127. | |
  128. | You should have received a copy of both licenses referred to here. |
  129. | If you did not, or have any questions about PHP licensing, please |
  130. | contact core@php.net. |
  131. +----------------------------------------------------------------------+
  132. fetch blob 3
  133. +----------------------------------------------------------------------+
  134. | PHP HTML Embedded Scripting Language Version 3.0 |
  135. +----------------------------------------------------------------------+
  136. | Copyright (c) 1997-2000 PHP Development Team (See Credits file) |
  137. +----------------------------------------------------------------------+
  138. | This program is free software; you can redistribute it and/or modify |
  139. | it under the terms of one of the following licenses: |
  140. | |
  141. | A) the GNU General Public License as published by the Free Software |
  142. | Foundation; either version 2 of the License, or (at your option) |
  143. | any later version. |
  144. | |
  145. | B) the PHP License as published by the PHP Development Team and |
  146. | included in the distribution in the file: LICENSE |
  147. | |
  148. | This program is distributed in the hope that it will be useful, |
  149. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  150. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  151. | GNU General Public License for more details. |
  152. | |
  153. | You should have received a copy of both licenses referred to here. |
  154. | If you did not, or have any questions about PHP licensing, please |
  155. | contact core@php.net. |
  156. +----------------------------------------------------------------------+
  157. end of test