@@ -0,0 +1,21 @@ | |||
MIT License | |||
Copyright (c) 2018 Erik Junghanns (aka Bergmann89) | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all | |||
copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||
SOFTWARE. |
@@ -0,0 +1,66 @@ | |||
# cppmariadb | |||
A C++11 class wrapper for the mysql/mariadb C connector. | |||
## Getting Started | |||
### Prerequisites | |||
Before you can use cppmariadb you need to download and install [the official mariadb C connector](https://downloads.mariadb.org/connector-c/)). And if you want to run the tests you additionally need [the google testing framework](https://github.com/google/googletest). | |||
[The cpputils libary](https://git.bergmann89.de/cpp/cpputils) will be automatically downladed during the build. | |||
### Small Usage Example | |||
``` | |||
#include <iostream> | |||
#include <exception> | |||
#include <cppmariadb.h> | |||
using namespace ::cppmariadb; | |||
int main(int argc, char** argv) | |||
{ | |||
try | |||
{ | |||
/* establish connection to database */ | |||
connection c = database::connect("localhost", 3306, "testuser", "password", "database", client_flags::empty()); | |||
/* prepare a query */ | |||
statement s("SELECT * FROM my_table WHERE id=?id?"); | |||
s.set("id", 5); | |||
/* execute the query */ | |||
result_used* res = con.execute_used(s); | |||
if (res == nullptr) | |||
{ | |||
throw std::exception("unable to fetch from table from database!"); | |||
} | |||
/* iterate over result set */ | |||
row* r = res->next(); | |||
while(r != nullptr) | |||
{ | |||
std::cout << "new dataset:" << std::endl; | |||
for (size_t i = 0; i < r->size(); ++i) | |||
{ | |||
field f = r->at(i); | |||
std::cout << " " << f.column().name << ": " << f.get<std::string>() << std::endl; | |||
} | |||
std::cout << std::endl; | |||
r = res->next(); | |||
} | |||
return 0; | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
std::cout << ex.what() << std::endl; | |||
} | |||
return 1 | |||
} | |||
``` | |||
## License | |||
This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details |