Re: How do you design ProC to work with C++?

From: Christian Pomar <ipycp_at_arrakis.es>
Date: 1998/07/12
Message-ID: <35a8b076.0_at_news.arrakis.es>#1/1


>I used to do my ProC (v2.2.3/Oracle 7.3) programming with C on an HP-UX
>machine and I would like to catch up with the rest of the world and start
>using C++. I have managed to get a simple database object (create the
>connection and closing it) to work by following the instructions on the
>manual. However, I haven't been able to figure out anything much after
 that.
> For example:
>
>- EXEC SQL CONNECT :userpass AT MY_DB USING :db_string; The "MY_DB" part
>doesn't compile when substituted by a host variable. This is going to
>severely hamper the reusability of the database object.
>
>- Doing a query. With the simple database object, the client can execute
>query just like before (EXEC SQL SELECT...) but this is a screwy thing to
 do
>and it totally defeats the purpose of OO design. I was trying to build a
>wrapper that let the client submit a query, get back an id, and use the id
 to
>fetch the next row. I'm also thinking of doing it ala OODBC's Database &
>Dynaset object. To do this, I need a generic fetch that can work for any
>number of columns but I am not sure how to write such thing.
>
>Does anyone tried to do this and is this a feasible thing to try? or would
 I
>better off trying to pull this with Oracle 8?
>
>Thanks,
>wan

I've been trying something similar, but I have desisted. I thought in something like a recordset class which represented a table. All the basic functionality for selecting was inside (dynamic sql type 4) and every derived class had to build up the recordset indicating number of rows, types, etc. The derived class could give the WHERE and ORDER BY clause of every SQL statement. For example:

class OracleConection
{
private:

    string ConnectString;
    string UserName;
    string Password;
    bool Connected;
};
class RecordSet
{

    // Lots of weird things to keep track of the table and its columns     protected:

        virtual int Refresh(void) = 0;
};
class Customer
{
...
};
class CustomerList : public RecordSet
{

    list<Customer> m_CustomerList;
    ...
    int Refresh(void);
};

In the constructor of CustomerList the RecordSet was initilized indicating the fields of the table and the types. The pure virtual method Refresh did the real query. The OracleConnection represents the connection with Oracle and does all the error stuff using exceptions.

In theory, this mechanism was generic enough to admit any SELECT on any table, view or join and allowed real error control using exceptions. It had many drawbacks, the mos important one was that you still had to know a lot about the table. It was not a real save of time because querying a table in Pro*c is quite easy and simple once you have done it several times.

It was all really too complicated, specially if it had to be used with other databases. Now I use something very similar, but the CustomerList is not derived from RecordSet. The refresh method does the SELECT and converts the data into Customer objets and pushes them into the list. It's more flexible for me. I still use the connection object because it improves error checking.

Hope it helps
Christian Pomar Received on Sun Jul 12 1998 - 00:00:00 CEST

Original text of this message