Re: SQL+C++, is it possible ?

From: Natan Pekerman <natan_at_euronet.co.il>
Date: 1995/12/22
Message-ID: <4bf7ln$8tq_at_shelly.euronet.co.il>#1/1


In article <4anpjk$d6q_at_aldebaran.sct.fr>, georgeb_at_worldnet.net says...
>
>Hi dear readers,
>
>I'd like some advice concerning the following issue:
>
>Starting from an Object Oriented Model (i.e. an OMT one)
>I'd like to implement the class (i.e. EMP) using C++ and
>code the methods using SQL statements embedded in C++.
>
>example (do not consider syntax mistakes):
>
>class EMP {
> int empid;
> char name [20];
> char address[35];
>public
> void print_emp (int);
>}
>
>/* how to implement this method?? */
>void EMP::print (int id){
> char empname[20];
>
> select name into empname
> from EMP
> where empid=id
>
>}
>
>This example try to expose my problem, does anyone know how to
>code SQL and C++ together ?
>
>Is there any Pro*C++ ?
>
>I'll really appreciate your help.
>
>Thanks,
>
>/*
>Bruno GEORGES
>MSc Computer Science
>5.rue Pierre Louys
>75016 Paris
>France
>*/
>

Hi,

  1. Read!!! http://www.dbmsmag.com/int9410.html
  2. Visual C++ 1.5 & 4.0 (MFC Microsoft Foundation Classes)
	class CDatabase : public CObject
	--------------------------------

A CDatabase object represents a connection to a data source, through which
you can operate on the data source. A data source is a specific instance of data hosted by some database management system (DBMS). Examples include
Oracle, Microsoft SQL Server, Microsoft Access, Borland dBASE, and xBASE. You
can have one or more CDatabase objects active at a time in your application.
To use CDatabase, construct a CDatabase object and call its Open member function. This opens a connection. When you then construct CRecordset objects for operating on the connected data source, pass the recordset constructor a pointer to your CDatabase object. When you finish using the connection, call the Close member function and destroy the CDatabase object.
Close closes any recordsets you have not closed previously. The recordsets you derive from the database classes use ODBC to communicate with a data source, and ODBC retrieves records from the data source by sending SQL statements.
A recordset constructs a SQL statement by building up the pieces of an SQL
statement into a CString. The string is constructed as a SELECT statement,
which returns a set of records.
When the recordset calls ODBC to send an SQL statement to the data source,
the ODBC Driver Manager loads the appropriate ODBC driver. The Driver Manager passes the statement to the ODBC driver, and the driver sends it to the
underlying DBMS. The DBMS returns a result set of records, and the ODBC driver returns the records to the application. The database classes let your
program access the result set in a type-safe C++ class derived from CRecordset.

Example

CString strCmd = "UPDATE Taxes SET Federal = 36%"; if( !m_dbCust.ExecuteSQL( strCmd ) )

        // ...

Bye.



Natan Pekerman
1 Shvil Savion, K.Motzkin, 26354, Israel natan_at_euronet.co.il
+972-4-8700568
Received on Fri Dec 22 1995 - 00:00:00 CET

Original text of this message