Check whether an ODBC entry exists: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library)
 
m (Reverted edits by 200.208.233.130 to last version by ConversionBot)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{PageAuthor|preisl}}
== The Function ==
== The Function ==
<highlight-nsis>
<highlight-nsis>
;
;
; Check wether an ODBC entry exists or not
; Check whether an ODBC entry exists or not
;
;
;  Input: Name of the ODBC entry
;  Input: Name of the ODBC entry
Line 52: Line 54:
</highlight-nsis>
</highlight-nsis>


Page author: preisl
[[Category:Database Functions]]

Latest revision as of 22:30, 4 December 2008

Author: preisl (talk, contrib)


The Function

;
; Check whether an ODBC entry exists or not
;
;  Input: Name of the ODBC entry
; Output: TRUE, FALSE
;
; Usage
;
;    Push "MyODBCEntry"
;    Call ODBCEntryExists
;    Pop "$1"
;    MessageBox MB_OK|MB_ICONINFORMATION "ODBC entry 'MyODBCEntry' exists: $1"
;
 
!macro ODBCEntryExistsMacro
 
  ; Clear all errors at the beginning
  ClearErrors
  ; Pop the name of the ODBC entry from the stack
  Exch $R0
 
  IfErrors InvalidParameter CheckODBCEntry
  InvalidParameter:
    MessageBox MB_OK|MB_ICONEXCLAMATION "ODBCEntryExists: Please push the name of the ODBC entry first."
    StrCpy $R0 "FALSE"
    Goto Done
  CheckODBCEntry:
    ClearErrors
    ReadRegStr $R0 HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources" "$R0"
    IfErrors NotFound Found
    NotFound:
      StrCpy $R0 "FALSE"
      Goto Done
    Found:
      StrCpy $R0 "TRUE"
      Goto Done
  Done:
 
  Exch $R0
 
!macroend
 
Function ODBCEntryExists
  !insertmacro ODBCEntryExistsMacro
FunctionEnd
 
Function un.ODBCEntryExists
  !insertmacro ODBCEntryExistsMacro
FunctionEnd