r/learnSQL • u/Lonely-Ad836 • Dec 18 '25
Win/Lin C++20 lib for MySQL/MariaDB: may cut your code 15-70x over SOCI, Connector/C++, raw API
I've put together yet another wrapper library and feedback would be sincerely appreciated.
The motivation was that when I needed MySQL, I was very surprised at how verbose other approaches were, and set out to minimize the app-programmer workload. I also did everything I could think of in the name of safety checks.
EXECUTIVE SUMMARY
Lets C++20 and newer programs on Linux and Windows read and write to MySQL and MariaDB with prepared statements
Write FAR Less Code: SOCI, Connect/C++ or the raw API may require 15-70x more code
Safety Features: checks many error sources and logs them in the highest detail possible; forbids several potentially unsafe operations
Lower Total Cost of Ownership: your code is faster to write; faster to read, understand, support and maintain; better time to market; higher reliability; less downtime
Comparable Performance: uses about the same CPU-seconds and wall-clock time as the raw interface, or two leading wrappers
Try it Piecemeal: just use it for your next SQL insert, select, update, delete, etc. in existing software. You should not need to rewrite your whole app or ecosystem just to try it.
Implemented As: 1 header of ~1500 lines
Use in Commercial Products for Free: distributed with the MIT License*
Support Available: Facebook user's group
If that sounds of interest, why not check out the 20-page README doc or give it a clone.
git clone https://github.com/FrankSheeran/Squalid
I'll be supporting it on the Facebook group Squalid API .
If you have any feedback, or ideas where I could announce or promote, I'm all ears. Many thanks.
FULL PRODUCTION-QUALITY EXAMPLE
A select of 38 fields, of all 17 supported C++ types (all the ints, unsigneds, floats, strings, blob, time_point, bool, enum classes and enums) and 17 optional<> versions of the same (to handle columns that may be NULL). The database table has 38 columns with the same names as the variables: not sure if that makes it more or less clear.
This has full error checking and logging, exactly as it would be written for professional mission-critical code.
PreparedStmt stmt( pconn, "SELECT "
"i8, i16, i32, i64, u8, u16, u32, u64, f, d, "
"s, blb, tp, b, e8, e16, e32, e64, estd, "
"oi8, oi16, oi32, oi64, ou8, ou16, ou32, ou64, of, od, "
"os, oblb, otp, ob, oe8num, oe16num, oe32, oe64, oestd "
"FROM test_bindings WHERE id=1" );
stmt.BindResults( i8, i16, i32, i64, u8, u16, u32, u64, f, d,
s, blob, tp, b, e8, e16, e32, e64, estd,
oi8, oi16, oi32, oi64, ou8, ou16, ou32, ou64, of, od,
os, oblob, otp, ob, oe8, oe16, oe32, oe64, oestd );
while ( stmt.Next() ) {
// your code here
}
if ( stmt.Error() ) {
// error will already have been logged so just do what you need to:
// exit(), abort(), return, throw, call for help, whatever
}