https://github.com/maurodelazeri/memsql-cpp-connector
MemSQL connector with pool of connections for c++
https://github.com/maurodelazeri/memsql-cpp-connector
connector mariadb memsql pool sql
Last synced: 19 days ago
JSON representation
MemSQL connector with pool of connections for c++
- Host: GitHub
- URL: https://github.com/maurodelazeri/memsql-cpp-connector
- Owner: maurodelazeri
- Created: 2019-12-05T20:23:26.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-05T21:14:19.000Z (over 6 years ago)
- Last Synced: 2025-02-23T18:15:28.540Z (over 1 year ago)
- Topics: connector, mariadb, memsql, pool, sql
- Language: C++
- Homepage:
- Size: 16.6 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# memsql-cpp-connector
Simple MemSQL connector with pool of connections for c++
### Dependencies
http://download.memsql.com/clients/mariadb-connector-c-3.0.9-linux-x86_64.tar.gz
```c++
#include
#include
#include "connection_pool.h"
#include
using namespace std;
int main(int argc, char **argv) {
std::ostringstream sqlQuery;
std::shared_ptr m_pool;
m_pool = std::make_shared("x.x.x.x", "root", "pwd", "database", 3306, 1, false);
sqlQuery << boost::format("INSERT INTO xxxx (x,x,x, x) VALUES ('%1%', '%2%', '%3%', '%4%')")
% "a"
% "b"
% "c";
shared_ptr con = m_pool->get_connection();
if (con) {
try {
con->execute(sqlQuery.str(), false, true);
m_pool->release_connection(*con);
} catch (...) {
m_pool->release_connection(*con);
}
}
return 0;
}
```
It's simple, ready to go...
You can for example check the affected rows using
```c++
std::shared_ptr affectRowsPtr = std::make_shared();
con->execute(sqlQuery.str(), false, true, affectRowsPtr.get());
if (*affectRowsPtr == 0) {
cout << "No changes" << endl;
}
```
or you can simple select data:
```c++
#include
#include
#include "connection_pool.h"
#include
using namespace std;
int main(int argc, char **argv) {
std::ostringstream sqlQuery;
auto product_id = 2;
sqlQuery << boost::format(
"select * venue from products where product_id=%1%")
% product_id;
shared_ptr con = m_pool->get_connection();
if (con) {
auto data = con->open(sqlQuery.str());
if (!data->is_valid()) {
return false;
}
auto row = data->next();
unsigned int row_idx = 0;
while (row) {
row_idx++;
cout << row->get_value(0) << endl;
row = data->next();
}
m_pool->release_connection(*con);
}
return 0;
}
```