54 |
|
TAB = #9; |
55 |
|
NULL_TERMINATOR = #0; |
56 |
|
|
57 |
< |
sqlReservedWords: array [0..197] of string = ( |
57 |
> |
sqlReservedWords: array [0..198] of string = ( |
58 |
|
'ADD', |
59 |
|
'ADMIN', |
60 |
|
'ALL', |
146 |
|
'INTO', |
147 |
|
'IS', |
148 |
|
'JOIN', |
149 |
+ |
'KEY', |
150 |
|
'LEADING', |
151 |
|
'LEFT', |
152 |
|
'LIKE', |
404 |
|
function ParseConnectString(ConnectString: AnsiString; var ServerName, |
405 |
|
DatabaseName: AnsiString; var Protocol: TProtocolAll; var PortNo: AnsiString |
406 |
|
): boolean; |
407 |
+ |
|
408 |
+ |
function GetProtocol(scheme: AnsiString): TProtocolAll; |
409 |
+ |
begin |
410 |
+ |
scheme := AnsiUpperCase(scheme); |
411 |
+ |
if scheme = 'INET' then |
412 |
+ |
Result := inet |
413 |
+ |
else |
414 |
+ |
if scheme = 'INET4' then |
415 |
+ |
Result := inet4 |
416 |
+ |
else |
417 |
+ |
if scheme = 'INET6' then |
418 |
+ |
Result := inet6 |
419 |
+ |
else |
420 |
+ |
if scheme = 'XNET' then |
421 |
+ |
Result := xnet |
422 |
+ |
else |
423 |
+ |
if scheme = 'WNET' then |
424 |
+ |
Result := wnet |
425 |
+ |
end; |
426 |
+ |
|
427 |
|
var RegexObj: TRegExpr; |
407 |
– |
scheme: AnsiString; |
428 |
|
begin |
429 |
|
ServerName := ''; |
430 |
|
DatabaseName := ConnectString; |
434 |
|
try |
435 |
|
{extact database file spec} |
436 |
|
RegexObj.ModifierG := false; {turn off greedy matches} |
437 |
< |
RegexObj.Expression := '^([a-zA-Z]+)://([a-zA-Z0-9\-\.]+)(|:[0-9a-zA-Z\-]+)/(.*)$'; |
437 |
> |
RegexObj.Expression := '^([a-zA-Z46]+)://([a-zA-Z0-9\-\.]*)(|:[0-9a-zA-Z\-]+)/(.*)$'; |
438 |
|
Result := RegexObj.Exec(ConnectString); |
439 |
|
if Result then |
440 |
|
begin |
441 |
|
{URL type connect string} |
442 |
< |
scheme := AnsiUpperCase(RegexObj.Match[1]); |
442 |
> |
Protocol := GetProtocol(RegexObj.Match[1]); |
443 |
|
ServerName := RegexObj.Match[2]; |
444 |
|
if RegexObj.MatchLen[3] > 0 then |
445 |
|
PortNo := system.Copy(ConnectString,RegexObj.MatchPos[3]+1,RegexObj.MatchLen[3]-1); |
446 |
|
DatabaseName := RegexObj.Match[4]; |
447 |
< |
if scheme = 'INET' then |
448 |
< |
Protocol := inet |
429 |
< |
else |
430 |
< |
if scheme = 'XNET' then |
431 |
< |
Protocol := xnet |
432 |
< |
else |
433 |
< |
if scheme = 'WNET' then |
434 |
< |
Protocol := wnet |
447 |
> |
if ServerName = '' then |
448 |
> |
DatabaseName := '/' + DatabaseName; |
449 |
|
end |
450 |
|
else |
451 |
|
begin |
452 |
< |
RegexObj.Expression := '^([a-zA-Z]:\\.*)'; |
452 |
> |
{URL type connect string - local loop} |
453 |
> |
RegexObj.Expression := '^([a-zA-Z46]+)://(.*)$'; |
454 |
|
Result := RegexObj.Exec(ConnectString); |
455 |
|
if Result then |
456 |
< |
Protocol := Local {Windows with leading drive ID} |
456 |
> |
begin |
457 |
> |
Protocol := GetProtocol(RegexObj.Match[1]); |
458 |
> |
DatabaseName := RegexObj.Match[2]; |
459 |
> |
end |
460 |
|
else |
461 |
|
begin |
462 |
< |
RegexObj.Expression := '^([a-zA-Z0-9\-\.]+)(|/[0-9a-zA-Z\-]+):(.*)$'; |
462 |
> |
RegexObj.Expression := '^([a-zA-Z]:\\.*)'; |
463 |
|
Result := RegexObj.Exec(ConnectString); |
464 |
|
if Result then |
465 |
< |
begin |
448 |
< |
{Legacy TCP Format} |
449 |
< |
ServerName := RegexObj.Match[1]; |
450 |
< |
if RegexObj.MatchLen[2] > 0 then |
451 |
< |
PortNo := system.Copy(ConnectString,RegexObj.MatchPos[2]+1,RegexObj.MatchLen[2]-1); |
452 |
< |
DatabaseName := RegexObj.Match[3]; |
453 |
< |
Protocol := TCP; |
454 |
< |
end |
465 |
> |
Protocol := Local {Windows with leading drive ID} |
466 |
|
else |
467 |
|
begin |
468 |
< |
RegexObj.Expression := '^\\\\([a-zA-Z0-9\-\.]+)(|@[0-9a-zA-Z\-]+)\\(.*)$'; |
468 |
> |
RegexObj.Expression := '^([a-zA-Z0-9\-\.]+)(|/[0-9a-zA-Z\-]+):(.*)$'; |
469 |
|
Result := RegexObj.Exec(ConnectString); |
470 |
|
if Result then |
471 |
|
begin |
472 |
< |
{Netbui} |
472 |
> |
{Legacy TCP Format} |
473 |
|
ServerName := RegexObj.Match[1]; |
474 |
|
if RegexObj.MatchLen[2] > 0 then |
475 |
|
PortNo := system.Copy(ConnectString,RegexObj.MatchPos[2]+1,RegexObj.MatchLen[2]-1); |
476 |
|
DatabaseName := RegexObj.Match[3]; |
477 |
< |
Protocol := NamedPipe |
477 |
> |
Protocol := TCP; |
478 |
|
end |
479 |
|
else |
480 |
|
begin |
481 |
< |
Result := true; |
482 |
< |
Protocol := Local; {Assume local} |
481 |
> |
RegexObj.Expression := '^\\\\([a-zA-Z0-9\-\.]+)(|@[0-9a-zA-Z\-]+)\\(.*)$'; |
482 |
> |
Result := RegexObj.Exec(ConnectString); |
483 |
> |
if Result then |
484 |
> |
begin |
485 |
> |
{Netbui} |
486 |
> |
ServerName := RegexObj.Match[1]; |
487 |
> |
if RegexObj.MatchLen[2] > 0 then |
488 |
> |
PortNo := system.Copy(ConnectString,RegexObj.MatchPos[2]+1,RegexObj.MatchLen[2]-1); |
489 |
> |
DatabaseName := RegexObj.Match[3]; |
490 |
> |
Protocol := NamedPipe |
491 |
> |
end |
492 |
> |
else |
493 |
> |
begin |
494 |
> |
Result := true; |
495 |
> |
Protocol := Local; {Assume local} |
496 |
> |
end; |
497 |
|
end; |
498 |
|
end; |
499 |
|
end; |
551 |
|
|
552 |
|
function MakeConnectString(ServerName, DatabaseName: AnsiString; |
553 |
|
Protocol: TProtocol; PortNo: AnsiString): AnsiString; |
554 |
+ |
|
555 |
+ |
function FormatURL: AnsiString; |
556 |
+ |
begin |
557 |
+ |
if (ServerName = '') and (Pos('/',DatabaseName) <= 1) then |
558 |
+ |
Result := DatabaseName |
559 |
+ |
else |
560 |
+ |
Result := ServerName + '/' + DatabaseName; |
561 |
+ |
end; |
562 |
+ |
|
563 |
|
begin |
564 |
|
if PortNo <> '' then |
565 |
|
case Protocol of |
579 |
|
SPX: Result := ServerName + '@' + DatabaseName; {do not localize} |
580 |
|
NamedPipe: Result := '\\' + ServerName + '\' + DatabaseName; {do not localize} |
581 |
|
Local: Result := DatabaseName; {do not localize} |
582 |
< |
inet: Result := 'inet://' + ServerName + '/'+ DatabaseName; {do not localize} |
583 |
< |
wnet: Result := 'wnet://' + ServerName + '/'+ DatabaseName; {do not localize} |
584 |
< |
xnet: Result := 'xnet://' + ServerName + '/'+ DatabaseName; {do not localize} |
582 |
> |
inet: Result := 'inet://' + FormatURL; {do not localize} |
583 |
> |
inet4: Result := 'inet4://' + FormatURL; {do not localize} |
584 |
> |
inet6: Result := 'inet6://' + FormatURL; {do not localize} |
585 |
> |
wnet: Result := 'wnet://' + FormatURL; {do not localize} |
586 |
> |
xnet: Result := 'xnet://' + FormatURL; {do not localize} |
587 |
|
end; |
588 |
|
end; |
589 |
|
|