A silly library that allows you to embed SQL queries in C++ code
Creating tables with cql is easy, and very closeley resembles standard SQL syntax for creating a table. The only exception is the need to include an additional keyword 'SCHEMA'.
int main(int argc, const char **argv)
{
CREATE TABLE Classes SCHEMA
(
id INTEGER,
department CHAR(10),
number INTEGER,
title CHAR(120),
difficulty DOUBLE
);
DROP TABLE Classes;
}
Or you can also create global tables:
CREATE TABLE Points SCHEMA ( x DOUBLE, y DOUBLE );
int main(int argc, const char **argv)
{
loadPoints();
computeStuffWithPoints();
DROP TABLE Points;
}
Insert operations in cql are similar to those in SQL, except they are slightly more restrictive in syntax and, like CREATE TABLE operations, require an additional keyword, in this case ATTRIBUTES.
void loadPoints()
{
INSERT INTO Points ATTRIBUTES(x, y) VALUES (10, 25);
INSERT INTO Points ATTRIBUTES(y, x) VALUES (30, -51);
}
void loadEECS()
{
INSERT INTO Classes ATTRIBUTES(id, department, number) VALUES (1, "EECS", 370);
INSERT INTO Classes ATTRIBUTES(id, title, difficulty, department, number)
VALUES (2, "Data Structures & Algorithms", 2.81, "EECS", 281);
INSERT INTO Classes ATTRIBUTES(id, department, number, title)
VALUES (3, "MATH", 417, "Matrix Algebra");
}
TODO: Document this.
are currently not implemented.
are currently not implemented.
Currently, the following types are supported for columns in tables:
- INTEGER
- CHAR(n)
- CHAR
- DOUBLE
The following types will be added "soon":
- FLOAT
- ENUM
This project (ab)uses several C++11 features and may not work in compilers with poor support for C++11 (Visual Studio...). I currently develop this project in GCC 4.8, and am 80% sure it will work in GCC 4.7, but I'll need to test that. I don't know about clang. I hear that has better support for C++11 (and also generates MB's less of template error messages, but who really wants that?)
- The CREATE TABLE command depends on (and increments twice) the COUNTER macro. The value of COUNTER must be even before the CREATE TABLE command is called. If you aren't using the COUNTER macro in your code, then you don't need to worry about this.
- Be careful when printing out tables / result sets containing CHAR typed columns. Currently, attempting to print a result set containing a column of type CHAR (not of type CHAR(n) ) is equivalent to printing a char* starting at the location in memory of the first (and only) character and may (usually) result in printing extraneous characters. This will be fixed and shouldn't be a problem
- UPDATE and DELETE aren't implemented yet, but who really uses those?
- The performance and code quality aren't great, but who really needs those?