4 ms·
The most elegant database interface I know for a low level language is the OTL: http://otl.sourceforge.net/ http://otl.sourceforge.net/ It is a single C++ head
by jake_morrison 7y ago
The most elegant database interface I know for a low level language is the OTL: http://otl.sourceforge.net/ http://otl.sourceforge.net/
It is a single C++ header file, and uses streams to handle queries and results.
#include <iostream>
using namespace std;
#include <stdio.h>
#include <otlv4.h>
otl_connect db;
void insert() {
otl_stream o(5, "insert into test_tab values(:f1<int>, newid())", db);
for (int i=1; i <= 13; ++i)
o << i;
}
void select() {
otl_stream i(5, "select * from test_tab", db);
otl_stream o(7, "insert into test_tab2 values(:f1<int>, :f2<char[37]>)", db);
o.set_commit(0);
int f1 = 0;
char f2[37];
while (!i.eof()) {
i >> f1 >> f2;
o << f1 << f2;
}
o.flush();
db.commit();
}
int main() {
otl_connect::otl_initialize();
try{
db.rlogon("UID=scott;PWD=tiger;DSN=mssql2008");
otl_cursor::direct_exec(db, "drop table test_tab", otl_exception::disabled);
otl_cursor::direct_exec(db, "create table test_tab(f1 int, f2 uniqueidentifier)");
otl_cursor::direct_exec(db, "drop table test_tab2", otl_exception::disabled);
otl_cursor::direct_exec(db, "create table test_tab2(f1 int, f2 uniqueidentifier)");
insert(); // insert records into table
select(); // select records from test_tab and insert them into test_tab2
}
catch (otl_exception& p) {
cerr << p.msg << endl;
cerr << p.stm_text << endl;
cerr << p.sqlstate << endl;
cerr << p.var_info << endl;
}
db.logoff();
return 0;
}
The website smells like 1996; download the examples file.