Me complaining about old unmaintainable codebase again: C-style SQL code in an o...

@charette@mstdn.ca

Me complaining about old unmaintainable codebase again:

C-style SQL code in an old mixed C/C++ application uses this error-prone coding style:

sprintf(buf, "UPDATE blah SET line=%d, group=%d, foo=%d WHERE something", foo, line, group);
db.exec(buf);

Ignore the sprintf() problem. See the other issue? "line", "foo", and "group" are bound to the incorrect variables!

Actual SQL has about 20 parameters, so wasn't as obvious or easy to spot. No errors at compile time, no way to check if this is valid. Code has been this way for years and I only found it today at 3am because I'm trying to reverse-engineer what this application is doing.

New replacement application I'm writing uses SQLiteCpp. I'm using bind() with named parameters, so this type of error cannot exist. New SQL looks like:

SQLite::Statement update(db, "UPDATE blah SET line=@line, group=@group, foo=@foo WHERE something);
update.bind("@line", line);
update.bind("@group", group);
update.bind("@foo", foo);
update.exec();
``` #cpp