PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/mysql/tests/mysql_field_flags.php

http://github.com/facebook/hiphop-php
PHP | 137 lines | 115 code | 21 blank | 1 comment | 21 complexity | dd7c136b33577a935037b3d66de3ac79 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. include "connect.inc";
  3. $tmp = NULL;
  4. $link = NULL;
  5. if (!is_null($tmp = @mysql_field_flags()))
  6. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  7. if (null !== ($tmp = @mysql_field_flags($link)))
  8. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  9. require('table.inc');
  10. if (!$res = mysql_query("SELECT id, label FROM test ORDER BY id LIMIT 2", $link)) {
  11. printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
  12. }
  13. if (NULL !== ($tmp = mysql_field_flags($res)))
  14. printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  15. if (false !== ($tmp = mysql_field_flags($res, -1)))
  16. printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  17. if (!is_string($tmp = mysql_field_flags($res, 0)) || empty($tmp))
  18. printf("[006] Expecting non empty string, got %s/%s\n", gettype($tmp), $tmp);
  19. if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp)) {
  20. printf("[007] Check the unicode support!\n");
  21. var_inspect($tmp);
  22. }
  23. if (false !== ($tmp = mysql_field_flags($res, 2)))
  24. printf("[008] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  25. mysql_free_result($res);
  26. $version = mysql_get_server_info($link);
  27. if (!preg_match('@(\d+)\.(\d+)\.(\d+)@ism', $version, $matches))
  28. printf("[009] Cannot get server version\n");
  29. $version = ($matches[1] * 1000) + ($matches[2] * 100) + $matches[3];
  30. $tables = array(
  31. 'label INT, UNIQUE KEY (label)' => array(
  32. array('label', '1'),
  33. 'label' => array(($version < 5000) ? 'multiple_key' : 'unique_key')
  34. ),
  35. 'labela INT, label2 CHAR(1), KEY keyname (labela, label2)' => array(
  36. array('labela, label2', "1, 'a'"),
  37. 'labela' => array('multiple_key'),
  38. ),
  39. 'label1 BLOB' => array(
  40. array('label1', "'blob'"),
  41. 'label1' => array('blob', 'binary'),
  42. ),
  43. 'label1 INT UNSIGNED' => array(
  44. array('label1', '100'),
  45. 'label1' => array('unsigned'),
  46. ),
  47. 'label1 INT UNSIGNED NOT NULL AUTO INCREMENT' => array(
  48. array('label1', '100'),
  49. 'label1' => array('auto_increment',
  50. 'unsigned'),
  51. ),
  52. 'label1 ENUM("a", "b")' => array(
  53. array('label1', "'a'"),
  54. 'label1' => array('enum'),
  55. ),
  56. 'label1 SET("a", "b")' => array(
  57. array('label1', "'a'"),
  58. 'label1' => array('set'),
  59. ),
  60. 'label1 TIMESTAMP' => array(
  61. array('label1', sprintf("'%s'", @date("Y-m-d H:i:s"))),
  62. 'label1' => array(
  63. 'timestamp',
  64. 'binary',
  65. 'not_null'),
  66. ),
  67. );
  68. if ($version < 5600) {
  69. $tables['label1 TIMESTAMP']['label1'][] = 'zerofill';
  70. $tables['label1 TIMESTAMP']['label1'][] = 'unsigned';
  71. }
  72. foreach ($tables as $columns => $expected) {
  73. if (!mysql_query("DROP TABLE IF EXISTS test", $link)) {
  74. printf("[010/%s] [%d] %s\n", $columns, mysql_errno($link), mysql_error($link));
  75. continue;
  76. }
  77. $sql = sprintf("CREATE TABLE test(id INT, %s) ENGINE = %s", $columns, $engine);
  78. if (!@mysql_query($sql, $link)) {
  79. // server or engine might not support this
  80. continue;
  81. }
  82. reset($expected);
  83. list($k, $values) = each($expected);
  84. $sql = sprintf("INSERT INTO test(id, %s) VALUES (1, %s)", $values[0], $values[1]);
  85. if (!mysql_query($sql, $link)) {
  86. printf("[011/%s] '%s', [%d] %s\n", $columns, $sql, mysql_errno($link), mysql_error($link));
  87. continue;
  88. }
  89. if (!$res = mysql_query(sprintf("SELECT id, %s FROM test", $values[0]), $link)) {
  90. printf("[012/%s] [%d] %s\n", $columns, mysql_errno($link), mysql_error($link));
  91. continue;
  92. }
  93. $i = 1;
  94. while (list($field, $flags) = each($expected)) {
  95. $tmp = mysql_field_flags($res, $i++);
  96. foreach ($flags as $k => $flag) {
  97. if (!preg_match(sprintf('@\s*%s\s*@ismU', $flag), $tmp)) {
  98. printf("[013/%s] Field '%s', flag '%s' not found, [%d] %s\n", $columns, $field, $flag, mysql_errno($link), mysql_error($link));
  99. }
  100. }
  101. foreach ($flags as $k => $flag) {
  102. $tmp = preg_replace(sprintf('@\s*%s\s*@ismU', $flag), '', $tmp);
  103. }
  104. if ('' != $tmp)
  105. printf("[014/%s] Field '%s', unexpected flags '%s' found, [%d] %s\n", $columns, $field, $tmp, mysql_errno($link), mysql_error($link));
  106. }
  107. mysql_free_result($res);
  108. }
  109. var_dump(mysql_field_flags($res, 0));
  110. mysql_close($link);
  111. print "done!";
  112. ?>
  113. <?php error_reporting(0); ?>
  114. <?php
  115. require_once("clean_table.inc");
  116. ?>