Re: Using ODBC database
"Jonathan Blitz" <jb@anykey.co.il> wrote in message
news:uEaQ4hNhGHA.764@TK2MSFTNGP03.phx.gbl...
I am using a PostgreSQL database and want to connect to it using ODBC.
OK.
I have used an external ODBC connector (libodbc++) to connect. This works
perfectly for fetching data.
I'm not familiar with that class library. Just btw I don't recall having
seen it discussed here.
So - I created a database source using the wizard and use it as a basis to
get data. This works ok but I cannot see how to switch between different
datasources. I tried editing the connection string but it still goes to
the
original data source.
I also looked at the online doctumentation and it talks about the
CDatabase
class and that seems to be different again!
So, what am I supposed to be using?
Well, you can use a class library or you can use the native ODBC API. In
either case you probably should search for a more appropriate group to post
the question.
That said, I can't help with libodbc or MFC's ODBC classes but at the level
of the API this is the deal:
You allocate a "environment" handle with
SQLAllocHandle(SQL_HANDLE_ENV, ...);
That makes your application a consumer of ODBC services. Within that
environment you can create one or more database "connections". You do that
by calling
SQLAllocHandle(SQL_HANDLE_DBC, ...)
to get an "empty" (my word) handle to a database connection. That done you
can use any of a number of services to connect to a DBMS. Among them is
SQLDriverConnect() which can optionally display dialogs if you have an
"incomplete" (my word) connection string.
Now once you have a connection, you can pass the connection handle to
SQLAllocHandle(SQL_HANDLE_STMT, ...)
to retrieve a statement handle. If you have multiple datasources you just
allocate multiple connection handles, on each connect to a data source and
create a statement handle. The SQL statements that you "prepare" or
"execute" on those statement handles are routed by ODBC to the proper data
source.
--
Regards,
Will
"I'm not ready to make nice, I'm not ready to back down ..."