Download demo project - 20 Kb
I have written a lot of database apps. Most of them have been small, and I soon realized that
CRecordset class was the only class requiring MFC for the majority of those apps. So, I
sat down and wrote these classes to provide most of the functionality I needed and so I could
get rid of MFC dependancies.
These classes are extremely basic, and provide little use for someone who does not use the
ODBC API directly. However, for those of you that do use the API, you might find them useful.
There are three classes in this collection,
CODBCFatQuery (you can find them all in the files ODBC.h and ODBC.cpp.)
the most complex (so far), it creates the connections to the DBMS and allows you to easily share those connections.
CODBCFatQuery really don't do much yet, but sometime in the near future
I plan on adding functionality to them. For now, they are basically coming along for the ride, because they are
in the same files ;)
CODBCCnx provides three functions,
Connect() function allows you to connect either through a DSN or by
using the computer's network name.
CODBCCnx name("SQL Server","CompName","username","password");
Ok so now we are connected, lets disconnect from the database. The
Disconnect() function forces you to
make a decision on how you want to disconnect. Because there might possibly be transactions still going on, you can
either roll them back, or wait for them to commit. If you do not provide a value for the parameter,
Disconnect rolls the transactions back by default.
Ok, so we have connected and disconnected, big deal. The nice thing about these classes is being able to share that
connection we just made. This is where
CODBCQuery comes in.
CODBCQuery is not really
useful by itself, but it is quite a handy class if you use it as a base class. The only thing note worthy about it,
is the constructor, and the public statement handle. Code speaks well....
CODBCCnx *pDsn = new CODBCCnx("foodsn", "username", "password");
CODBCQuery qry1, qry2;
CODBCQuery qry(new CODBCCnx("foodsn", "username", "password"), true);
CODBCQuery qry2(pDsn), qry3(pDsn,false);
CODBCQuery qry4("SQL Server", "CompName", "username", "password");
CODBCQuery qry5(NULL, "foodsn", "username", "password");
As you can see in the above code snippet, the constructors for
CODBCQuery are pretty flexible. The most
important thing to note is the boolean flag. If you pass the value true,
CODBCQuery will delete the
pointer. However, if you pass just the pointer or false as well, then
CODBCQuery will NOT delete the
One final note. There is a global function,
SQLSuccess(). You pass it a
and it will return a non-zero value if the
SQLRETURN value is either
I just simply grew tired of typing those out ;)
The only thing left to do after all this connecting and sharing is to bind variables to result sets. Which I leave for you
to do :)
I didn't provide a demo, because I feel that these classes are too simple to warrant one. However, if you would like one
give me a holler and I will gladdly provide you with one.
If you look at the code, there are two files, strutil.h and strutil.cpp. They are very simple functions to handle
found all the work you have to go through allocating memory for
strcpy, etc.. annoying. So I replaced them with the funcs in
those files. To prevent name collisions, I put them in the jkl_str namespace. I hope you find them useful.
5 Nov 2001 - updated download