Create an ODBC entry for an Oracle database

From NSIS Wiki
Jump to navigationJump to search
Author: preisl (talk, contrib)


The Script

;
; Create an Oracle ODBC Entry
;
; Requres: OracleDefaultHome, ValidOracleHome, ODBCEntryExists
;   Input: Name of the ODBC entry
;          Oracle server name (TNSNAME)
;  Output: TRUE,FALSE
;
; Usage:
;
;    Push "ORACLETEST"
;    Push "NTW"
;    Call CreateOracleODBCEntry
;    Pop $1
;    MessageBox MB_OK|MB_ICONINFORMATION "Oracle ODBC entry 'ORACLETEST' created: $1"
;
 
Function CreateOracleODBCEntry
  Exch $R2          ; Server Name
  Exch
  Exch $R3          ; Name of the ODBC Entry
 
  ; Save Registers R0,R1
  Push $R0
  Push $R1
  Push $R4
 
  ; Try to find an Oracle home directory
  Call OracleDefaultHome
  Pop $R0
  StrCmp $R0 "" FindAnyValidOracleHome CheckForODBCDriverExistence
 
  ; Find any valid home, if there is no valid default home
  FindAnyValidOracleHome:
    Call ValidOracleHome
    Pop $R0
    StrCmp $R0 "" NoOracleHomeFound CheckForODBCDriverExistence
 
  ; Check whether the ODBC entry already exists
  CheckForODBCDriverExistence:
    Push $R3
    Call ODBCEntryExists
    Pop $R1
    StrCmp $R1 "TRUE" ODBCEntryAlreadyExists
 
    ; Get the path of the Oracle home
    Push $R0
    Call OracleHomePath
    Pop $R4
 
    ; Create the registry keys
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "Driver" "$R4\bin\sqora32.dll"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "Translation DLL" ""
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "Translation Option" "0"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "Attributes" "W"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "FetchBufferSize" "64000"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "NumericSetting" "NLS"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "ForceWCHAR" "F"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "FailoverDelay" "10"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "FailoverRetryCount" "10"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "MetadataIdDefault" "F"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "Longs" "F"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "CloseCursor" "F"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "EXECSchemaOpt" ""
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "EXECSyntax" "F"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "Application Attributes" "T"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "SQLGetData extensions" "F"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "ResultSets" "T"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "QueryTimeout" "T"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "Failover" "T"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "Lobs" "T"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "DisableMTS" "F"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "BatchAutocommitMode" "IfAllSuccessful"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "Description" ""
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "ServerName" "$R2"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "Password" ""
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "UserID" ""
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\$R3" "DSN" "$R3"
    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources" "$R3" "Oracle in $R0"
    StrCpy $R2 "TRUE"
    Goto Done
 
  ODBCEntryAlreadyExists:
    StrCpy $R2 "FALSE"
    Goto Done
 
  NoOracleHomeFound:
    StrCpy $R2 "FALSE"
 
  Done:
 
  ; Restore R0-R4
  Pop $R4
  Pop $R1
  Pop $R0
  Pop $R3
  Exch $R2
 
FunctionEnd