Attach server version to SQL functions and use that to hide unsupported functions in query helpers, popupQuery and SynCompletionProposal.

This commit is contained in:
Ansgar Becker
2007-07-06 22:07:05 +00:00
parent fa46bd85c8
commit 86f01b4675
5 changed files with 369 additions and 8 deletions

View File

@@ -5,6 +5,33 @@
* Functions are fetched by using the HELP commands
*/
// Gather version information for functions
$ver_cont = file_get_contents('http://dev.mysql.com/doc/refman/5.2/en/func-op-summary-ref.html');
if( $ver_cont )
{
// <code class="literal">ADDDATE()</code></a>(v4.1.1)
$ver_cont = html_entity_decode($ver_cont);
$matches = array();
preg_match_all( '#\<a[^\>]+\>\<code class="literal"\>([^\(\s\<]+).*\<\/a\>\(v(.+)\)#', $ver_cont, $matches );
$versions = array();
for( $i=0; $i<count($matches[0]); $i++ )
{
$versionArr = explode( '.', $matches[2][$i] );
// make int of array
if( !isset($versionArr[1]) )
$versionArr[1] = '0';
if( !isset($versionArr[2]) )
$versionArr[2] = '0';
$version = sprintf('%d%02d%02d',
$versionArr[0],
$versionArr[1],
$versionArr[2]
);
// functionname => version
$versions[ $matches[1][$i] ] = $version;
}
}
// Specify your own host, user, pass here.
// Do NOT commit passwords into SVN!!
mysql_connect( 'localhost', 'root' );
@@ -27,7 +54,7 @@ getfunctions('Geographic Features');
function getfunctions( $cat, $rootcat='' )
{
global $nl, $fstruc, $fnames;
global $nl, $fstruc, $fnames, $versions;
$q = mysql_query('HELP "'.$cat.'"');
while( $row = mysql_fetch_object($q) )
{
@@ -80,15 +107,23 @@ function getfunctions( $cat, $rootcat='' )
$description = wordwrap($description,70, " '".$nl." +'" );
}
$version = 'SQL_VERSION_ANSI';
if( !empty($versions[$name]) )
{
$version = $versions[$name];
}
$fstruc[$name] .= sprintf(" (".$nl
." Name: '%s';".$nl
." Declaration: '%s';".$nl
." Category: '%s';".$nl
." Version: %s;".$nl
." Description: '%s'".$nl
." ),".$nl.$nl,
$name,
$declaration,
(!empty($rootcat) ? $rootcat : $cat),
$version,
$description
);
}

View File

@@ -787,7 +787,7 @@ begin
if ( UpperCase( ds.FieldByName('Support').AsString ) = 'NO' ) then
begin
menuitem.Enabled := false;
menuitem.Hint := menuitem.Hint + ' (Not supported on this server)';
menuitem.Hint := menuitem.Hint + ' ('+STR_NOTSUPPORTED+')';
end;
menuitem.OnClick := MenuChangeTypeClick;
MenuChangeType.Add( menuitem );
@@ -845,13 +845,22 @@ begin
if mi.Caption = '-' then
mi.Caption := '&-';
mi.Hint := MySqlFunctions[j].Name + MySqlFunctions[j].Declaration;
if MySqlFunctions[j].Description <> '' then
mi.Hint := mi.Hint + ' - ' + Copy(MySqlFunctions[j].Description, 0, 200 );
// Take care of needed server version
if MySqlFunctions[j].Version <= mysql_version then
begin
if MySqlFunctions[j].Description <> '' then
mi.Hint := mi.Hint + ' - ' + Copy(MySqlFunctions[j].Description, 0, 200 );
mi.Tag := j;
// Place menuitem on menu
mi.OnClick := insertFunction;
end
else
begin
mi.Hint := mi.Hint + ' - ('+STR_NOTSUPPORTED+', needs >= '+ConvertServerVersion(MySqlFunctions[j].Version)+')';
mi.Enabled := False;
end;
// Prevent generating a seperator for ShortHint and LongHint
mi.Hint := StringReplace( mi.Hint, '|', '<27>', [rfReplaceAll] );
mi.Tag := j;
// Place menuitem on menu
mi.OnClick := insertFunction;
popupQuery.Items[i+13].Add(mi);
end;
end;
@@ -3182,6 +3191,9 @@ begin
// Add functions
for i := 0 to Length(MySQLFunctions) - 1 do
begin
// Don't display unsupported functions here
if MySqlFunctions[i].Version > mysql_version then
continue;
SynCompletionProposal1.InsertList.Add( MySQLFunctions[i].Name + MySQLFunctions[i].Declaration );
SynCompletionProposal1.ItemList.Add( '\hspace{2}\color{'+ColorToString(SynSQLSyn1.FunctionAttri.Foreground)+'}function\color{clWindowText}\column{}' + MySQLFunctions[i].Name + '\style{-B}' + MySQLFunctions[i].Declaration );
end;
@@ -5529,6 +5541,9 @@ begin
begin
for i := 0 to Length(MySQLFunctions) - 1 do
begin
// Don't display unsupported functions here
if MySqlFunctions[i].Version > mysql_version then
continue;
lboxQueryHelpers.Items.Add( MySQLFunctions[i].Name + MySQLFunctions[i].Declaration );
end;
end;

View File

@@ -22,6 +22,7 @@ const
APPNAME = 'HeidiSQL';
REGPATH = 'Software\' + APPNAME;
STATUS_MSG_READY = 'Ready.';
STR_NOTSUPPORTED = 'Not supported by this server';
// Used by maskSQL and fixSQL:
SQL_VERSION_ANSI = -1;

View File

@@ -67,6 +67,7 @@ uses Classes, SysUtils, Graphics, db, clipbrd, dialogs,
procedure AddUniqueItemsToList( ToAdd: TStrings; BaseList: TStrings );
function GetFieldValue( Field: TField ): String;
function LastPos( substr: WideString; str: WideString): Integer;
function ConvertServerVersion( Version: Integer ): String;
var
MYSQL_KEYWORDS : TStringList;
@@ -1885,6 +1886,21 @@ begin
end;
{**
Convert integer version to real version string
}
function ConvertServerVersion( Version: Integer ): String;
var
v : String;
v1, v2 : Byte;
begin
v := IntToStr( Version );
v1 := StrToIntDef( v[2]+v[3], 0 );
v2 := StrToIntDef( v[4]+v[5], 0 );
Result := v[1] + '.' + IntToStr(v1) + '.' + IntToStr(v2);
end;
initialization

View File

File diff suppressed because it is too large Load Diff