There are 5486 unique visitors to this page.

This page is dedicated to database-related programs, that can help in SPTK-based development.

At the moment, only one utility is included here. The Perl script Sql2Cpp.pl (included with SPTK distribution) allows generation of C++ interface classes for PostgreSQL stored procedures.


Why is it needed?

For a large database-related project that uses many stored procedures, it is important to have the universal way to call these procedures.

  • Sql2Cpp creates an abstraction layer, so instead of dealing with stored procedures you use C++ methods. The advantages are clear. The resulting code is cleaner and more compact.
  • C++ methods generated by Sql2Cpp enforce the parameter types and return type. If stored procedure parameters change, the conflict is created in compile time that is much easier to spot. Of course, Sql2Cpp should be ran after any change in stored procedure parameters or return values.
  • Sql2Cpp enforces documentation of the stored procedures (right in SQL file) that is transformed into Doxygen comment in C++ header files. This is really helpful for large projects with many developers using generated classes.


How does it work?

Sql2Cpp reads SQL-scripts that create stored procedures, and generates C++ source files. Every C++ source file defines a single class (that corresponds to SQL-script file). Every method implements a single stored procedure call. Sql2Cpp tries to support a strong type control of parameters and returned data. That is achieved by using classes for DB-specific types such as table and view records.


What databases are supported?

Currently, it is only PostgreSQL. We are planning to add more server types in the future.


How the class names/input paths/etc are configured?

Sql2Cpp comes with the default configuration file that allows to define many useful generation parameters. Please, let us know if you need to tweak something else.


How can I try it?

Sql2Cpp is included with the SPTK starting from version 3.5.7.08. All the files needed for testing are located in dbtools/ sub-directory. In order to try Sql2Cpp, you have to setup PostgreSQL server with default database for your user. After that, run the command:


perl sql2cpp.pl


The test would create two C++ modules, CAuthor{.h,.cpp} and CBook{.h,.cpp} in src/ sub-directory. You can now change the configuration parameters, or edit stored procedure files, and run Sql2Cpp again.


Valid XHTML 1.0! If you have any questions or comments regarding this page feel free to drop a line to Alexey Parshin.
Design by Michael Perlov