SQLITE C ++ Wrapper is a minimum package package for SQLITE in a C ++ language.

SQLite C++ Wrapper is a minimal package of C++ language to SQLite.
Sample code 1:
#include
#include
# include
using namespace std;
#include “sqlite3x.hpp”
using namespace sqlite3x;
int main(void) {
try {
sqlite3_connection con(“test.db”);
int count = con.executeint(
“select count(*) “
“from sqlite_master”
“where name= ‘t_test’;”);
if(count == 0) {
con.executenonquery(
“create table t_test(number,string);”);
}
sqlite3_transaction trans(con);
{
sqlite3_command cmd(con,
“insert into t_test values(?,?);”);
cmd.bind(2, “foobar”, 6); < /div>

for(int i = 0; i <10000; ++i) {
cmd.bind(1, i);
cmd.executenonquery();
}
}
// if trans goes out of scope (due to an exception or
// anything else) before calling commit(), it will
// automatically rollback()
trans.commit ();
}
catch(exception &ex) {
cerr << "Exception Occured: "<< ex.what() << endl;
}
return 0;
}
Sample code 2:
#include
#include
using namespace std;
#include “sqlite3x.hpp”
using namespace sqlite3x;
int main(void) {
try {
sqlite3_connection con(“test.db”);
sqlite3_command cmd(con, “select * from t_test;”);
sqlite3_reader reader = cmd.executereader();
while(reader.read()) {
cout << reader.getcolname(0) << ": "
<< reader.getint(0) << endl;
}
}
catch(exception &ex) {
cerr << "Exception Occured: "<< ex.what( ) << endl;
}
return 0;
}

SQLite C++ Wrapper is a minimal package of C++ language to SQLite.

Sample code 1:

#include

#include

# include

using namespace std;

#include “sqlite3x.hpp”

using namespace sqlite3x;

int main(void) {

try {

sqlite3_connection con(“test.db”);

int count = con.executeint(

“select count(*) “

“from sqlite_master “

“where name= ‘t_test’;”);

if(count == 0) {

con.executenonquery(

“create table t_test(number,string);”);

}

sqlite3_transaction trans(con);

{

sqlite3_command cmd(con,

“insert into t_test values(?,?);”);

cmd.bind(2, “foobar”, 6);< /p>

for(int i = 0; i <10000; ++i) {

cmd.bind(1, i);

< p>cmd.executenonquery();

}

}

// if trans goes out of scope (due to an exception or

// anything else) before calling commit(), it will

// automatically rollback()

trans.commit();

}

catch(exceptio n &ex) {

cerr << "Exception Occured: "<< ex.what() << endl;

}

< p>return 0;

}

Sample code 2:

#include

#include

using namespace std;

#include “sqlite3x.hpp”

using namespace sqlite3x;

p>

int main(void) {

try {

sqlite3_connection con(“test.db”);

sqlite3_command cmd(con, “select * from t_test;”);

sqlite3_reader reader = cmd.executereader();

< p>while(reader.read()) {

cout << reader.getcolname(0) << ": "

<< reader.getint(0) << endl ;

}

}

catch(exception &ex) {

cerr << "Exception Occured: "<< ex.what () << endl;

}

return 0;

}

Leave a Comment

Your email address will not be published.