root / LicensesMercure / mysql_win32.inc @ 5
Historique | Voir | Annoter | Télécharger (9,165 ko)
1 |
{ ********************************************************************* |
---|---|
2 |
* The contents of this file are used with permission, subject to * |
3 |
* the Mozilla Public License Version 1.1 (the "License"); you may * |
4 |
* not use this file except in compliance with the License. You may * |
5 |
* obtain a copy of the License at * |
6 |
* http: www.mozilla.org/MPL/MPL-1.1.html * |
7 |
* * |
8 |
* Software distributed under the License is distributed on an * |
9 |
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * |
10 |
* implied. See the License for the specific language governing * |
11 |
* rights and limitations under the License. * |
12 |
* * |
13 |
* Contributor(s) * |
14 |
* (so) Samuel Soldat <samuel.soldat@audio-data.de> * |
15 |
* * |
16 |
*********************************************************************} |
17 |
|
18 |
{$IFNDEF EmbeddedCharacterConvert} |
19 |
type |
20 |
TMySqlWindowsMapping=record |
21 |
CharacterSetName: String; |
22 |
CodePage: Word; |
23 |
end; |
24 |
|
25 |
const |
26 |
UnKnownCodePage = $FFFF; |
27 |
{Server 4.0: |
28 |
latin1 big5 czech euc_kr gb2312 gbk latin1_de sjis tis620 ujis dec8 dos german1 |
29 |
hp8 koi8_ru latin2 swe7 usa7 cp1251 danish hebrew win1251 estonia hungarian koi8_ukr |
30 |
win1251ukr greek win1250 croat cp1257 latin5} |
31 |
{Server 3.23 |
32 |
latin1 big5 czech euc_kr gb2312 gbk sjis tis620 ujis dec8 dos german1 hp8 koi8_ru |
33 |
latin2 swe7 usa7 cp1251 danish hebrew win1251 estonia hungarian koi8_ukr win1251ukr |
34 |
greek win1250 croat cp1257 latin5} |
35 |
MySqlCharacterSetNames: array [0..43] of TMySqlWindowsMapping=( |
36 |
(CharacterSetName: 'big5'; CodePage: 950), //Big5 Traditional Chinese |
37 |
(CharacterSetName: 'dec8'; CodePage: UnKnownCodePage), //DEC Multinational Character Set=>VT220? |
38 |
(CharacterSetName: 'cp850'; CodePage: 850), //DOS West European |
39 |
(CharacterSetName: 'hp8'; CodePage: UnKnownCodePage), //HP West European |
40 |
(CharacterSetName: 'koi8r'; CodePage: 20866), //KOI8-R Relcom Russian |
41 |
(CharacterSetName: 'koi8_ru'; CodePage: 20866), //KOI8-R Relcom Russian |
42 |
(CharacterSetName: 'latin1'; CodePage: 1252), //cp1252 West European |
43 |
(CharacterSetName: 'german1'; CodePage: 1252), //cp1252 West European |
44 |
(CharacterSetName: 'latin1_de'; CodePage: 1252), //cp1252 West European |
45 |
(CharacterSetName: 'latin2'; CodePage: 28592), //ISO 8859-2 Central European |
46 |
(CharacterSetName: 'swe7'; CodePage: 20107), //7bit Swedish |
47 |
(CharacterSetName: 'ascii'; CodePage: 20127), //US ASCII (#0..#127) |
48 |
(CharacterSetName: 'usa7'; CodePage: 20127), //US ASCII (#0..#127) |
49 |
(CharacterSetName: 'dos'; CodePage: 437), //US ASCII (#0..#127) |
50 |
(CharacterSetName: 'ujis'; CodePage: 51932), //EUC-JP Japanese |
51 |
(CharacterSetName: 'sjis'; CodePage: 932), //Shift-JIS Japanese |
52 |
(CharacterSetName: 'hebrew'; CodePage: 28598), //ISO 8859-8 Hebrew |
53 |
(CharacterSetName: 'tis620'; CodePage: 874), //ANSI/OEM Thai (same as 28605, ISO 8859-11); Thai (Windows) |
54 |
(CharacterSetName: 'euckr'; CodePage: 51949), //EUC-KR Korean |
55 |
(CharacterSetName: 'euc_kr'; CodePage: 51949), //EUC-KR Korean |
56 |
(CharacterSetName: 'koi8u'; CodePage: 21866), //KOI8-U Ukrainian |
57 |
(CharacterSetName: 'koi8_ukr'; CodePage: 21866), //KOI8-U Ukrainian |
58 |
(CharacterSetName: 'gb2312'; CodePage: 20936), //GB2312 Simplified Chinese |
59 |
(CharacterSetName: 'greek'; CodePage: 28597), //ISO 8859-7 |
60 |
(CharacterSetName: 'cp1250'; CodePage: 1250), //Windows Central European |
61 |
(CharacterSetName: 'win1250'; CodePage: 1250), //Windows Central European |
62 |
(CharacterSetName: 'gbk'; CodePage: 936), //GBK Simplified Chinese |
63 |
(CharacterSetName: 'latin5'; CodePage: 28599), //ISO 8859-9 Turkish |
64 |
(CharacterSetName: 'armscii8'; CodePage: UnKnownCodePage), //ARMSCII-8 Armenian |
65 |
(CharacterSetName: 'utf8'; CodePage: 65001), //UTF-8 Unicode |
66 |
(CharacterSetName: 'cp866'; CodePage: 866), //DOS Russian |
67 |
(CharacterSetName: 'keybcs2'; CodePage: UnKnownCodePage), //DOS Kamenicky Czech-Slovak |
68 |
(CharacterSetName: 'macce'; CodePage: 10029), //Mac Central European |
69 |
(CharacterSetName: 'macroman'; CodePage: 10000), //Mac West European |
70 |
(CharacterSetName: 'cp852'; CodePage: 852), //DOS Central European |
71 |
(CharacterSetName: 'latin7'; CodePage: 28603), //ISO 8859-13 Baltic |
72 |
(CharacterSetName: 'cp1251'; CodePage: 1251), //Windows Cyrillic |
73 |
(CharacterSetName: 'win1251'; CodePage: 1251), //Windows Cyrillic |
74 |
(CharacterSetName: 'cp1256'; CodePage: 1256), //Windows Arabic |
75 |
(CharacterSetName: 'cp1257'; CodePage: 1257), //Windows Baltic |
76 |
(CharacterSetName: 'binary'; CodePage: $FFFF), //RawByteString |
77 |
(CharacterSetName: 'geostd8'; CodePage: UnKnownCodePage), //GEOSTD8 Georgian |
78 |
(CharacterSetName: 'cp932'; CodePage: 932), //SJIS for Windows Japanese |
79 |
(CharacterSetName: 'eucjpms'; CodePage: 20932)); //UJIS for Windows Japanese |
80 |
|
81 |
// ----------------------------------------------------------------------------------------------- |
82 |
// Get the MySql Character set name according to Codepage |
83 |
// ----------------------------------------------------------------------------------------------- |
84 |
|
85 |
function CodePageToCharsetName(CodePage: Word; List: Boolean): String; |
86 |
var |
87 |
i: Integer; |
88 |
begin |
89 |
Result := ''; |
90 |
for i := 0 to High(MySqlCharacterSetNames) do |
91 |
begin |
92 |
if MySqlCharacterSetNames[i].CodePage=CodePage |
93 |
then begin |
94 |
Result := Result + MySqlCharacterSetNames[i].CharacterSetName + ','; |
95 |
if not List then break; |
96 |
end; |
97 |
end; |
98 |
if Result<>'' |
99 |
then |
100 |
SetLength(Result, Length(Result)-1); |
101 |
end; |
102 |
|
103 |
// ----------------------------------------------------------------------------------------------- |
104 |
// Get the Codepage according to MySql Character set name |
105 |
// ----------------------------------------------------------------------------------------------- |
106 |
|
107 |
function CharsetNameToCodePage(CharacterSetName: String): Word; |
108 |
var |
109 |
i: Integer; |
110 |
begin |
111 |
Result := UnKnownCodePage; |
112 |
for i := 0 to High(MySqlCharacterSetNames) do |
113 |
begin |
114 |
if AnsiSameText(MySqlCharacterSetNames[i].CharacterSetName, CharacterSetName) |
115 |
then begin |
116 |
Result := MySqlCharacterSetNames[i].CodePage; |
117 |
break; |
118 |
end; |
119 |
end; |
120 |
end; |
121 |
|
122 |
{$ENDIF} |
123 |
|
124 |
function MySqlToUTF16(Source: PAnsiChar; Length: Integer; CodePage: Word): UnicodeString; |
125 |
var |
126 |
DestLen: Integer; |
127 |
begin |
128 |
if (Length<0) |
129 |
then |
130 |
Length := MySql_StrLen(Source); |
131 |
if Length>0 |
132 |
then begin |
133 |
if CodePage=CP_ACP |
134 |
then |
135 |
CodePage := DefaultMySqlCodePage; |
136 |
DestLen := MultiByteToWideChar(CodePage, 0, Source, Length, nil, 0); |
137 |
if DestLen>0 |
138 |
then begin |
139 |
SetLength(Result, DestLen); |
140 |
MultiByteToWideChar(CodePage, 0, Source, Length, Pointer(Result), DestLen); |
141 |
end |
142 |
else |
143 |
Result := ''; |
144 |
end |
145 |
else |
146 |
Result := ''; |
147 |
end; |
148 |
|
149 |
function UTF16ToMySql(const Source: UnicodeString; CodePage: Word): RawByteString; |
150 |
var |
151 |
SourceLen: Integer; |
152 |
DestLen: Integer; |
153 |
begin |
154 |
SourceLen := Length(Source); |
155 |
if SourceLen>0 |
156 |
then begin |
157 |
if CodePage=CP_ACP |
158 |
then |
159 |
CodePage := DefaultMySqlCodePage; |
160 |
DestLen := WideCharToMultiByte(CodePage, 0, Pointer(Source), SourceLen, nil, 0, nil, nil); |
161 |
if DestLen>0 |
162 |
then begin |
163 |
SetLength(Result, DestLen); |
164 |
WideCharToMultiByte(CodePage, 0, Pointer(Source), SourceLen, Pointer(Result), DestLen, nil, nil); |
165 |
{$IFDEF CONDITIONALEXPRESSIONS} |
166 |
{$IF (CompilerVersion>=20)} {Delphi 2009 and above} |
167 |
SetCodePage(Result, CodePage, False); |
168 |
{$IFEND} |
169 |
{$ENDIF} |
170 |
end |
171 |
else |
172 |
Result := ''; |
173 |
end |
174 |
else |
175 |
Result := ''; |
176 |
end; |
177 |
|
178 |
// ----------------------------------------------------------------------------------------------- |
179 |
|
180 |
{ TMySqlEncoding } |
181 |
|
182 |
constructor TMySqlEncoding.Create(Codepage: Word); |
183 |
begin |
184 |
inherited Create; |
185 |
if Codepage=CP_ACP |
186 |
then |
187 |
FCodepage := GetACP |
188 |
else |
189 |
FCodepage := Codepage; |
190 |
end; |
191 |
|
192 |
|
193 |
function TMySqlEncoding.MySqlToUTF16(Source: PAnsiChar; Length: Integer): UnicodeString; |
194 |
begin |
195 |
Result := mysql.MySqlToUTF16(Source, Length, FCodePage); |
196 |
end; |
197 |
|
198 |
function TMySqlEncoding.UTF16ToMySql(const Source: UnicodeString): RawByteString; |
199 |
begin |
200 |
Result := mysql.UTF16ToMySql(Source, FCodePage); |
201 |
end; |