The Specialized SQL Structures (SSQLS) allows you create structures
to hold data for mysql queries with extra functionality to make your
life easier. These structures are in no way related to any Standard
Template Library (STL) type of containers. These structures are exactly
that structs. Each member item is stored with a unique
name within the structure. You can in no way use STL algorithms are
anything else STL to work with the individual structures. However
you CAN use these structures as the value_type for STL containers.
(They would be pretty useless if you couldn't.)
Where # is the number of valuables in the vector, NAME is the name
of the structure you wish to create, and TYPE1 is the type name for
first item and ITEM1 is the valuables name for the first item etc..
You can also make the structure comparable by changing the first 0
in the previous example to a non zero number. This number, lets call
it n, will tell c++ that if the first n number or the same then the
two structures are the same.
will create a structure where only the item valuable is checked to
see if two different stocks are the same. It also allows you to compare
one structure to another based on the value of item. (If n is greater
than one it will compare the structures in a Lexicographic order.
For example if it was 2 it would first compare item and
if item was the same it would then compare num. If num
was the same it would declare the two structures the same.)
In addition what the previous example defines it also defines the
This will create a similar structure as in the previous example except
that that the order of the data items will be different and c++ will
use the first two items to compare with (date, price). However because
a custom order is specified you can use the same query to populate
the set. It will fill date with the first 5th item of the
query result set, price with the 4th, etc...
...(The logical equivalent for field_list and equal_list)...
value_list() returns a special class that when used with
the << operator with an ostream on the left will
return a comma separated list with values properly quoted and escaped
field_list() return a special class than does the same thing
but returns a list of fields that the structure holds which in this
case is the same thing as the valuable names. The field names are
not escaped or quoted
equal_list() returns a comma separated list with the format
field name = value. The field name is not quoted or escaped
and value is escaped or quoted as needed.
You can also use SQLQuery::insert or SQLQuery::replace (and thus Query::insert
or Query::replace) as a short cut to accomplish the same task like
It will use s.table for the table name which defaults to the name
of the structure.
You can also specify an different delimiter "d".
If none is specified it defaults to ",". With
this you can use the delimiter " AND " for equal_list
to aid in update and select queries. For example:
stock s2 = s;
s2.item = "6 Dinner Roles";
query << "UPDATE TABLE stock SET " << s2.equal_list()
<< " WHERE " << s.equal_list(" AND ");
would produce the query:
UPDATE TABLE stock SET item = '6 Dinner Roles',num = 75,weight = 0.95,
price = 0.97,date = '1998-05-25'
WHERE item = 'Dinner Roles' AND num = 75
AND weight = 0.95 AND price = 0.97
AND date = '1998-05-25'
which will change the entree in the table so that item is now "6
Dinner Roles" instead of "Dinner Roles"
You can use SQLQuery::update (and thus Query::update)
as a short cut to accomplishing the same task like so:
Like SQLQuery::insert, it will use s.table for the table
name which defaults to the name of the structure.
You can also specify an different manipulator which will effect the
way c++ quotes or escapes the values. This may be any valid stream
manipulator that only effects the item to the right of manipulator.
value_list and equal_list defaults to escape
and field_list defaults to do_nothing. For equal_list
the manipulator only effects the value part and not the field
This can be useful creating exporting to a file where you don't want
quotes around strings for example.
The three non-basic forms allow you to specify which items are returned.
cout << q.value_list(false,false,true,true,false) << endl; //bool form
cout << q.value_list(stock_weight, stock_price) << endl; //list form
will both return:
The bool form excepts boolean arguments where each true/false
represents an wether to show a valuable. False means not to show
it while true means to show it. If you leave of some they are assumed
to be false. For example:
The list form allows you to specify which items to show.
An enum values are created for each valuable with the name of struct
plus the underscore character prefixed before it. For example: item
These forms can be useful is select queries. For example:
query << "SELECT * FROM stock WHERE "
<< q.equal_list(" AND ",stock_weight,stock_price);
would produce the query:
SELECT * FROM stock WHERE weight=0.95 AND price=0.97
which will select all rows from stock which have the same weight and
price as q.
The vector form (not shown above) allows you to pass a boolean
vector which is a time saver if you use the some pattern more than
once as it avoids having to create the vector from the arguments each
time. If a is a boolean vector then a will
hold wether to include the first variable a the second
etc... For example:
a = false; a = false; a = true; a = true; a = false;
query << "SELECT * FROM stock WHERE " << q.equal_list(" AND ", a);
will produce the same query as in the above example.
In order to avoid having even more forms we decided not to allow
you to specify a different table name in the actual macro call. The
table name is used by SQLQuery::insert, replace,
and update. However you can easeally change the default
table name, which is the same as the struct name, by changing the
reference NAME::table() returns to a different const
char * For example:
stock::table() = "in_stock"
Will change the table name to "in_stock" in the
examples used through out this guide.
The best way to add functionality is through inheritance. Even though
you could paste the code outputted from pretty.pl and modify it this
is not recommended because it won't reflect future enhancements.
Macros are defined for structures with up to 25 items. If you need
more modify the underlying perl script custom.pl. This perl script
is used to generate the header file. It in no way tries to parse C++
The header file that the script custom.pl creates is close to a meg.
However, please note that the 1 meg header file (custom-macros.hh)
is NOTHING but macros. Therefor the compiler has to do very little
work when reading is.
Also, everything included by the macro call is done in such a way
that you can safely include the macro call in a header file and not
have to worry about duplicate function calls or anything of the like.