mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Simplify and optimize functions generator for MariaDB, and update functions-mariadb.ini with predefined line breaks
This commit is contained in:
@ -1,7 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
define('NL', "\r\n");
|
|
||||||
|
|
||||||
function finalizeEntries($iniEntries)
|
const NL = "\r\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $iniEntries
|
||||||
|
* @param bool $doWordWrap Set to false if descriptions already contain line breaks, like in MySQL
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function finalizeEntries(array $iniEntries, bool $doWordWrap): string
|
||||||
{
|
{
|
||||||
static $replaceMap = [
|
static $replaceMap = [
|
||||||
'“' => '"',
|
'“' => '"',
|
||||||
@ -38,8 +44,23 @@ function finalizeEntries($iniEntries)
|
|||||||
}
|
}
|
||||||
$descr = $iniEntry['description'];
|
$descr = $iniEntry['description'];
|
||||||
$descr = strtr($descr, $replaceMap);
|
$descr = strtr($descr, $replaceMap);
|
||||||
$descr = wordwrap($descr);
|
// Limit description to 50 lines, if the rest is longer than 100 chars
|
||||||
$descr = str_replace("\n", '\n', $descr);
|
$numLinebreaks = 0;
|
||||||
|
$lenDescr = strlen($descr);
|
||||||
|
for($i=0; $i<strlen($descr); $i++) {
|
||||||
|
if($descr[$i] == "\n") {
|
||||||
|
$numLinebreaks++;
|
||||||
|
}
|
||||||
|
if($numLinebreaks == 50 && $lenDescr > $i + 100) {
|
||||||
|
$descr = substr($descr, 0, $i+1) . ' ...';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//die();
|
||||||
|
if($doWordWrap) {
|
||||||
|
$descr = wordwrap($descr);
|
||||||
|
}
|
||||||
|
$descr = str_replace(["\r\n", "\r", "\n"], '\n', $descr);
|
||||||
|
|
||||||
$entry .= "declaration=".$iniEntry['declaration'].NL
|
$entry .= "declaration=".$iniEntry['declaration'].NL
|
||||||
. "category=".$iniEntry['category'].NL
|
. "category=".$iniEntry['category'].NL
|
||||||
@ -47,11 +68,12 @@ function finalizeEntries($iniEntries)
|
|||||||
$finalEntries[$section] = $entry;
|
$finalEntries[$section] = $entry;
|
||||||
}
|
}
|
||||||
ksort($finalEntries);
|
ksort($finalEntries);
|
||||||
|
//var_dump($finalEntries);
|
||||||
return implode(NL, $finalEntries);
|
return implode(NL, $finalEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function gen_sqlite()
|
function gen_sqlite(): string
|
||||||
{
|
{
|
||||||
$urls = [
|
$urls = [
|
||||||
'Aggregate Functions'=>'https://www.sqlite.org/lang_aggfunc.html',
|
'Aggregate Functions'=>'https://www.sqlite.org/lang_aggfunc.html',
|
||||||
@ -135,14 +157,14 @@ function gen_sqlite()
|
|||||||
'description'=>'All five date and time functions take a time value as an argument. The time value is followed by zero or more modifiers. The strftime() function also takes a format string as its first argument.',
|
'description'=>'All five date and time functions take a time value as an argument. The time value is followed by zero or more modifiers. The strftime() function also takes a format string as its first argument.',
|
||||||
];
|
];
|
||||||
|
|
||||||
return finalizeEntries($iniEntries);
|
return finalizeEntries($iniEntries, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function gen_mysql()
|
function gen_mariadb()
|
||||||
{
|
{
|
||||||
// Insert your custom password and port
|
// Insert your custom password and port
|
||||||
$mysqli = mysqli_connect('localhost', 'root', null, null, '3333');
|
$mysqli = mysqli_connect('localhost', 'root', null, null, '3317');
|
||||||
$query = mysqli_query($mysqli, "SELECT t.name, t.description, c.name AS categ
|
$query = mysqli_query($mysqli, "SELECT t.name, t.description, c.name AS categ
|
||||||
FROM mysql.help_topic t, mysql.help_category c
|
FROM mysql.help_topic t, mysql.help_category c
|
||||||
WHERE
|
WHERE
|
||||||
@ -157,26 +179,28 @@ function gen_mysql()
|
|||||||
|
|
||||||
while($row = mysqli_fetch_object($query)) {
|
while($row = mysqli_fetch_object($query)) {
|
||||||
$name = $row->name;
|
$name = $row->name;
|
||||||
$nameUpper = strtoupper($name);
|
// Exclude function names with spaces, or other non-word characters:
|
||||||
if(!preg_match('#\w+#', $nameUpper)) {
|
if(!preg_match('#^\w+$#', $name)) {
|
||||||
//echo "10\n";
|
//echo "10\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#echo $name."\n";
|
||||||
$matchCount = preg_match(
|
$matchCount = preg_match(
|
||||||
'#^(Syntax\:[\r\n\s]+)?'.preg_quote($row->name).'\(([^\)]*)\)[^\r\n]*[\r\n](.*)$#si',
|
'#\b'.preg_quote($row->name).'\s?\[?\(([^\)]*)\)[^\r\n]*[\r\n](.*)$#is',
|
||||||
$row->description,
|
$row->description,
|
||||||
$matches);
|
$matches);
|
||||||
if(!$matchCount) {
|
if(!$matchCount) {
|
||||||
//echo "20\n";
|
//echo "20\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$description = trim($matches[3]);
|
$declaration = trim($matches[1]);
|
||||||
$declaration = trim($matches[2]);
|
|
||||||
if(preg_match('#^([^\.]+)\.#', $description, $matchesD)) {
|
|
||||||
$description = $matchesD[1];
|
|
||||||
}
|
|
||||||
$description = preg_replace('#[\r\n]#', ' ', $description);
|
|
||||||
$declaration = preg_replace('#[\r\n]#', ' ', $declaration);
|
$declaration = preg_replace('#[\r\n]#', ' ', $declaration);
|
||||||
|
|
||||||
|
$description = trim($matches[2]);
|
||||||
|
if(preg_match('#Description\s+\-+[\r\n](.+)#is', $description, $matchesD)) {
|
||||||
|
$description = trim($matchesD[1]);
|
||||||
|
}
|
||||||
|
//$description = preg_replace('#[\r\n]#', ' ', $description);
|
||||||
#echo $row->name."\n".$matches[2]."\n".$matches[3]."\n\n";
|
#echo $row->name."\n".$matches[2]."\n".$matches[3]."\n\n";
|
||||||
$iniEntries[] = [
|
$iniEntries[] = [
|
||||||
'name'=>$row->name,
|
'name'=>$row->name,
|
||||||
@ -186,11 +210,11 @@ function gen_mysql()
|
|||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
return finalizeEntries($iniEntries);
|
return finalizeEntries($iniEntries, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function gen_pg()
|
function gen_pg(): string
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* https://www.postgresql.org/docs/current/functions-string.html
|
* https://www.postgresql.org/docs/current/functions-string.html
|
||||||
@ -229,11 +253,11 @@ function gen_pg()
|
|||||||
foreach($categoryUrls as $category => $url) {
|
foreach($categoryUrls as $category => $url) {
|
||||||
$doc = file_get_contents($url);
|
$doc = file_get_contents($url);
|
||||||
if(empty($doc)) {
|
if(empty($doc)) {
|
||||||
throw new \RuntimeException("Could not read $url");
|
throw new RuntimeException("Could not read $url");
|
||||||
}
|
}
|
||||||
$numMatches = preg_match_all('#<p class="func_signature"><a\s*[^>]*></a>\s*<code class="function">(\w+)</code>\s*\(([^)]*)\).*</p>\s*<p>(.+)</p>#', $doc, $matches);
|
$numMatches = preg_match_all('#<p class="func_signature"><a\s*[^>]*></a>\s*<code class="function">(\w+)</code>\s*\(([^)]*)\).*</p>\s*<p>(.+)</p>#', $doc, $matches);
|
||||||
if($numMatches === false) {
|
if($numMatches === false) {
|
||||||
throw new \RuntimeException("Regexp error: ".preg_last_error());
|
throw new RuntimeException("Regexp error: ".preg_last_error());
|
||||||
}
|
}
|
||||||
#var_dump($matches);
|
#var_dump($matches);
|
||||||
foreach($matches[1] as $i=>$name) {
|
foreach($matches[1] as $i=>$name) {
|
||||||
@ -246,9 +270,9 @@ function gen_pg()
|
|||||||
}
|
}
|
||||||
#break;
|
#break;
|
||||||
}
|
}
|
||||||
return finalizeEntries($iniEntries);
|
return finalizeEntries($iniEntries, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
# echo gen_sqlite();
|
# echo gen_sqlite();
|
||||||
#echo gen_mysql();
|
echo gen_mariadb();
|
||||||
echo gen_pg();
|
#echo gen_pg();
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user