ODBC is a package to provide connectivity to databases supporting the
ODBC interface.  The package itself is platform independent and
provide access to any database for which a driver exists.  It has been
tested with MySQL and PostgreSQL on both Linux and Windows (and to
those DBMSs on Linux hosts from R under Windows), Oracle on Windows,
Microsoft Access, SQL Server and Excel spreadsheets and DBase files,
and users have reported success with connections to DB2.  We have also
used SQLite3 with sqliteodbc for simple tasks.

For installation, see file INSTALL in the sources.

Basic usage is covered in the R Data Import/Export manual.

Do be aware of the limitations on table and column names of various
databases and drivers.  SQL supports alphanumeric plus _ and up to 128
characters (but some DBMSs only support 32), and '.' and ' ' are
disallowed.  However, Access allows spaces, and Excel allows '.' in
column names in Excel which appear to get mapped to '#' by the driver.
It is your job and not the RODBC maintainers' to know about your DBMS
and ODBC driver, and it is inappropriate to ask them about such
questions.


ODBC under Windows
==================

ODBC is often installed by applications that can use this interface
(it is part of MDAC).  DSNs are usually set up using the control panel
('Data Sources (ODBC)' in the 'Administrative Tools' section on
2000/XP).  If using RGui a DSN can be prepared via dialog boxes using

R> channel <- odbcDriverConnect("")

and this is often the simplest way for new users to ODBC or for
rarely-used data sources.  There are convenience functions
odbcConnectAccess/Dbase/Excel to ease connecting to one of these
systems.  You do need the appropriate drivers installed, but the
Office 2007 versions can be downloaded from 
http://www.microsoft.com/downloads/details.aspx?FamilyID=7554f536-8c28-4598-9b72-ef94e038c891&DisplayLang=en


ODBC under Unix/Linux/Mac OS X
==============================

A (somewhat biased) tutorial on using unixODBC on Linux can be found at
http://www.easysoft.com/developer/interfaces/odbc/linux.html

DSNs are described in files: the user's file is ~/.odbc.ini.  Mine is:

gannet% cat .odbc.ini
[test]
Description     = testmysql
Driver          = MySQL
Trace           = No
TraceFile       =
Server          = localhost
Port            = 3306
Socket          =
Database        = test

[testpg]
Description     = testpg
Driver          = PostgreSQL
Trace           = No
TraceFile       =
ServerName      = localhost
UserName        = ripley
Port            = 5432
Socket          =
Database        = testdb

[sqlite3]
Description     = sqlite3
Driver          = sqlite3
Database	= /tmp/mysqlite3.db

This can be used via

R> channel <- odbcConnect("test")

as MySQL provides open access to the 'test' database, but for real
examples you will need to provide a uid and pwd entry as in

R> channel <- odbcConnect("test", uid="ripley", pwd="secret")

More sophisticated connections, e.g. to remote machines, can be built
using odbcDriverConnect or as DSNs.

Note that you need to ensure that .../etc/odbcinst.ini contains the
rest of the driver information.  (UnixODBC uses
/usr/local/etc/odbcinst.ini and iODBC /etc/odbcinst.ini, by
default. However, some RPM-based installations will differ: Fedora
uses /etc/odbcinst.ini) We have (with paths differing by platform)

gannet% cat /etc/odbcinst.ini
[MySQL]
Description    = ODBC for MySQL
Driver         = /usr/lib64/libmyodbc3.so
Setup          = /usr/lib64/libmyodbc3.so
FileUsage      = 1

[PostgreSQL]
Description     = ODBC for PostgreSQL
Driver          = /usr/lib64/psqlodbc.so
Setup           = /usr/lib64/psqlodbc.so
FileUsage       = 1

[sqlite3]
Description = sqliteodbc
Driver = /usr/local/lib64/libsqlite3odbc.so
Setup = /usr/local/lib64/libsqlite3odbc.so
FileUsage = 1

The Sqlite ODBC driver is from http://www.ch-werner.de/sqliteodbc/.
(UnixODBC allows Driver64 here to allow for different paths on 32-bit
and 64=bit platforms.)


One quirk to be watched is the use of connections to the DBMS via the
Unix sockets vs ports.  The PostgreSQL driver bundled with unixODBC
will use Unix sockets to 'localhost', but this driver seems unreliable
(see the ChangeLog).  The current driver will only use a TCP/IP port,
and to use that needs postmaster started with the -i flag (which is
not the default) and with tcp/ip enabled in the configuration file
(which is the default).

Users of unixODBC and iODBC can use graphical front ends (called
something like gODBCConfig and iodbcadm-gtk repspectively) to prepare
user and systems DSNs: they are reworkings of the Window's ODBC
administation multi-tabbed dialog box.  Both write in ~/.odbc.ini, in
slightly different formats.  A version of the iODBC administation
application is provided on Mac OS X as Applications/Utilities/ODBC
Administator.  iODBC also has a web-based DSN administrator.
