Red Hat Topics - Re: Does ecpg precompile C++ programs with embedded SQL, or does

This is Interesting: Free IT Magazines  
Home > Archive > Red Hat Topics > June 2007 > Re: Does ecpg precompile C++ programs with embedded SQL, or does





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: Does ecpg precompile C++ programs with embedded SQL, or does
Jean-David Beyer

2007-06-21, 7:13 pm

Ivan Marsh wrote:
> On Thu, 21 Jun 2007 03:11:15 +0000, Jean-David Beyer wrote:
>
>
> Must be out of my depth... how and for that matter why do you pre-compile
> an interpreted language?


I guess it is beyond your depth, unless we completely misunderstand each other.

Embedded SQL is normally used in a normal "higher level" language, like C,
or C++, so that the non-procedural SQL statements generate the proper calls
to the (in this case) PostgreSQL API run-time library to get the stuff done.
While it is theoretically possible to call the run-time library directly, it
harms portability and clarity compared with just writing the SQL statements
in the C or C++ program, bracketed with a EXEC SQL and a semicolon. Once
such a program is written, all you have to do is precompile it with a
suitable preprocessor (e.g., IBM's DB2 pre-compiler or postgresql's ecpg
program) that converts a file in the language in question with embedded SQL
to a similar program without the SQL. You then run that program through the
regular compiler to get a runnable program.

I suppose SQL can be interpreted for a simple user-interface that just looks
up stuff, and perhaps adds, updates, or deletes a few records at a time. But
for a major database application you would not want these things interpreted
because the efficiency is far too low. When you write a program with
embedded SQL, this is usually pre-compiled to a C or C++ (or Fortran or
whatever language you would normally use) first. In addition to converting
the SQL to function calls, where possible the dbms arranges that the queries
are processed in an optimum fashion (choosing whether to use indices or
sequential search, picking the order of searches where joins are involved,
and so on) that the average programmer would not have the resources to
decide by himself.

--
.~. Jean-David Beyer Registered Linux User 85642.
/V\ PGP-Key: 9A2FC99A Registered Machine 241939.
/( )\ Shrewsbury, New Jersey http://counter.li.org
^^-^^ 14:40:01 up 22:15, 3 users, load average: 4.27, 4.18, 4.07
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com