test-pgblob.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. function getmicrotime()
  3. {
  4. $t = microtime();
  5. $t = explode(' ',$t);
  6. return (float)$t[1]+ (float)$t[0];
  7. }
  8. function doloop()
  9. {
  10. global $db,$MAX;
  11. $sql = "select id,firstname,lastname from adoxyz where
  12. firstname not like ? and lastname not like ? and id=?";
  13. $offset = 0;
  14. /*$sql = "select * from juris9.employee join juris9.emp_perf_plan on epp_empkey = emp_id
  15. where emp_name not like ? and emp_name not like ? and emp_id=28000+?";
  16. $offset = 28000;*/
  17. for ($i=1; $i <= $MAX; $i++) {
  18. $db->Param(false);
  19. $x = (rand() % 10) + 1;
  20. $db->debug= ($i==1);
  21. $id = $db->GetOne($sql,
  22. array('Z%','Z%',$x));
  23. if($id != $offset+$x) {
  24. print "<p>Error at $x";
  25. break;
  26. }
  27. }
  28. }
  29. include_once('../adodb.inc.php');
  30. $db = NewADOConnection('postgres7');
  31. $db->PConnect('localhost','tester','test','test') || die("failed connection");
  32. $enc = "GIF89a%01%00%01%00%80%FF%00%C0%C0%C0%00%00%00%21%F9%04%01%00%00%00%00%2C%00%00%00%00%01%00%01%00%00%01%012%00%3Bt_clear.gif%0D";
  33. $val = rawurldecode($enc);
  34. $MAX = 1000;
  35. adodb_pr($db->ServerInfo());
  36. echo "<h4>Testing PREPARE/EXECUTE PLAN</h4>";
  37. $db->_bindInputArray = true; // requires postgresql 7.3+ and ability to modify database
  38. $t = getmicrotime();
  39. doloop();
  40. echo '<p>',$MAX,' times, with plan=',getmicrotime() - $t,'</p>';
  41. $db->_bindInputArray = false;
  42. $t = getmicrotime();
  43. doloop();
  44. echo '<p>',$MAX,' times, no plan=',getmicrotime() - $t,'</p>';
  45. echo "<h4>Testing UPDATEBLOB</h4>";
  46. $db->debug=1;
  47. ### TEST BEGINS
  48. $db->Execute("insert into photos (id,name) values(9999,'dot.gif')");
  49. $db->UpdateBlob('photos','photo',$val,'id=9999');
  50. $v = $db->GetOne('select photo from photos where id=9999');
  51. ### CLEANUP
  52. $db->Execute("delete from photos where id=9999");
  53. ### VALIDATION
  54. if ($v !== $val) echo "<b>*** ERROR: Inserted value does not match downloaded val<b>";
  55. else echo "<b>*** OK: Passed</b>";
  56. echo "<pre>";
  57. echo "INSERTED: ", $enc;
  58. echo "<hr />";
  59. echo"RETURNED: ", rawurlencode($v);
  60. echo "<hr /><p>";
  61. echo "INSERTED: ", $val;
  62. echo "<hr />";
  63. echo "RETURNED: ", $v;