Code Monkey home page Code Monkey logo

firebird's Introduction

Firebird C++ Library

Header only C++ wrapper on Firebird database client C API. Require C++17.

Use examples

#include <firebird.hpp>
#include <iostream>

int main() {
    fb::database emp("employee");
    emp.connect();
    // Using default transaction from fb::database
    fb::query query(emp, "select last_name from employee");
    // There are many ways to read result from the query
    for (auto& row : query.execute()) {
        std::cout << row["LAST_NAME"].value_or("") << std::endl;
    }
    // Database will disconnect when goes out of scope here
}
#include <firebird.hpp>
#include <iostream>

int main() {
    fb::database emp("employee");
    emp.connect();
    // Database has a default transaction, but you can create a new one
    fb::transaction trans(emp);

    try {
        fb::query query(trans,
            "insert into project (proj_id, proj_name, proj_desc) "
            "values ('TEST', ?, ?)");
        // One way to set parameters is to send in execute() call
        // (proj_desc is a blob type here)
        query.execute("New project", "This project using Firebird C++ library");
        trans.commit();
    }
    catch (const fb::exception& ex) {
        std::cout << "ERROR: " << ex.what() << std::endl;
        trans.rollback();
    }
}

More examples are given in the examples directory.

Documentation

Documentation can be built with doxygen. Under Linux run

make docs

Features

  • Creates a view on parameters and result from the query. No unnecessary copying and allocations.
  • Has expandable built-in type converter making it easy to read and write fields and parameters.
  • Has visitor pattern for received data.
    query.foreach([](auto... fields) { });
  • Methods to convert to and from std::time_t and std::tm for SQL timestamp.
  • Has support for BLOB type.
  • Possibility to create new database from the code.
  • Has support for execute_immediate.

Creating a single header

You can grab single header from single directory. There also a script called make_single.py provided in the repository. To create single header locally, run:

make single

Testing

There are not many tests available, but look in tests directory. These can be compiled with:

make tests

Adding library to your project

Linux

  1. Install firebird dev package
sudo apt install firebird-dev
  1. Include firebird.hpp in your program and link with fbclient library
g++ -Ifirebird/include your_app.cpp -lfbclient

Windows

  1. Download and extract zip package of Firebird from https://firebirdsql.org/en/server-packages/.
  2. You will need to copy following files to your project's directory:
    • include\ibase.h
    • include\iberror.h
    • include\ib_util.h
    • lib\fbclient_ms.lib
    • lib\ib_util_ms.lib
    • fbclient.dll
  3. Link both lib files to your project. From "Project" menu choose "Properties". Expand "Linker" and choose "Input". Add fbclient_ms.lib and ib_util_ms.lib to "Additional Dependencies".
  4. Include firebird.hpp in your program and compile.

firebird's People

Contributors

talybin avatar

Stargazers

dianjixz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.