OpenKO Database Model
Table- and column-level documentation generated from the jsonSchema
Loading...
Searching...
No Matches
StoredProcedure.h
1#ifndef STOREDPROC_DETAIL_STOREDPROCEDURE_H
2#define STOREDPROC_DETAIL_STOREDPROCEDURE_H
3
4#pragma once
5
6#include <memory>
7#include <string>
8
9#include <nanodbc/nanodbc.h>
10
11namespace storedProc
12{
13 namespace detail
14 {
15 class StoredProcedure
16 {
17 protected:
18 StoredProcedure();
19 StoredProcedure(std::shared_ptr<nanodbc::connection> conn);
20
23 void prepare(const std::string& query) noexcept(false);
24
26 // This must be called in the destructor of a stored procedure with any output & return values.
27 void flush_on_destruct();
28
32 std::weak_ptr<nanodbc::result> execute() noexcept(false);
33
34 public:
36 void set_connection(const std::shared_ptr<nanodbc::connection>& conn);
37
39 void flush();
40
41 protected:
42 void skip_rows_in_result_set();
43
44 std::shared_ptr<nanodbc::connection> _conn;
45 nanodbc::statement _stmt;
46 std::shared_ptr<nanodbc::result> _result;
47 bool _flushed;
48 };
49 }
50}
51
52#endif // STOREDPROC_DETAIL_STOREDPROCEDURE_H
std::weak_ptr< nanodbc::result > execute() noexcept(false)
Executes the currently prepared statement.
Definition StoredProcedure.cpp:51
void flush_on_destruct()
Flushes any output variables or return values on destruction.
Definition StoredProcedure.cpp:35
void set_connection(const std::shared_ptr< nanodbc::connection > &conn)
Sets the associated database connection.
Definition StoredProcedure.cpp:59
void prepare(const std::string &query) noexcept(false)
Opens and prepares the statement with the associated query.
Definition StoredProcedure.cpp:22
void flush()
Flushes any output variables or return values by reading any and all result sets.
Definition StoredProcedure.cpp:71