Link to home
Start Free TrialLog in
Avatar of bry
bry

asked on

Accessing queries internal to a database w/ ODBC and VC++ 1.52

We're doing Win3.1 deveopment at work, and I need to access queries that are
stored in an Access 2.0 .mdb file, using ODBC 2.1.  Any solutions?
Avatar of psdavis
psdavis
Flag of United States of America image

Use the CRecordset class to open up the query very much like a regular recordset.

Phillip

Avatar of bobplace
bobplace

Use CDaoQueryDef.  It will open the query for you.  Then you can open a CDaoRecordset using the CDaoquerydef ratehr than a CDaoDatabase.
We both wish.  CDaoQueryDef is 32-bit.  We're still 16-bit ODBC aren't we?

Phillip

Avatar of bry

ASKER

Please note: ODBC is *NOT* DAO.  I cannot use CDaoQueryDef
because DAO wasn't around when VC++ 1.52 was released, hence
it's version of MFC does not support DAO.  I'm trying to
port this app from MFC 4.2 to MFC 2.5 (or whatever it is that
shipped w/ VC++).

Oh, I see you are moving to a lower platform.  Sorry I gave up on the 16 bit world several years ago.  Never mind....
If all you're trying to do is port a Win32 program down to Win16, how about Win32s?  I believe that you still gain your DAO implementation, and it should help with absolutely everything else you're trying to convert.

Phillip

Avatar of bry

ASKER

We've already tried Win32s, and there are some problems w/ it
(particularly w/ property sheets).  Also, it slows Win3.1
down a bit, and we're having problems with speed already (we
have a 200,000-entry database to manipulate).

I may have found a solution, though.  I'll have to wait 'til
I get to work tomorrow to see what happens.

Thanks

Bry
Avatar of bry

ASKER

Okay, the problem is fixed -- here's what needs to be done, for
those out there who are doing Win3.1 development:

1. Create a CRecordset w/ ClassWizard that accesses one of the
tables that your query uses

2. Add/delete member variables from your recordset class to
reflect the columns of data returned by the query - you may
have to add some manually outside the ClassWizard-defined
braces

3. Initialize your vars, and also edit the Record Field Exchange
part of your class to reflect the vars you added - note if you
have parameters you want to send to the query, you will also
have to add those member vars and set them up in the Field
Exchange as well - see the docs

4. You're now ready to open the query.  First, initialize all
your parameters (if you have them) w/ whatever data you want
to send to the query.  Then, construct a CString as follows:

CString mySQL = _T("{CALL myquery ( <params> )}");

where 'myquery' is the name of the query stored in the DB.
Then create an instance of your recordset, and open it with:

myCRecordSet.Open(CRecordset::snapshot, mySQL, CRecordSet::readOnly);

This will open the query and begin the Field Exchange as normal.


PS -
I don't know how to get the points back, so I guess the first
person who responds can have them.
ASKER CERTIFIED SOLUTION
Avatar of psdavis
psdavis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial