mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-26 19:20:17 +08:00
MakeInt(): Correctly backconvert strings which were previously formatted by FormatByteNumber() . Fixes incorrect sorting of columns in VirtualTrees which contain some byte values. Also enables us to call FormatToByteNumber() in "Size" column of ListTables.
This commit is contained in:
@ -1990,7 +1990,7 @@ begin
|
|||||||
ListCaptions.Add( FormatNumber( ds.FieldByName('Rows').AsFloat ) );
|
ListCaptions.Add( FormatNumber( ds.FieldByName('Rows').AsFloat ) );
|
||||||
// Size: Data_length + Index_length
|
// Size: Data_length + Index_length
|
||||||
bytes := ds.FieldByName('Data_length').AsFloat + ds.FieldByName('Index_length').AsFloat;
|
bytes := ds.FieldByName('Data_length').AsFloat + ds.FieldByName('Index_length').AsFloat;
|
||||||
ListCaptions.Add( FormatNumber( bytes / 1024 + 1 ) + ' KB');
|
ListCaptions.Add( FormatByteNumber( FloatToStr(bytes) ) );
|
||||||
// Created:
|
// Created:
|
||||||
if not ds.FieldByName('Create_time').IsNull then
|
if not ds.FieldByName('Create_time').IsNull then
|
||||||
ListCaptions.Add( ds.FieldByName('Create_time').AsString )
|
ListCaptions.Add( ds.FieldByName('Create_time').AsString )
|
||||||
|
@ -52,3 +52,18 @@ const
|
|||||||
ICONINDEX_UNIQUEKEY = 64;
|
ICONINDEX_UNIQUEKEY = 64;
|
||||||
ICONINDEX_FULLTEXTKEY = 65;
|
ICONINDEX_FULLTEXTKEY = 65;
|
||||||
|
|
||||||
|
// Size of byte units
|
||||||
|
{KiloByte} SIZE_KB = 1024;
|
||||||
|
{MegaByte} SIZE_MB = 1048576;
|
||||||
|
{GigaByte} SIZE_GB = 1073741824;
|
||||||
|
{TeraByte} SIZE_TB = 1099511627776;
|
||||||
|
{PetaByte} SIZE_PB = 1125899906842624;
|
||||||
|
|
||||||
|
// Abbreviations of byte unit names
|
||||||
|
{Bytes} NAME_BYTES = ' B';
|
||||||
|
{KiloByte} NAME_KB = ' KB';
|
||||||
|
{MegaByte} NAME_MB = ' MB';
|
||||||
|
{GigaByte} NAME_GB = ' GB';
|
||||||
|
{TeraByte} NAME_TB = ' TB';
|
||||||
|
{PetaByte} NAME_PB = ' PB';
|
||||||
|
|
||||||
|
@ -1228,17 +1228,44 @@ End;
|
|||||||
function MakeInt( Str: String ) : Int64;
|
function MakeInt( Str: String ) : Int64;
|
||||||
var
|
var
|
||||||
i : Integer;
|
i : Integer;
|
||||||
StrWithInts : String;
|
StrNumber : String;
|
||||||
|
float : Extended;
|
||||||
|
p_kb, p_mb, p_gb, p_tb, p_pb : Integer;
|
||||||
begin
|
begin
|
||||||
StrWithInts := '';
|
StrNumber := '';
|
||||||
for i:=1 to Length(str) do
|
for i:=1 to Length(Str) do
|
||||||
begin
|
begin
|
||||||
if StrToIntDef( str[i], -1 ) <> -1 then
|
if Str[i] in ['0'..'9', DecimalSeparator] then
|
||||||
begin
|
begin
|
||||||
StrWithInts := StrWithInts + str[i];
|
StrNumber := StrNumber + Str[i];
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
result := StrToInt64Def( StrWithInts, 0 );
|
|
||||||
|
// Temporarly convert result to a floating point value to ensure
|
||||||
|
// we don't discard decimal digits for the next step
|
||||||
|
float := StrToFloat( StrNumber );
|
||||||
|
|
||||||
|
// Detect if the string was previously formatted by FormatByteNumber
|
||||||
|
// and convert it back by multiplying it with its byte unit
|
||||||
|
p_kb := Pos(NAME_KB, Str);
|
||||||
|
p_mb := Pos(NAME_MB, Str);
|
||||||
|
p_gb := Pos(NAME_GB, Str);
|
||||||
|
p_tb := Pos(NAME_TB, Str);
|
||||||
|
p_pb := Pos(NAME_PB, Str);
|
||||||
|
|
||||||
|
if (p_kb > 0) and (p_kb = Length(Str)-Length(NAME_KB)+1) then
|
||||||
|
float := float * SIZE_KB
|
||||||
|
else if (p_mb > 0) and (p_mb = Length(Str)-Length(NAME_MB)+1) then
|
||||||
|
float := float * SIZE_MB
|
||||||
|
else if (p_gb > 0) and (p_gb = Length(Str)-Length(NAME_GB)+1) then
|
||||||
|
float := float * SIZE_GB
|
||||||
|
else if (p_tb > 0) and (p_tb = Length(Str)-Length(NAME_TB)+1) then
|
||||||
|
float := float * SIZE_TB
|
||||||
|
else if (p_pb > 0) and (p_pb = Length(Str)-Length(NAME_PB)+1) then
|
||||||
|
float := float * SIZE_PB;
|
||||||
|
|
||||||
|
// Result has to be of integer type
|
||||||
|
Result := Trunc( float );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1955,25 +1982,19 @@ end;
|
|||||||
@param Byte Decimals to display when bytes is bigger than 1M
|
@param Byte Decimals to display when bytes is bigger than 1M
|
||||||
}
|
}
|
||||||
function FormatByteNumber( Bytes: Int64; Decimals: Byte = 1 ): String; Overload;
|
function FormatByteNumber( Bytes: Int64; Decimals: Byte = 1 ): String; Overload;
|
||||||
const
|
|
||||||
{KiloByte} KB = 1024;
|
|
||||||
{MegaByte} MB = 1048576;
|
|
||||||
{GigaByte} GB = 1073741824;
|
|
||||||
{TeraByte} TB = 1099511627776;
|
|
||||||
{PetaByte} PB = 1125899906842624;
|
|
||||||
begin
|
begin
|
||||||
if Bytes >= PB then
|
if Bytes >= SIZE_PB then
|
||||||
Result := FormatNumber( Bytes / PB, Decimals ) + ' PB'
|
Result := FormatNumber( Bytes / SIZE_PB, Decimals ) + NAME_PB
|
||||||
else if Bytes >= TB then
|
else if Bytes >= SIZE_TB then
|
||||||
Result := FormatNumber( Bytes / TB, Decimals ) + ' TB'
|
Result := FormatNumber( Bytes / SIZE_TB, Decimals ) + NAME_TB
|
||||||
else if Bytes >= GB then
|
else if Bytes >= SIZE_GB then
|
||||||
Result := FormatNumber( Bytes / GB, Decimals ) + ' GB'
|
Result := FormatNumber( Bytes / SIZE_GB, Decimals ) + NAME_GB
|
||||||
else if Bytes >= MB then
|
else if Bytes >= SIZE_MB then
|
||||||
Result := FormatNumber( Bytes / MB, Decimals ) + ' MB'
|
Result := FormatNumber( Bytes / SIZE_MB, Decimals ) + NAME_MB
|
||||||
else if Bytes >= KB then
|
else if Bytes >= SIZE_KB then
|
||||||
Result := FormatNumber( Bytes / KB, Decimals ) + ' KB'
|
Result := FormatNumber( Bytes / SIZE_KB, Decimals ) + NAME_KB
|
||||||
else
|
else
|
||||||
Result := FormatNumber( Bytes ) + ' Bytes'
|
Result := FormatNumber( Bytes ) + NAME_BYTES
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user