#138725 - 2005-04-26 07:41 PM
MySQLODBC() usage questions
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
MySQLODBC()
1. What does this UDF do? After reading through the UDF post, I'm a little confused as to what this actually does. It sounds like it does two things, checks to see if the MySQL ODBC drivers are installed and also executes a query???
2. How do I just check a target machine to see if they have the MySQL ODBC drivers installed and if not, install them?
3. Would each person running this script need admin rights to install the MySQL ODBC drivers?
Thank you in advance...
|
Top
|
|
|
|
#138726 - 2005-04-26 08:33 PM
Re: MySQLODBC() usage questions
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
piper,
This UDF automates the ODBC Configuration and creates a DSN in the Control Panel..
If you want to simply look for the existence of a MySQLODBC Driver, then you could simply look for the following file - Code:
IF EXIST('%WINDIR%\System32\myodbc3.dll') ; do something ELSE ; do something else ENDIF
HTH,
Kent
|
Top
|
|
|
|
#138728 - 2005-04-26 08:40 PM
Re: MySQLODBC() usage questions
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Looking back at the UDF under dependencies, you are going to need 3 files:
- myodbc3.dll "%windir%\system32\myodbc3.dll"
- myodbc3d.dll "%windir%\system32\myodbc3d.dll"
- my3dsn.hlp "%windir%\help\my3dsn.hlp"
HTH,
Kent
|
Top
|
|
|
|
#138732 - 2005-04-26 09:36 PM
Re: MySQLODBC() usage questions
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
In our Hand dandy - KiXtart FAQ & How to's
We see how we can deploy apps/files/etc. as an Admin - Installing an Application as an Admin
Also, if you have a list of systems on your Domain, you can copy the files from say your desktop too.
HTH,
Kent
|
Top
|
|
|
|
#138735 - 2005-05-03 05:22 PM
Re: MySQLODBC() usage questions
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
Tried multiple things and am still having problems. I first off tried to write a script that would copy the three pertinent files for the MySQL ODBC drivers to all of my machines and that worked but when my script is run against them, they get an error about the provider not being available or something. And on those same systems, if I go ahead and run the .msi from MySQL on the system and then re-run the script, it runs fine so I know it has to do with the fact that I'm not copying everything that needs to be copies to the different machines. Here is the code I was using to copy the three files to the System32 directory:
Code:
;COPY MYSQL ODBC DRIVERS TO TARGET SYSTEM SO THEY CAN WRITE TO THE DATABASE IF NOT EXIST('%WINDIR%\System32\myodbc3.dll') COPY \\gjlk2w2ws101\softwarepushes\sms\myodbc3.dll %windir%\System32\ ENDIF
IF NOT EXIST('%WINDIR%\System32\my3dsn.hlp') COPY \\gjlk2w2ws101\softwarepushes\sms\my3dsn.hlp %windir%\System32\ ENDIF
IF NOT EXIST('%WINDIR%\System32\myodbc3S.dll') COPY \\gjlk2w2ws101\softwarepushes\sms\myodbc3S.dll %windir%\System32\ ENDIF
Then, since I figured that wouldn't work and I was using SMS to run this script anyways, I decided I'd just try to push the MySQL msi for the ODBC drivers through SMS also. So I created the package and it just sat in the background because it was waiting for user input. I researched the MSI on MySQL's site and couldn't find command-line switches for this file and then tried to use the command lines associated with msiexec and it turns out that there are no switches for windows installer version 2.0 and below? And myself and only a few others are using SP2 which ships windows installer version 3.0 that has command line switches! And while I can run the file with the /quiet switch, it's still running in my processes so I guess it's still waiting for user input?
So I guess my questions are this. For SMS, what else do I need to add to my script so that I can push it out to all of my systems and have it install the MySQL ODBC drivers OR what do I need to do to get a silent install of the msi???
Thanx in advance!
|
Top
|
|
|
|
#138736 - 2005-05-03 06:53 PM
Re: MySQLODBC() usage questions
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
piper,
Why aren't you surronding the source and destination of the COPY Command with Quotes?
If we look at the docs, we see: Code:
COPY "S:\MyDir\*.*" "S:\NewDir\*.*"
So, shouldn't your code be: Code:
;COPY MYSQL ODBC DRIVERS TO TARGET SYSTEM SO THEY CAN WRITE TO THE DATABASE IF NOT EXIST('%WINDIR%\System32\myodbc3.dll') COPY '\\gjlk2w2ws101\softwarepushes\sms\myodbc3.dll' '%windir%\System32' ENDIF
IF NOT EXIST('%WINDIR%\help\my3dsn.hlp') COPY '\\gjlk2w2ws101\softwarepushes\sms\my3dsn.hlp' '%windir%\help' ENDIF
IF NOT EXIST('%WINDIR%\System32\myodbc3S.dll') COPY '\\gjlk2w2ws101\softwarepushes\sms\myodbc3S.dll' '%windir%\System32' ENDIF
Note: I made a small change with the HLP file as it should go in the Help folder.
HTH,
Kent
|
Top
|
|
|
|
#138738 - 2005-05-03 07:30 PM
Re: MySQLODBC() usage questions
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Since we don't have MySQL here in house, you will have to test it out to be sure that it works.
Kent
|
Top
|
|
|
|
#138741 - 2005-05-03 08:23 PM
Re: MySQLODBC() usage questions
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
OK.. If we go back and look at the original post you made on this, you were asking how to make an ODBC Connnection. Is that still the case?
MySQLODBC() - Creates a ODBC connection to MySQL
If so, then yes, you do need to make some changes to the Reigstry.
I Took the liberty of modifying the ODBC code..
going to http://mysql.com , we find the new version of the ODBC driver to be - 3.51.11.
Code:
; Function: MySQLODBC() ; ; Author: Martijn (martijn@raceeend.com) ; ; Version: 1.0 ; ; Action: - Checks if MyODBC is installed. If not it will be installed. ; - Creates a ODBC connection to MySQL ; ; Syntax: $ADOdb = MySQLODBC($DataSourceName, $Description, $Option, $SourcePath, Optional $DBName, Optional $Pwd, Optional $Port, Optional $Server, Optional $Stmt, Optional $user) ; ; Parameters: ; Required ; $DataSourceName: Data Source Name of the connection ; $Description: Description of Data Source Name ; $Option: Used to select options which have affect on the drivers behaviours ; $SourcePath: Path where MyODBC files are located ; Optional ; $DBName: Database to connect to ; $Pwd: Password of database ; $Port: TCP Port used by MySQL ; $Server: IpAdress of MySQL server ; $Stmt: SQL statement which executes on connection ; $user: User which connects to database ; ; Dependencies: MyODBC files myodbc3.dll, myodbc3d.dll, my3dsn.hlp. Oh and a MySQL server http://mysql.com ; ; Remarks: Tested on Win2k with Kix 4.12 ; ; Example: $DataSourceName = "MySQL-ADODB" ; $Description = "MySQL ADODB connection" ; $Option = "3" ;Default MySQL option ; $Server = "10.0.0.1" ; $SourcePath = "\\server\share\" ; ; $ADOdb = MySQLODBC($DataSourceName, $Description, $Option, $SourcePath,,,, $Server,,)
Function MySQLODBC($DSN, $Description, $Option, $SourcePath, Optional $DBName, Optional $Pwd, Optional $Port, Optional $Server, Optional $Stmt, Optional $user) Dim $ConnKey Dim $Driver Dim $RegKey $ConnKey = "HKCU\Software\ODBC\ODBC.INI\" $Driver = "%windir%\System32\myodbc3.dll" $RegKey = "HKLM\Software\ODBC\ODBCINST.INI\MySQL ODBC 3.51 Driver" If NOT Exist("%windir%\system32\myodbc3.dll") Copy $SourcePath+"myodbc3.dll" "%windir%\system32\myodbc3.dll" EndIf If NOT Exist("%windir%\help\my3dsn.hlp") Copy $SourcePath+"my3dsn.hlp" "%windir%\help\my3dsn.hlp" EndIf If NOT Exist("%windir%\system32\myodbc3d.dll") Copy $SourcePath+"myodbc3d.dll" "%windir%\system32\myodbc3d.dll" EndIf IF ReadValue("HKLM\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers","MySQL ODBC 3.51 Driver")<>"Installed" $x=WriteValue("HKLM\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers","MySQL ODBC 3.51 Driver","Installed","REG_SZ") EndIf IF ReadValue($RegKey,"UsageCount")<>12 $x=WriteValue($RegKey,"UsageCount",12,"REG_DWORD") EndIf IF ReadValue($RegKey,"Driver")<>"%windir%\System32\myodbc3.dll" $x=WriteValue($RegKey,"Driver","%windir%\System32\myodbc3.dll","REG_SZ") EndIf IF ReadValue($RegKey,"Setup")<>"%windir%\System32\myodbc3.dll" $x=WriteValue($RegKey,"Setup","%windir%\System32\myodbc3.dll","REG_SZ") EndIf IF ReadValue($RegKey,"APILevel")<>2 $x=WriteValue($RegKey,"APILevel",2,"REG_SZ") EndIf IF ReadValue($RegKey,"ConnectFunctions")<>"YYN" $x=WriteValue($RegKey,"ConnectFunctions","YYN","REG_SZ") EndIf IF ReadValue($RegKey,"DriverODBCVer")<>"03.51" $x=WriteValue($RegKey,"DriverODBCVer","03.51","REG_SZ") EndIf IF ReadValue($RegKey,"FileUsage")<>0 $x=WriteValue($RegKey,"FileUsage",0,"REG_SZ") EndIf IF ReadValue($RegKey,"FileExtns")<>"*.txt" $x=WriteValue($RegKey,"FileExtns","*.txt","REG_SZ") EndIf IF ReadValue($RegKey,"SQLLevel")<>1 $x=WriteValue($RegKey,"SQLLevel",1,"REG_SZ") EndIf IF ReadValue($RegKey,"CPTimeout")<>60 $x=WriteValue($RegKey,"CPTimeout",60,"REG_SZ") EndIf IF ReadValue($RegKey,"DNSHelpFile")<>"%windir%\help\my3dsn.hlp" $x=WriteValue($RegKey,"DNSHelpFile","%windir%\help\my3dsn.hlp","REG_SZ") EndIf IF ReadValue("HKLM\Software\ODBC\ODBCINST.INI\ODBC Core","UsageCount")<>1 $x=WriteValue("HKLM\Software\ODBC\ODBCINST.INI\ODBC Core","UsageCount",1,"REG_DWORD") EndIf IF ReadValue($ConnKey+"ODBC Data Sources",$DSN)<>"MySQL ODBC 3.51 Driver" $w = WriteValue($ConnKey+"ODBC Data Sources",$DSN,"MySQL ODBC 3.51 Driver","REG_SZ") EndIf IF ReadValue($ConnKey+$DSN,"Description")<>$Description $w = WriteValue($ConnKey+$DSN,"Description",$Description,"REG_SZ") EndIf IF ReadValue($ConnKey+$DSN,"Database")$DatabaseName $w = WriteValue($ConnKey+$DSN,"Database",$DBName,"REG_SZ") EndIf IF ReadValue($ConnKey+$DSN,"Driver")<>$Driver $w = WriteValue($ConnKey+$DSN,"Driver",$Driver,"REG_SZ") EndIf IF ReadValue($ConnKey+$DSN,"Option")<>$Option $w = WriteValue($ConnKey+$DSN,"Option",$Option,"REG_SZ") EndIf IF ReadValue($ConnKey+$DSN,"Password")<>$Pwd $w = WriteValue($ConnKey+$DSN,"Password",$Pwd,"REG_SZ") EndIf IF ReadValue($ConnKey+$DSN,"Port")<>$Port $w = WriteValue($ConnKey+$DSN,"Port",$Port,"REG_SZ") EndIf IF ReadValue($ConnKey+$DSN,"Server")<>$Server $w = WriteValue($ConnKey+$DSN,"Server",$Server,"REG_SZ") EndIf IF ReadValue($ConnKey+$DSN,"Stmt")<>$Stmt $w = WriteValue($ConnKey+$DSN,"Stmt",$Stmt,"REG_SZ") EndIf IF ReadValue($ConnKey+$DSN,"User")<>$User $w = WriteValue($ConnKey+$DSN,"User",$User,"REG_SZ") EndIf EndFunction
HTH,
Kent
Edited by kdyer (2005-05-03 08:57 PM)
|
Top
|
|
|
|
#138742 - 2005-05-03 08:55 PM
Re: MySQLODBC() usage questions
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
We can take this a step further, if you want just the drivers and to be "registered" you can do the following: Code:
FUNCTION MYSQLODBCDRIVER() DIM $sourcepath,$connkey,$driver,$regkey,$x $sourcepath=@ldrive+'\programs' $connkey = "HKCU\Software\ODBC\ODBC.INI\" $driver = "%windir%\System32\myodbc3.dll" $regkey = "HKLM\Software\ODBC\ODBCINST.INI\MySQL ODBC 3.51 Driver"
IF NOT Exist("%windir%\system32\myodbc3.dll") COPY $sourcepath+"myodbc3.dll" "%windir%\system32\myodbc3.dll" ENDIF IF NOT Exist("%windir%\help\my3dsn.hlp") COPY $sourcepath+"my3dsn.hlp" "%windir%\help\my3dsn.hlp" ENDIF IF NOT Exist("%windir%\system32\myodbc3d.dll") COPY $sourcepath+"myodbc3d.dll" "%windir%\system32\myodbc3d.dll" ENDIF IF ReadValue("HKLM\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers","MySQL ODBC 3.51 Driver")<>"Installed" $x=WriteValue("HKLM\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers","MySQL ODBC 3.51 Driver","Installed","REG_SZ") ENDIF IF ReadValue($regkey,"UsageCount")<>12 $x=WriteValue($regkey,"UsageCount",12,"REG_DWORD") ENDIF IF ReadValue($regkey,"Driver")<>"%windir%\System32\myodbc3.dll" $x=WriteValue($regkey,"Driver","%windir%\System32\myodbc3.dll","REG_SZ") ENDIF IF ReadValue($regkey,"Setup")<>"%windir%\System32\myodbc3.dll" $x=WriteValue($regkey,"Setup","%windir%\System32\myodbc3.dll","REG_SZ") ENDIF IF ReadValue($regkey,"APILevel")<>2 $x=WriteValue($regkey,"APILevel",2,"REG_SZ") ENDIF IF ReadValue($regkey,"ConnectFunctions")<>"YYN" $x=WriteValue($regkey,"ConnectFunctions","YYN","REG_SZ") ENDIF IF ReadValue($regkey,"DriverODBCVer")<>"03.51" $x=WriteValue($regkey,"DriverODBCVer","03.51","REG_SZ") ENDIF IF ReadValue($regkey,"FileUsage")<>0 $x=WriteValue($regkey,"FileUsage",0,"REG_SZ") ENDIF IF ReadValue($regkey,"FileExtns")<>"*.txt" $x=WriteValue($regkey,"FileExtns","*.txt","REG_SZ") ENDIF IF ReadValue($regkey,"SQLLevel")<>1 $x=WriteValue($regkey,"SQLLevel",1,"REG_SZ") ENDIF IF ReadValue($regkey,"CPTimeout")<>60 $x=WriteValue($regkey,"CPTimeout",60,"REG_SZ") ENDIF IF ReadValue($regkey,"DNSHelpFile")<>"%windir%\help\my3dsn.hlp" $x=WriteValue($regkey,"DNSHelpFile","%windir%\help\my3dsn.hlp","REG_SZ") ENDIF IF ReadValue("HKLM\Software\ODBC\ODBCINST.INI\ODBC Core","UsageCount")<>1 $x=WriteValue("HKLM\Software\ODBC\ODBCINST.INI\ODBC Core","UsageCount",1,"REG_DWORD") ENDIF ENDFUNCTION
If you need to create just the ODBC connector, provided the drivers are installed - above, then you can do the following (note: the $user parameter added for adding a global or system-wide DSN): Code:
FUNCTION MYSQLODBC($dsn, $description, $option, $sourcepath, OPTIONAL $user, OPTIONAL $dbname, OPTIONAL $pwd, OPTIONAL $port, OPTIONAL $server, OPTIONAL $stmt, OPTIONAL $user) DIM $w,$connkey IF $user $connkey = "HKCU\Software\ODBC\ODBC.INI\" ELSE $connkey = "HKLM\Software\ODBC\ODBC.INI\" ENDIF IF ReadValue($connkey+"ODBC Data Sources",$dsn)<>"MySQL ODBC 3.51 Driver" $w=WriteValue($connkey+"ODBC Data Sources",$dsn,"MySQL ODBC 3.51 Driver","REG_SZ") ENDIF IF ReadValue($connkey+$dsn,"Description")<>$description $w=WriteValue($connkey+$dsn,"Description",$description,"REG_SZ") ENDIF IF ReadValue($connkey+$dsn,"Database")$DatabaseName $w=WriteValue($connkey+$dsn,"Database",$dbname,"REG_SZ") ENDIF IF ReadValue($connkey+$dsn,"Driver")<>$driver $w=WriteValue($connkey+$dsn,"Driver",$driver,"REG_SZ") ENDIF IF ReadValue($connkey+$dsn,"Option")<>$option $w=WriteValue($connkey+$dsn,"Option",$option,"REG_SZ") ENDIF IF ReadValue($connkey+$dsn,"Password")<>$pwd $w=WriteValue($connkey+$dsn,"Password",$pwd,"REG_SZ") ENDIF IF ReadValue($connkey+$dsn,"Port")<>$port $w=WriteValue($connkey+$dsn,"Port",$port,"REG_SZ") ENDIF IF ReadValue($connkey+$dsn,"Server")<>$server $w=WriteValue($connkey+$dsn,"Server",$server,"REG_SZ") ENDIF IF ReadValue($connkey+$dsn,"Stmt")<>$stmt $w=WriteValue($connkey+$dsn,"Stmt",$stmt,"REG_SZ") ENDIF IF ReadValue($connkey+$dsn,"User")<>$user $w=WriteValue($connkey+$dsn,"User",$user,"REG_SZ") ENDIF ENDFUNCTION
HTH,
Kent
Edited by kdyer (2005-05-03 08:59 PM)
|
Top
|
|
|
|
#138744 - 2005-05-03 10:59 PM
Re: MySQLODBC() usage questions
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Hmm..
Try one of the following: inctrl5.zip http://www.devhood.com/tools/tool_details.aspx?tool_id=432 tool_details.aspx-tool_id=432
http://regshot.yeah.net/ Regshot
On second thought, rather than "hacking" this together (I just did a RegShot) and installed the MSI from http://mysql.com and it adds in 97 registry entries.. You should really do something like: Code:
IF 0=Exist('%windir%\system32\myodbc3d.dll') RUN 'MsiExec.exe /i @ldrive+"Programs\MySql.msi" /qn' ENDIF
HTH,
Kent
Edited by kdyer (2005-05-03 11:10 PM)
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
2 registered
(morganw, mole)
and 414 anonymous users online.
|
|
|