CppCon Program Highlights, 5 of N: Modern C++ and Databases

The CppCon 2014 conference program has been posted for the upcoming September conference. We've received requests that the program continue to be posted in "bite-sized" posts, a few sessions at a time, to make the 100+ sessions easier to absorb, so here is another set of talks. This series of posts will conclude once the entire conference program has been posted in this way.

 

Whether you're using an in-memory flat database or a cloud-scale RDBMS, SQL and ODB databases continue to be a critical layer of modern software. But how do you use them well with modern C++? The following CppCon talks address this question, and as always are presented by the right people -- Those Who Know and Those Who Do, as usual with an international global perspective and including a two-part talk by CppCon's own Boris Kolpackov.

In this post:

  • sqlpp11, An SQL Library Worthy Of Modern C++
  • Persisting C++ Classes in Relational Databases with ODB
  • ODB, Advanced Weapons and Tactics

 

sqlpp11, An SQL Library Worthy Of Modern C++

SQL and C++ are both strongly typed languages. They should play well together. But most C/C++ interfaces to SQL databases are string based. They force the developer to effectively hide the SQL types, names and expression structures from the compiler. This defers the validation of SQL expressions until runtime, i.e. unit tests or even production. And the strings might even be vendor specific, because different databases expect different dialects of SQL in those strings.

That feels wrong. Modern C++ can do better.

This talk gives an introduction to sqlpp11, a templated embedded domain specific language for SQL in C++. It allows you to build type-safe SQL expressions with type-safe results, all of which can be verified at compile time, long before your code enters unit tests or even production.

In addition to its obvious use with relational databases, sqlpp11 can also serve as an SQL frontend for all kinds of data sources: Since sqlpp11 offers complete SQL expression trees even at compile time, it isn't hard to apply SQL expressions to std::vector or std::map for instance, or streams, or XML, or JSON, you name it. With your help, sqlpp11 could become for C++ what LINQ is for C#.

Speaker: Roland Bock, Head of Development, PPRO Financial Ltd., London/Munich.  Roland is Head of Development at PPRO Financial Ltd, an FCA regulated e-Money institute offering prepaid MasterCard card programs and comprehensive financial solutions for international electronic payment transactions. Since 2008 he has been using SQL in C++. Being unhappy with the string-based approach of most SQL libraries, he decided to do something about it and developed a type-safe EDSL for SQL in C++: sqlpp11, see https://github.com/rbock/sqlpp11. In his spare time Roland is preparing sqlpp11 to be proposed for boost and possibly also for the C++ standard. He lives and codes in Munich (Germany). C++ is his preferred language, especially since the arrival of C++11.

 

Persisting C++ Classes in Relational Databases with ODB

ODB is an open source, cross-platform and cross-database (SQLite, PostgreSQL, MySQL, MS SQL Server, Oracle) object-relational mapping (ORM) system for C++. It allows you to persist C++ objects to a relational database without having to deal with tables, columns, or SQL, and without manually writing any mapping code.

In the first part of this two-part talk we will cover the basics of transactionally persisting, loading, updating, and deleting simple C++ classes in a database as well as querying the database for objects. We will then look into persisting C++ classes that have more interesting data members, such as containers and pointers to objects, or that form a polymorphic hierarchy. Support for C++11, Qt, and Boost value types, containers, and smart pointers will also be covered.

Targeting 5 different database systems at the same time may sound like a daunting task but as we will see it is not that hard with ODB. Life would also be a lot easier if our C++ classes never changed. The next best thing is to have comprehensive tooling support. So we will conclude the first half with a discussion of database schema evolution and its support in ODB.

ODB, Advanced Weapons and Tactics

Hiding a relational database behind an ORM does not work. Did I just say that? Yes! Performance and scalability limitations always get in the way. Should we then throw away the whole ORM idea and go back to SQL? We don't have to. In fact, the bulk of ODB features were specifically designed to resolve these limitations without degenerating to JOINs and SQL. And that's what the second part of this talk is all about: bulk operations, object caches, lazy pointers, views, change-tracking containers, optimistic concurrency, object sections (partitions), and prepared and cached queries. By the end of the second half you will be ready for anything that real-world C++ object persistence and database access can throw at you.

Speaker: Boris Kolpackov Boris Kolpackov is a founder and chief software designer at Code Synthesis, a company focusing on the development of open-source tools and libraries for C++. For the past 10 years Boris has been working on solving interesting problems in the context of C++ using domain-specific languages (DSL), C++ parsing, source-to-source translation, and code generation. His notable projects to date include the ODB C++ ORM system as well as XSD and XSD/e XML Schema to C++ compilers.

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.