ECPG – Embedded SQL in C
postgresql.org
postgresql.org
PGresult *res = PQexec(conn, "SELECT VERSION()");
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
// handle error
}
char* verName = PQgetvalue(res, 0, 0); // Gives null-terminated string.
vs with ECPG: char verName[100]; // ?
EXEC SQL SELECT VERSION() INTO :verName;
if (sqlca.sqlcode != ECPG_NO_ERROR) {
// handle error
}
It seems wrong that ECPG doesn't allocate a null-terminated string on the heap like libpq. Now you have to manage that yourself, and the intro code examples have buffer overrun risks. Am I missing something? Found this: https://postgrespro.com/list/thread-id/1910796Aside from that, I'm not convinced yet that this is much easier than using libpq. Is there an example of a bigger difference?
Indeed, this (or the equivalent in other languages) is one of the main ways the SQL standard expects to be used! It get presented before more familiar approaches, and various wording and placement choices make it clear that the standard considers this embedded SQL approach more core to how it works than other approaches.
A design like libpq, ODBC, etc where the sql syntax needs to be parsed at runtime rather than compile time is considered "dynamic sql" by the standard, and the standard acts like it is less likely to be provided than this interface. Obviously that is hogwash.
This is one of many reasons (like backwards compatibility) that unlike most other programming languages very few SQL implementations make much effort towards faithfully implementing the standard. PostgreSQL actually puts a lot more effort towards implementing the standard than many other popular RDBMses. Postgres has fairly few places where they intentionally violate the standard and don't hope to fix things in the future, and several are fairly obscure, or othewise not likely to cause issues. While Oracle has MANY super common features not spec complaint with no plans to fix. Same with SQL Server. I'm not sufficiently familiar with MySQL/MariaDB to evaluate how closely it tracks the SQL standard. It seems to claim only minor deviations, but that may well be from not claiming conformance at all with features it has implemented but differently from the standard.
Yet the “static” variant sounds like a match made in heaven for optimizations that need to know the specific queries you are going to be making ahead of time, like Noria (Materialize.io, etc.). So maybe not so dumb after all, whatever its actual popularity.
Oracle also has Pro*COBOL.
https://www.oracle.com/database/technologies/instant-client/...
Also ''=NULL.
</bitch>
We had to use Pascal with Oracle embeddings (CS130 with Carol Goble if anyone from cs.man.ac.uk is reading.) Most peculiar it was.
https://docs.oracle.com/en/database/oracle/oracle-database/2...
SQLc is a compiler that translates your SQL statements into little RPC like functions with all the types translated for you. It has the added benefit of making sure you don't typo a table or column name, so you don't have to worry about that exploding at runtime.
What I've been doing more and more is modelling relational concepts in whatever programming language I'm using atm [0]; tables, columns, keys, indexes etc; rather than littering my code with SQL.
Might have been easier if I'd ever done C before; but since it was Informix, I had a pulse, and I was the only person on the bench at the time, I got volunteered that role.
Still got the scars to prove it...