esql/README.md
2024-02-13 19:53:47 +01:00

1.6 KiB

Embeded SQL

Framework and SQLite implementation of DB2 style embeded SQl for C/C++

What is embeded SQL?

In short, this:

#include <stdio.h>

signed main(){
	EXEC SQL BEGIN DECLARE SECTION;
	int i;
	char c[4];
	EXEC SQL END DECLARE SECTION;

	EXEC SQL CONNECT TO testdb AS myconnection;
	EXEC SQL SELECT i, text INTO :i, :c FROM test WHERE i = 1;

	puts(c);

	return i;
}

It, in broad sense, is what PL/SQL is for Ada, for C/C++.

With an extra step of preprocessing, the above is turned into conventional C, that any compiler will be able to deal with.

Why?

Embeded SQL provides the following benefits:

  • better syntax highlighting compatibility
  • compile time SQL syntax checks
  • more agile database <-> language type conversions

Who is responsible for this?

IBM is. The embeded SQL debuted with their DB2. I am awfully unsure, which edition, but I believe it originates from the 80s.

In 1998, Michael Meskes started Postgresqls on going embeded SQL support with the following comment:

Well this is not really a patch. But I mananged to get Linus' old Postgres95 precompiler to compile and work with PostgreSQL.

What that implies is under investigation.

Regardles the standard Postgresql tool ecpg is highly functional and something I can only recommend for people working with Postgresql in specific.

However, I find the usage of databases with a server architecture for non-enterprise purposes of rather poor taste. This is why this project sets out to start supporting SQLite/embeded SQL and to create a system where adding arbitrary databases is easy