Tim
Goeke
Thomas
Lockhart
1998-08-25
ODBC Interface
Background information originally by
Tim Goeke
ODBC (Open Database Connectivity) is an abstract
API
which allows you to write standard "ODBC" applications.
ODBC provides a product-neutral interface
between frontend applications and database servers,
allowing a user or developer to write applications which are portable among servers.
Background
The ODBC API matches up
on the backend to an ODBC-compatible data source.
This could be anything from a text file to an Oracle or
Postgres RDBMS.
The backend access come from ODBC drivers, or vendor specifc drivers that
allow data access. psqlODBC is such a driver, along with others that are
available, such as the OpenLink ODBC drivers.
Once you write an ODBC application, you SHOULD be able to connect to ANY
back end database, regardless of the vendor, as long as the database schema
is the same.
For example. you could have MS SQL Server
and Postgres servers which have
exactly the same data. Using ODBC, your Windows app would make exactly the
same calls and the back end data source would look the same (to the windows
app).
Insight Distributors provides active and ongoing
support for the core psqlODBC distribution. They provide a
FAQ, ongoing development
on the code base, and actively participate on the
interfaces mailing list.
Windows Applications
In the real world, differences in drivers and the level of ODBC support
lessens the potential of ODBC:
Access, Delphi, and Visual Basic all support ODBC directly.
Under C++, such as Visual C++, you can use the C++ ODBC API.
In Visual C++, you can use the CRecordSet class, which wraps the
ODBC API
set within an MFC 4.2 class. This is the easiest route if you are doing
Windows C++ development under Windows NT.
If I write an app for Postgres
can I write it using ODBC calls
to the Postgres server, or is that only when another database program
like MS SQL Server or Access needs to access the data?
Again, the ODBC API set is the way to go.
You can find out more at
Microsoft's web site or in your Visual C++ docs (if that's what you are using.)
Visual Basic and the other RAD tools have Recordset objects that use ODBC
directly to access data. Using the data-aware controls, you can quickly
link to the ODBC back end database (very quickly).
Playing around with MS Access will help you sort this out. Try using
File->Get External Data
You'll have to set up a DSN first.
Unix Applications
ApplixWare has an ODBC database interface
supported on at least some platforms. ApplixWare v4.4.1 has been
demonstrated under Linux with Postgres v6.4
using the psqlODBC
driver contained in the Postgres distribution.
Configuration Files
The ~/.odbc.ini contains user-specified access information
for the psqlODBC
driver. The file uses conventions typical for Windows
Registry files, but despite this
restriction can be made to work.
Here is an example .odbc.ini file,
showing access information for three databases:
[ODBC Data Sources]
DataEntry = Read/Write Database
QueryOnly = Read-only Database
Test = Debugging Database
Default = Postgres Stripped
[DataEntry]
ReadOnly = 0
Servername = localhost
Database = Sales
[QueryOnly]
ReadOnly = 1
Servername = localhost
Database = Sales
[Test]
Debug = 1
CommLog = 1
ReadOnly = 0
Servername = localhost
Username = tgl
Password = "no$way"
Port = 5432
Database = test
[Default]
Servername = localhost
Database = tgl
Driver = /opt/postgres/current/lib/libpsqlodbc.so
[ODBC]
InstallDir = /opt/applix/axdata/axshlib
For Applix, here is an example ~/axhome/macros/login.am file:
macro login
set_set_system_var@("sql_username@","tgl")
set_system_var@("sql_passwd@","no$way")
endmacro
Supported Platforms
psqlODBC has been built and tested
on Linux. There have been reports of success
with FreeBSD and with Solaris.