Print Thread
Problem in function DecodeConnectString
#9976 09/17/08 06:38 PM
Joined: Nov 2006
Posts: 44
Ukraine
D
Devil Offline OP
Member
OP Offline
Member
D
Joined: Nov 2006
Posts: 44
Ukraine
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 @):

Code
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

Re: Problem in function DecodeConnectString
#9977 09/18/08 02:55 PM
Joined: Aug 1999
Posts: 22,220
Member
Offline
Member
Joined: Aug 1999
Posts: 22,220
If you want to use special characters in usernames or passwords, you have to include them in double quotes. Using 2 @ characters in a connect-string is ambiguous without quotes.


Marco Kalter
Allround Automations
Re: Problem in function DecodeConnectString
#9978 09/18/08 08:53 PM
Joined: Nov 2006
Posts: 44
Ukraine
D
Devil Offline OP
Member
OP Offline
Member
D
Joined: Nov 2006
Posts: 44
Ukraine
Not working.
Give me example please?

All variants return not logged on.
ORA-12154.
TNS- resolve name not exists return @tt@ora,

because sid database start from first special character @(@tt@ora)


In Open PLSQL Developer, File -> New -> Command Window

SQL> connect scott/sc@@tt@ora
Not logged on

or
SQL> connect "scott/sc@tt@ora"
Not logged on

or
SQL> connect scott/"sc@tt"@ora
Not logged on

or
SQL> connect "scott/sc@tt"@ora
Not logged on

user scott exists with password: sc@tt
and tnsname for database exists: ora

Re: Problem in function DecodeConnectString
#9979 09/19/08 03:11 PM
Joined: Aug 1999
Posts: 22,220
Member
Offline
Member
Joined: Aug 1999
Posts: 22,220
This does indeed not work. We'll fix it.


Marco Kalter
Allround Automations
Re: Problem in function DecodeConnectString
#9980 09/20/08 12:48 PM
Joined: Nov 2006
Posts: 44
Ukraine
D
Devil Offline OP
Member
OP Offline
Member
D
Joined: Nov 2006
Posts: 44
Ukraine
Thank's.


Moderated by  support 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 7.1.33 Page Time: 0.056s Queries: 13 (0.017s) Memory: 2.5190 MB (Peak: 3.0426 MB) Data Comp: Off Server Time: 2024-05-19 09:33:47 UTC
Valid HTML 5 and Valid CSS