Get Oracle TNS Connection Names: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library) |
|||
(6 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{PageAuthor|Iceman_K}} | |||
Required Functions: | Required Functions: | ||
[[GetDefaultOracleHomePath]] | [[Get Default Oracle Home Path|GetDefaultOracleHomePath]] | ||
[[Trim]] | [[Trim]] | ||
Line 36: | Line 38: | ||
; The path of the TNS names file | ; The path of the TNS names file | ||
StrCpy $R2 "$R2 | StrCpy $R2 "$R2\network\admin\tnsnames.ora" | ||
; Open the TNS names file | ; Open the TNS names file | ||
Line 64: | Line 65: | ||
StrCmp $R7 " " whitespace | StrCmp $R7 " " whitespace | ||
StrCmp $R7 " " whitespace | StrCmp $R7 " " whitespace | ||
StrCmp $R7 "$
" whitespace | StrCmp $R7 "$\r" whitespace | ||
StrCmp $R7 "$ | StrCmp $R7 "$\n" whitespace | ||
" whitespace | |||
StrCmp $R7 "(" openparen | StrCmp $R7 "(" openparen | ||
StrCmp $R7 ")" closeparen | StrCmp $R7 ")" closeparen | ||
Line 76: | Line 76: | ||
StrCmp $R8 " " syntaxerror | StrCmp $R8 " " syntaxerror | ||
StrCmp $R8 " " syntaxerror | StrCmp $R8 " " syntaxerror | ||
StrCmp $R8 "$
" syntaxerror | StrCmp $R8 "$\r" syntaxerror | ||
StrCmp $R8 "$ | StrCmp $R8 "$\n" syntaxerror | ||
" syntaxerror | |||
blank: | blank: | ||
StrCpy $R6 "$R6$R7" | StrCpy $R6 "$R6$R7" | ||
Line 131: | Line 130: | ||
</highlight-nsis> | </highlight-nsis> | ||
[[Category:Database Functions]] |
Latest revision as of 16:55, 17 April 2009
Author: Iceman_K (talk, contrib) |
Required Functions: GetDefaultOracleHomePath Trim
The Script
; ; Returns the list of Oracle TNS Connection Names separated by the ; pipe ("|") symbol, suitable for setting the ListItems attribute ; in an InstallOptions DropList. ; ; Requires: GetDefaultOracleHomePath ; Requires: Trim ; ; Usage: ; ; Call GetOracleConnections ; Pop $0 ; Function GetOracleConnections ClearErrors Push $R1 ;The connection list Push $R2 ;Line read from tnsnames.ora Push $R3 ;File handle Push $R4 ;Flag indicating whether connection name has been captured Push $R5 ;Parentheses count Push $R6 ;Current connection name Push $R7 ;Character being currently processed Push $R8 ;Temp var StrCpy $R1 "" Call GetOracleDefaultHomePath Pop $R2 StrCmp $R2 "" done ; The path of the TNS names file StrCpy $R2 "$R2\network\admin\tnsnames.ora" ; Open the TNS names file StrCpy $R3 "" FileOpen $R3 $R2 "r" StrCmp $R3 "" fileerror ClearErrors StrCpy $R1 "" reset: ; Reset variables StrCpy $R4 "0" StrCpy $R5 "0" StrCpy $R6 "" read: ; Read a line from the file FileRead $R3 $R2 StrCmp $R2 "" 0 loop IfErrors closefile read ; Loop through the characters in the line just read loop: StrCpy $R7 $R2 1 StrCmp $R7 "" read StrCpy $R2 $R2 "" 1 StrCmp $R7 "#" comment StrCmp $R7 " " whitespace StrCmp $R7 " " whitespace StrCmp $R7 "$\r" whitespace StrCmp $R7 "$\n" whitespace StrCmp $R7 "(" openparen StrCmp $R7 ")" closeparen StrCmp $R7 "=" equal StrCmp $R4 "1" loop append: StrCmp $R6 "" blank StrCpy $R8 $R6 1 -1 StrCmp $R8 " " syntaxerror StrCmp $R8 " " syntaxerror StrCmp $R8 "$\r" syntaxerror StrCmp $R8 "$\n" syntaxerror blank: StrCpy $R6 "$R6$R7" GoTo loop comment: StrCmp $R6 "" read StrCmp $R4 "1" read syntaxerror whitespace: StrCmp $R6 "" loop StrCmp $R4 "1" loop append equal: StrCmp $R4 "1" loop StrCpy $R4 "1" GoTo loop openparen: StrCmp $R4 "1" 0 syntaxerror IntOp $R5 $R5 + 1 GoTo loop closeparen: StrCmp $R4 "1" 0 syntaxerror IntOp $R5 $R5 - 1 IntCmp $R5 0 0 syntaxerror loop Push $R1 Call Trim Pop $R1 StrCmp $R1 "" +2 StrCpy $R1 "$R1|" StrCpy $R1 "$R1$R6" GoTo reset closefile: FileClose $R3 GoTo done fileerror: MessageBox MB_OK "File access error: tnsnames.ora." StrCpy $R1 "" GoTo done syntaxerror: MessageBox MB_OK "File syntax error: tnsnames.ora." StrCpy $R1 "" StrCmp $R3 "" +2 FileClose $R3 done: Pop $R8 Pop $R7 Pop $R6 Pop $R5 Pop $R4 Pop $R3 Pop $R2 Exch $R1 FunctionEnd