A lightweight forum engine written in PHP. Repository is now obsolete and read-only. http://www.pioder.pl/uforum.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.4 KiB

  1. <?php
  2. /**
  3. * @package uForum
  4. * @file includes/sql_parse.php
  5. * @version $Id$
  6. * @copyright 2009(c) PioDer <pioder@wp.pl>
  7. * @link http://pioder.gim2przemysl.int.pl/
  8. * @license GNU GPL v3
  9. * @note Originally, phpMyAdmin function
  10. **/
  11. function remove_comments(&$output)
  12. {
  13. $lines = explode("\n", $output);
  14. $output = "";
  15. $linecount = count($lines);
  16. $in_comment = false;
  17. for($i = 0; $i < $linecount; $i++)
  18. {
  19. if( preg_match("/^\/\*/", preg_quote($lines[$i])) )
  20. {
  21. $in_comment = true;
  22. }
  23. if( !$in_comment )
  24. {
  25. $output .= $lines[$i] . "\n";
  26. }
  27. if( preg_match("/\*\/$/", preg_quote($lines[$i])) )
  28. {
  29. $in_comment = false;
  30. }
  31. }
  32. unset($lines);
  33. return $output;
  34. }
  35. function remove_remarks($sql)
  36. {
  37. $lines = explode("\n", $sql);
  38. $sql = "";
  39. $linecount = count($lines);
  40. $output = "";
  41. for ($i = 0; $i < $linecount; $i++)
  42. {
  43. if (($i != ($linecount - 1)) || (strlen($lines[$i]) > 0))
  44. {
  45. if ($lines[$i][0] != "#")
  46. {
  47. $output .= $lines[$i] . "\n";
  48. }
  49. else
  50. {
  51. $output .= "\n";
  52. }
  53. $lines[$i] = "";
  54. }
  55. }
  56. return $output;
  57. }
  58. function split_sql_file($sql)
  59. {
  60. $delimiter = ';';
  61. $tokens = explode($delimiter, $sql);
  62. $sql = "";
  63. $output = array();
  64. $matches = array();
  65. $token_count = count($tokens);
  66. for ($i = 0; $i < $token_count; $i++)
  67. {
  68. if (($i != ($token_count - 1)) || (strlen($tokens[$i] > 0)))
  69. {
  70. $total_quotes = preg_match_all("/'/", $tokens[$i], $matches);
  71. $escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$i], $matches);
  72. $unescaped_quotes = $total_quotes - $escaped_quotes;
  73. if (($unescaped_quotes % 2) == 0)
  74. {
  75. $output[] = $tokens[$i];
  76. $tokens[$i] = "";
  77. }
  78. else
  79. {
  80. $temp = $tokens[$i] . $delimiter;
  81. $tokens[$i] = "";
  82. $complete_stmt = false;
  83. for ($j = $i + 1; (!$complete_stmt && ($j < $token_count)); $j++)
  84. {
  85. $total_quotes = preg_match_all("/'/", $tokens[$j], $matches);
  86. $escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$j], $matches);
  87. $unescaped_quotes = $total_quotes - $escaped_quotes;
  88. if (($unescaped_quotes % 2) == 1)
  89. {
  90. $output[] = $temp . $tokens[$j];
  91. $tokens[$j] = "";
  92. $temp = "";
  93. $complete_stmt = true;
  94. $i = $j;
  95. }
  96. else
  97. {
  98. $temp .= $tokens[$j] . $delimiter;
  99. $tokens[$j] = "";
  100. }
  101. }
  102. }
  103. }
  104. }
  105. return $output;
  106. }
  107. ?>