Sujet : Re: VMS x86-64 database server
De : arne (at) *nospam* vajhoej.dk (Arne Vajhøj)
Groupes : comp.os.vmsDate : 07. Jul 2025, 19:07:31
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <104h2d1$31cae$2@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla Thunderbird
On 7/6/2025 10:42 PM, Lawrence D'Oliveiro wrote:
On Sun, 6 Jul 2025 19:58:04 -0400, Arne Vajhøj wrote:
But in embedded SQL then it is the standard way to do queries.
Not sure what “embedded SQL” means. I normally use SQL “embedded” in an
app written in some other programming language.
Embedded SQL is a thing or was a thing 30-40-50 years ago.
Basically you write source code with SQL statements prefixed
by EXEC SQL, put it through a pre-compiler to get valid
code in whatever language (Cobol, PL/I, C or whatever).
Here is C call API code:
PGresult *res;
res = PQprepare(con, "stmt_selectf1f2fromt1", "SELECT f1,f2 FROM t1", 0, NULL);
PQclear(res);
res = PQexecPrepared(con, "stmt_selectf1f2fromt1", 0, NULL, NULL, NULL, 0);
int nrows = PQntuples(res);
for(int i = 0; i < nrows; i++)
{
int f1 = atoi(PQgetvalue(res, i, 0));
char f2[51];
strcpy(f2, PQgetvalue(res, i, 1));
printf("%d %s\n", f1, f2);
}
PQclear(res);
PQexec(con, "DEALLOCATE stmt_selectf1f2fromt1");
same code as C with embedded SQL:
EXEC SQL DECLARE mycursor CURSOR FOR SELECT f1,f2 FROM t1;
EXEC SQL OPEN mycursor;
for(;;)
{
EXEC SQL FETCH mycursor INTO :f1, :f2;
if(sqlca.sqlcode != 0) break;
printf("%d %s\n", f1, f2);
}
EXEC SQL CLOSE mycursor;
Simpler shorter code, because the pre-compiler handle
some of the plumbing.
Arne