I've recently implemented a package that uses the database/sql
package. By limiting the SQL to very simple select/update/insert statements I assumed the package would work with all the DBMS supported by database/sql
.
However, it turns out that some databases use ?
as placeholder value while others use $1
, $2
, etc., which means the prepared statements will work with some DBMS but not with others.
So I'm wondering is there any technique to make this work in a generic way with all the supported drivers? Or is it necessary to have DBMS-specific code everywhere? (which I think would make the abstraction provided by database/sql
a bit pointless). I guess using non-prepared statements is not an option either since different DBMS have different ways to escape parameters.
Any suggestion?