
git: git clone https://gitlab.com/m8618/mfsql tar.gz: download at: https://gitlab.com/m8618/mfsql
mfsql is a simple way to access and use SQLite/MariaDB/PostgreSQL databases via c++ interface
mfsql is distributed under the BSD 3-Clause License, see copying for details
<mfsql.h> mfsql::mfsqlite DBobject; mfsql::mfmariadb DBobject; mfsql::mfpostgre DBobject;use the appropriate open function
// the open functions throw a mfsql::mfdberror on failure
mfsqlite::open( std::string& path_dbname);
mfmariadb::open( std::string& dbname_server, std::string& DBname, std::string& DBuser, std::string& DBpassw, port = 3306 );
mfpostgre::open( std::string& dbname_server, std::string& DBname, std::string& DBuser, std::string& DBpassw, port = 5432 );
close();
query( std::string& sql_statement, std::string& errmsg, & errorcode);
tablefieldnames(const std::string& tablename, std::vector<std::string>& fieldnames, std::string& errmsg);
error(std::string& errmsg);
sqlite3* || MYSQL* || PGconn*
getdb() ;
<iostream>
<mfsql.h>
main() {
mfsql::mfsqlite DB;
{
DB.open("sqlite_testdb.db");
}
(mfsql::mfdberror err) {
std::cerr << err.what() << std::endl;
0;
}
rc(0);
std::vector<std::vector<std::string> > data;
std::string err_msg;
std::string sql("select * from asset;");
(DB.query(sql, err_msg, rc)) {
DB.getquerydata(data);
(std::vector<std::vector<std::string> >::iterator it = data.begin(); it != data.end(); ++it) {
(std::vector<std::string>::iterator yt = it->begin(); yt != it->end(); ++yt) {
std::cout << "'" << *yt << "' ";
}
std::cout << "\n";
}
}
std::cerr << "SQL error:" << rc << " error string:" << err_msg << "\n";
0;
}
compilation of above code example if this was a file named codeexample.cpp
g++ codeexample.cpp -o theprogram `pkg-config --libs --cflags mfsql-1.2.4`static compilation example
g++ codeexample.cpp -o theprogram -I/usr/local/include/mfsql-1.2.4 /usr/local/lib/libmfsql-1.2.4.a -lsqlite3