1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
unit MyxDbUtils;
interface
uses TntStdCtrls, Grt;
procedure UpdateCollations(ComboBox: TTntComboBox);
procedure SetCollations(ComboBox: TTntComboBox;
Collation: WideString; FailBackCollation: WideString = '');
procedure SetCharsetCollation(Collation: WideString; Obj: Pointer;
CharsetMember: WideString; CollationMember: WideString);
implementation
// -----------------------------------------------------------------------------
function Grt: TGrt;
begin
Result := RuntimeEnvironment;
end;
// -----------------------------------------------------------------------------
procedure UpdateCollations(ComboBox: TTntComboBox);
var
I, J: Integer;
CharsetList, Charset, CollationList: Pointer;
ItemText, OldSelVal: WideString;
begin
if (ComboBox = nil) then
Exit;
OldSelVal := ComboBox.Text;
with ComboBox do
begin
Items.Clear;
// Add favourites
Items.Add('latin1_swedish_ci');
Items.Add('latin1_german_ci');
Items.Add('utf8_general_ci');
Items.Add('_____________________');
Items.Add('');
CharsetList := Grt.Global['/workbench/catalog/characterSets'];
for I := 0 to Grt.ListCount(CharsetList) - 1 do
begin
Charset := Grt.ListRefItem[CharsetList, I];
CollationList := Grt.DictItem[Charset, 'collations'];
for J := 0 to Grt.ListCount(CollationList) - 1 do
begin
ItemText := Grt.ListString[CollationList, J];
Items.Add(ItemText);
if (ItemText = OldSelVal) and
(ItemIndex = -1) then
ItemIndex :=
Items.Count - 1;
end;
end;
if (ItemIndex = -1) then
begin
I := Items.IndexOf('latin1_swedish_ci');
if (I >= 0) then
ItemIndex := I
else
ItemIndex := 0;
end;
end;
end;
// -----------------------------------------------------------------------------
procedure SetCollations(ComboBox: TTntComboBox;
Collation: WideString; FailBackCollation: WideString);
var
I: Integer;
begin
// character set / collation
with ComboBox do
begin
I := Items.IndexOf(Collation);
if (I < 0) then
begin
if (FailBackCollation <> '') then
I := Items.IndexOf(FailBackCollation);
end;
if (I >= 0) then
ItemIndex := I
else
ItemIndex := Items.IndexOf('');
end;
end;
// -----------------------------------------------------------------------------
procedure SetCharsetCollation(Collation: WideString; Obj: Pointer;
CharsetMember: WideString; CollationMember: WideString);
var
P: Integer;
begin
P := Pos('_', Collation);
if (P > 0) then
Grt.DictString[Obj, CharsetMember] := Copy(Collation, 1, P - 1)
else
Grt.DictString[Obj, CharsetMember] := Collation;
Grt.DictString[Obj, CollationMember] := Collation;
end;
// -----------------------------------------------------------------------------
end.
|