Objective: how to build MyODBC for Mac OS X and configure for use with iODBC

Introduction
============

This readme file describes the steps required to build a MyODBC driver
on Mac OS X.

Before this driver can be built you need to install the current version of
MySQL on your system. As building MySQL itself on Mac OS X falls outside
the context of this readme, we suggest you download a Darwin binary from:

	http://www.mysql.com/downloads/mysql-4.0.htm

As of writing the version of this package is:

	MySQL 4.0.14
	MacOS X 10.2 (Darwin 6.x) (PowerPC) (7.4M)


From the same site you can also download the latest MyODBC sources:

	http://www.mysql.com/downloads/api-myodbc-3.51.html	

As of writing the version of this package is:

	MyODBC 3.51.06
	Source Files (tar.gz) (314K)


Unpack this source code into a new directory.

There are who ways to build the MyODBC driver which we will both describe
in detail below:


Method 1 : using the iODBC frameworks
=====================================

1.  Install iODBC framework version

    Please read the file ../README.MACOSX for details on how to build
    and install the framework version of iODBC.


2.  Setting up the MyODBC source tree.

    To setup the MyODBC tree execute the following commands:

	$ cd MyODBC-3.51.06


    Then we can either use the supplied myodbc.configure.diff file from
    the iODBC project using the command:

	$ patch -p1 < myodbc.configure.diff

    or edit the file configure manually and replace every occurrence of

	String			Replace with

	-liodbc			-framework iODBC
	-liodbcinst		-framework iODBCinst
	isql.h			iODBC/isql.h
	isqlext.h		iODBC/isqlext.h
	isqltypes.h		iODBC/isqltypes.h
	sql.h			iODBC/sql.h
	sqlext.h		iODBC/sqlext.h
	sqltypes.h		iODBC/sqltypes.h
	iodbcinst.h		iODBCinst/iodbcinst.h
	

    After this we configure the source code using the following
    command:
 
	./configure --with-mysql-libs=XXX --with-mysql-includes=YYY

    where XXX and YYY need to be replaced with the correct paths to the
    MySQL libraries and header files.


    Edit the file myodbc3.h and replace every occurrence of:

	String			Replace with

	isql.h			iODBC/isql.h
	isqlext.h		iODBC/isqlext.h
	isqltypes.h		iODBC/isqltypes.h
	sql.h			iODBC/sql.h
	sqlext.h		iODBC/sqlext.h
	sqltypes.h		iODBC/sqltypes.h
	iodbcinst.h		iODBCinst/iodbcinst.h


    Edit the file myconf.h and make sure the following options are defined:

	HAVE_IODBCINST_H
	HAVE_ISQL_H
	HAVE_ISQLEXT_H
	HAVE_SQLGETPRIVATEPROFILESTRING

    If any of these options are not defined, change the line from:

	/* #undef HAVE_ISQL_H */

    into:

	#define HAVE_ISQL_H	1


    Finally, you need to tell to the build process to link the MyODBC driver
    against the iODBCinst framework. To achieve this goal, just edit the
    driver/Makefile, make a search on libmyodbc3_la_LIBADD, and append
    -Wl,-framework,iODBCinst at the end of this line.


3.  Building the MyODBC driver

    You can now execute the following command to build the driver:

	$ make

    As Mac OS X is only able to load at runtime only bundle libraries,
    you need to use the following command to build the actual MyODBC
    driver :

	$ cd driver
	$ cc -bundle -o libmyodbc.dylib *.lo -framework iODBCinst \
	  -L/usr/local/mysql/lib/mysql -lmysqlclient -lz

    Use this file libmyodbc.dylib as the driver.



Method 2 : using the iODBC Unix libraries
=========================================

1.  Install iODBC Unix version
 
    The iODBC package can also be build as a normal Unix type package
    using the following commands:

	$ ./configure --prefix=/usr
	$ make

    followed by installing the library as root using the command:

	# make install


2.  Setting up the MyODBC source tree.

    To setup the MyODBC tree execute the following commands:

	$ cd MyODBC-3.51.06


    After this we can configure the source code using the following 
    command:
 
	./configure --with-mysql-libs=XXX --with-mysql-includes=YYY

    where XXX and YYY need to be replaced with the correct paths to the
    MySQL libraries and header files.


3.  Building the MyODBC driver

    You can now execute the following command to build the driver:

	$ make

    As Mac OS X is only able to load at runtime only bundle libraries,
    you need to use the following command to build the actual MyODBC
    driver :

	$ cc -bundle -o libmyodbc.dylib *.lo -framework iODBCinst \
	  -L/usr/local/mysql/lib/mysql -lmysqlclient -lz

    Use this file libmyodbc.dylib to configure the driver in the next 
    section.


Configuring MyODBC Driver for use with iODBC
=============================================

To configure the MyODBC for use with iODBC the following actions should
be performed:

1.  From the MyODBC directory run the following command to install driver
    in '/usr/local/lib' as user root:

	$ cp libmyodbc.dylib /usr/local/lib


2.  Configure the MyODBC Driver by adding the following lines to
    /etc/odbcinst.ini:

	[ODBC Drivers]
	MyODBC Driver = Installed

	[MyODBC Driver]
	Driver = /usr/local/lib/libmyodbc.dylib


3.  Configure MyODBC Driver ODBC DSN by adding the following lines to
    either /etc/odbc.ini or $HOME/.odbc.ini:

	[ODBC Data Sources]
	MyODBCDSN = MyODBC Driver

	[MyODBCDSN]
	Driver = /usr/local/lib/libmyodbc.dylib
	Port = 3306
	UID = mysql

     *** Please note that the DSN ie MyODBCDSN, must be the name of a
         valid MySQL Database for the Database Server the connection
         attempt is being made to.


4.  A test connection can now be made to the MySQL Database using the
    following sample program bundled with the iODBC SDK:

	/usr/local/bin/odbctest
	OpenLink ODBC Demonstration program
	This program shows an interactive SQL processor

	Enter ODBC connect string (? shows list): ?

	DSN                            | Driver
	---------------------------------------------------------------

	MyODBCDSN                      | MyODBC Driver

	Enter ODBC connect string (? shows list): 

    Use the following string:

	DSN=MyODBCDSN;UID=mysql;PWD=xxxx

	Driver: 02.50.39 

	SQL> select * from <table_name>

