PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/extra/update_pas_mysql_structures.php

http://heidisql.googlecode.com/
PHP | 146 lines | 125 code | 10 blank | 11 comment | 13 complexity | b3ac381bbb27cf87cae2bad665aeb0b9 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * This is a helper file for generating the MySQLFunctions Array
  4. * in /source/mysql.pas
  5. * Functions are fetched by using the HELP commands
  6. */
  7. // Gather version information for functions
  8. $ver_cont = file_get_contents('http://dev.mysql.com/doc/refman/6.0/en/func-op-summary-ref.html');
  9. if( $ver_cont )
  10. {
  11. // <code class="literal">ADDDATE()</code></a>(v4.1.1)
  12. $ver_cont = html_entity_decode($ver_cont);
  13. $matches = array();
  14. preg_match_all( '#\<a[^\>]+\>\<code class="literal"\>([^\(\s\<]+).*\<\/a\>\(v(.+)\)#', $ver_cont, $matches );
  15. $versions = array();
  16. for( $i=0; $i<count($matches[0]); $i++ )
  17. {
  18. $versionArr = explode( '.', $matches[2][$i] );
  19. // make int of array
  20. if( !isset($versionArr[1]) )
  21. $versionArr[1] = '0';
  22. if( !isset($versionArr[2]) )
  23. $versionArr[2] = '0';
  24. $version = sprintf('%d%02d%02d',
  25. $versionArr[0],
  26. $versionArr[1],
  27. $versionArr[2]
  28. );
  29. // functionname => version
  30. $versions[ $matches[1][$i] ] = $version;
  31. }
  32. }
  33. // Specify your own host, user, pass here.
  34. // Do NOT commit passwords into SVN!!
  35. mysql_connect( 'localhost', 'root' );
  36. $nl = "\r\n";
  37. $fnames = array();
  38. $fstruc = array();
  39. $q = mysql_query('HELP "functions"');
  40. while( $row = mysql_fetch_object($q) )
  41. {
  42. if( $row->is_it_category == 'Y' )
  43. {
  44. getfunctions($row->name);
  45. }
  46. }
  47. getfunctions('Functions and Modifiers for Use with GROUP BY');
  48. getfunctions('Geographic Features');
  49. function getfunctions( $cat, $rootcat='' )
  50. {
  51. global $nl, $fstruc, $fnames, $versions;
  52. $q = mysql_query('HELP "'.$cat.'"');
  53. while( $row = mysql_fetch_object($q) )
  54. {
  55. if( $row->is_it_category == 'Y' )
  56. {
  57. if( empty($rootcat) )
  58. {
  59. $rootcat = $cat;
  60. }
  61. getfunctions( $row->name, $rootcat );
  62. }
  63. else
  64. {
  65. $sql = "HELP '".$row->name."'";
  66. $qdetails = mysql_query($sql);
  67. $rowdetails = mysql_fetch_object($qdetails);
  68. if( preg_match('#(\S+)#', $rowdetails->name, $m1) )
  69. {
  70. $name = $m1[1];
  71. }
  72. else
  73. {
  74. $name = $row->name;
  75. }
  76. if( in_array($name,$fnames) )
  77. {
  78. continue;
  79. }
  80. $fnames[] = $name;
  81. $declaration = '';
  82. $desc_cut = substr($rowdetails->description, 0, strpos($rowdetails->description,"\n\n"));
  83. $df = preg_match('#(Syntax:)?[^\(]*(\([^\)]*\))#Us', $desc_cut, $m2);
  84. if( $df )
  85. {
  86. $declaration = $m2[2];
  87. $declaration = str_replace("'", "''", $declaration );
  88. }
  89. $description = '';
  90. $df = preg_match('#(Syntax:)?.*\n\n(.+)$#Uis', $rowdetails->description, $m3);
  91. if( $df )
  92. {
  93. $description = trim($m3[2]);
  94. $description = preg_replace('#\bURL\:\s+\S+#s', ' ', $description );
  95. $description = preg_replace('#(\s+)#', ' ', $description );
  96. $description = str_replace(' o ', ' ', $description);
  97. $description = str_replace("'", "''", $description );
  98. $description = trim($description );
  99. $description = wordwrap($description,70, " '".$nl." +'" );
  100. }
  101. $version = 'SQL_VERSION_ANSI';
  102. if( !empty($versions[$name]) )
  103. {
  104. $version = $versions[$name];
  105. }
  106. $fstruc[$name] = sprintf(" (".$nl
  107. ." Name: '%s';".$nl
  108. ." Declaration: '%s';".$nl
  109. ." Category: '%s';".$nl
  110. ." Version: %s;".$nl
  111. ." Description: '%s'".$nl
  112. ." ),".$nl.$nl,
  113. $name,
  114. $declaration,
  115. (!empty($rootcat) ? $rootcat : $cat),
  116. $version,
  117. $description
  118. );
  119. }
  120. }
  121. }
  122. // Sort alphabetically by function name
  123. asort($fstruc);
  124. // produce output
  125. $counter = 0;
  126. foreach( $fstruc as $func )
  127. {
  128. print ' // Function nr. '.++$counter.$nl;
  129. print $func;
  130. }
  131. ?>