Hi,
For exemple, I have next connection information:
scott/sc@tt@ora
In password used
@When I pass this string in a function
...
DecodeConnectString('scott/sc@tt@ora', Username, Password, Database, ConnectAs);
...
that takes place not faithful treatment of this string.
username: scott
password: sc
database: tt@ora
On my a next variant will be more correct(used function PosEx for finding last @):
uses StrUtils;
...
function DecodeConnectString(const S: string; var Username, Password, Database, ConnectAs : string): Boolean;
var i, Mode: Integer;
InQuotes, ModeChange: Boolean;
ws: widestring;
begin
ws := s;
Mode := 0;
InQuotes := False;
if ws = '' then
begin
ws := Username;
if Password <> '' then ws := ws + '/' + Password;
if Database <> '' then ws := ws + '@' + Database;
if ConnectAs <> '' then ws := ws + ' as ' + ConnectAs;
end;
Username := '';
Password := '';
Database := '';
ConnectAs := StripConnectAs(ws);
for i := 1 to Length(ws) do
begin
if ws[i] = '"' then InQuotes := not InQuotes;
ModeChange := False;
if (not InQuotes) then
begin
if (Mode < 1) and (ws[i] = '/') then
begin
mode := 1;
ModeChange := True;
end else if (Mode < 2) and ((ws[i] = '@') and (PosEx('@', ws, i + 1) = 0)) then
begin
mode := 2;
ModeChange := True;
end;
end;
if not ModeChange then
begin
case Mode of
0: Username := Username + ws[i];
1: Password := Password + ws[i];
2: Database := Database + ws[i];
end;
end;
end;
Result := (Password <> '') or (Database <> '') or (ConnectAs <> '');
end;
Please check up this variant and correct in the next versions of DOA.
For test: Open PLSQL Developer, File -> New -> Command Window:
SQL> connect sameuser/same@password@same_db