PrevUpHomeNext

Chapter 1. Queries in C++ Expressions

Table of Contents

What, Why, How, and for Whom?
What Does it Look Like?
Like this ...
... or these
Rise of the Monster Query
The Quincessential Dot Points

Quince is a library that allows C++ programs to create SQL commands, and to have them executed on a relational DBMS. When data accompanies an outgoing command, quince first converts the data from C++ types (including user-defined classes and structs) to the DBMS's formats; and when data comes back in reply, quince makes the reverse conversion. So quince is an Object Relational Mapper (ORM).

The difference between quince and existing ORMs is this: Quince offers more support for sophisticated queries. A user who knows the power of a relational database will want to harness it, by issuing commands that employ server-side calculations, WHERE clauses, SELECT clauses, JOINs, DISTINCT, GROUP BY, INTERSECT, and so on, all combined and interconnected according to the user's own design. Quince treats such a user as the normal case, not an outlier. Of course it is also sometimes necessary to store or retrieve a single record, and quince makes that very easy to do; but it is only one point on a wide spectrum of possible uses. This reflects an underlying belief that an RDBMS is an engine of data processing as much as it is an engine of data storage.

Other ORMs make room for sophisticated queries, if at all, by asking users to enter literal SQL text. For an ORM to insist on this is in several ways retrograde: it forces the user to juggle two syntactically different languages, C++ and SQL, with two unrelated type systems, and while any errors of syntax or type consistency on the C++ side are detected early, any such errors on the other side go undetected until run-time, when the SQL hits the DBMS.

To avoid these difficulties, quince re-presents the SQL concepts in C++, so the user works full-time in C++ syntax with C++ data types. There are C++ functions join(), distinct() where() etc., corresponding to the SQL keywords, and there are C++ operator overloads corresponding to SQL's arithmetic, string, relational, and logic operators. All of these devices are statically typed, so that type errors are caught at compile time. At run time, they work together to build a data structure that represents the user's query. And finally, when the running application is ready for the query to be executed, quince renders the data structure as correct SQL and hands it off to the DBMS.


PrevUpHomeNext