Files
HeidiSQL/extra/generate_mysqlfunction_array.php
Ansgar Becker 69e1abbf43 Implement an up-to-date list of MySQL functions in mysql.pas. Used for
- popupmenu in query memo
- query helpers
- SynCompletionProposal
Drops function.txt and parser for that file.

Pros:
- No dependency on this file anymore
- Much easier and safer coding
- File-parsing no longer needed

Notes:

The old function.txt was meant to be editable and extensible for users but I never saw or heard anyone who does that, most likely because it wasn't documented. Another problem was that the file resided in the programs-directory, where only administrators have write-access, so in these cases it couldn't be edited anyway.

The PHP file in /extras can be used for creating an up-to-date list for mysql.pas .

As not all functions of the new list are available in all mysql-versions, it would be the best if we would fetch the list by the use of HELP commands. Contra: Would result in poor performancing popupmenu and many servers don't have the help-tables filled.
2007-07-04 22:31:56 +00:00

103 lines
2.3 KiB
PHP

<?php
/**
* This is a helper file for generating the MySQLFunctions Array
* in /source/mysql.pas
* Functions are fetched by using the HELP commands
*/
// Specify your own host, user, pass here.
// Do NOT commit passwords into SVN!!
mysql_connect( 'localhost', 'root' );
$nl = "\r\n";
$fnames = array();
$fstruc = array();
$q = mysql_query('HELP "functions"');
while( $row = mysql_fetch_object($q) )
{
if( $row->is_it_category == 'Y' )
{
getfunctions($row->name);
}
}
function getfunctions($cat)
{
global $nl, $fstruc, $fnames;
$q = mysql_query('HELP "'.$cat.'"');
while( $row = mysql_fetch_object($q) )
{
if( $row->is_it_category == 'Y' )
{
getfunctions( $row->name );
}
else
{
$sql = "HELP '".$row->name."'";
$qdetails = mysql_query($sql);
$rowdetails = mysql_fetch_object($qdetails);
if( preg_match('#(\S+)#', $rowdetails->name, $m1) )
{
$name = $m1[1];
}
else
{
$name = $row->name;
}
if( in_array($name,$fnames) )
{
continue;
}
$fnames[] = $name;
$declaration = '';
$desc_cut = substr($rowdetails->description, 0, strpos($rowdetails->description,"\n\n"));
$df = preg_match('#Syntax:[^\(]*(\([^\)]*\))#Us', $desc_cut, $m2);
if( $df )
{
$declaration = $m2[1];
$declaration = str_replace("'", "''", $declaration );
}
$description = '';
$df = preg_match('#Syntax:.*\n\n(.+)$#Uis', $rowdetails->description, $m3);
if( $df )
{
$description = trim($m3[1]);
$description = preg_replace('#(\s+)#', ' ', $description );
$description = str_replace(' o ', ' ', $description);
$description = str_replace("'", "''", $description );
$description = wordwrap($description,70, " '".$nl." +'" );
}
$fstruc[$name] .= sprintf(" (".$nl
." Name: '%s';".$nl
." Declaration: '%s';".$nl
." Category: '%s';".$nl
." Description: '%s'".$nl
." ),".$nl.$nl,
$name,
$declaration,
$cat,
$description
);
}
}
}
// Sort alphabetically by function name
asort($fstruc);
// produce output
$counter = 0;
foreach( $fstruc as $func )
{
print ' // Function nr. '.++$counter.$nl;
print $func;
}
?>