Home  +  Forums  +  C++ and Sockets  +  C++ and SQL: MySQL, sqlite, ODBC  +  Miscellaneous Projects
Logo

    
~Database~
~ C++ ~
~Contact~

SQL C++ code generator

  main page   |   sample code and usage example   |   sample code with -stl
mysql devconnect member logo

Welcome to the SQL C++ code generator (sql2class) homepage.

The sql2class utility is a code generation tool, able to convert output from the mysql tool mysqldump to simple C++ classes. From version 1.7 it also supports the sqlite database (version 3).

For each database table, one C++ class will be generated containing member variables for each column as well as methods to read / insert / update / delete records and also return the record as XML. The primary key and unique indexes of a table is used to generate specific constructors for each table, to spawn single objects.

Generated classes use any of the *wrapped database libraries to access the database - no code generated by sql2class is actually dependent on any specific database server.

Check out the *wrapped/sql2class tutorial here.

The source code of this tool is made available under the GPL license.

Download latest version
Changes

2008-06-25: Fix crash bug when a table does not have a primary key.

2006-04-10: Classes are now generated with get/set methods for field data. To get the old behaviour a '-getset' option has been added that disables generation of get/set methods. Name mangling of table and column names can be turned off with the new option '-mangle'. The parser will now be able to correctly read files with both unix and win32 end of line markers.

2006-03-28: Mysql set and enum support working again. Added header comment block to each file, containing the exact command line and sql2class version used to generate the file. Added option to suppress GPL license in generated files. Win32 project file added (vs6). Limited experimental java support added.

2005-09-14: Some sql parsing issues fixed.

2005-08-12: Added sqlitewrapped library support (-sqlite command line argument), and modified parser to support sqlite quirks.

2005-04-12: Using unique index to generate update / erase methods if primary index is not available. If no primary / unique index is available, then update / erase methods for that table is not generated.

2005-02-22: Modified generated classes so they easily can be used together with sql join statements. Added support to parse newer output format from mysqldump.

2004-08-20: Small changes because of name change of the mysql wrapper. Include and header files have new name ("mysqlwrapped").

2004-08-17: Changed generated code to work with latest version of the mysql C API C++ wrapper.

2004-08-05: Bugfix in mediumtext handling. When using generated class to read from the database the last line in a mediumtext field was always lost.

2004-07-09: support for mediumtext in generated insert / update sql statements.

2004-06-22: Improved mysql column type support: unsigned integers, bigint, enum and set. Integer values are now stored in member variables of the correct bit size and sign. Enum and Set fields are handled by two classes, enum_t and set_t. The options "-stl" and "-global" are now by default ON.

2004-06-18: minor bugfixes to stay compatible with dbdesigner.

2004-05-30: Every index / key that returns one unique object are used to generate constructors. Removed the constructor that spawns an object from a "long" input parameter, and replaced that constructor with one constructor for the primary key and constructors for each unique key.

2004-05-21: New command line option '-stl' generates classes that use std::string instead of char * for text/string columns. Replaced a lot of char * input parameters with std::string.

Older versions

Links

Page, code, and content Copyright (C) 2013 by Anders Hedström