Arachne 1.0
Arachne - the perpetual stitcher of Wikidata entities.
Loading...
Searching...
No Matches
arachne::penelope::anonymous_namespace{inbox.cpp}::statement Class Referencefinal

Public Member Functions

 statement (sqlite3 *const database, const std::string_view sql)
 statement (const statement &)=delete
statementoperator= (const statement &)=delete
 statement (statement &&)=delete
statementoperator= (statement &&)=delete
 ~statement ()
void bind (const int index, const std::string_view value)
void bind (const int index, const std::int64_t value)
void bind (const int index, const double value)
void bind_null (const int index)
void bind_json_value (const int index, const json &value)
bool step ()
void execute ()
std::int64_t integer (const int column) const
double real (const int column) const
std::string text (const int column) const
bool is_null (const int column) const
sqlite3_stmt * native () const noexcept
 statement (sqlite3 *const database, const std::string_view sql)
 statement (const statement &)=delete
statementoperator= (const statement &)=delete
 statement (statement &&)=delete
statementoperator= (statement &&)=delete
 ~statement ()
void bind (const int index, const std::string_view value)
void bind (const int index, const std::int64_t value)
void bind (const int index, const double value)
void bind_null (const int index)
void bind_json_value (const int index, const json &value)
bool step ()
void execute ()
std::int64_t integer (const int column) const
double real (const int column) const
std::string text (const int column) const
bool is_null (const int column) const
sqlite3_stmt * native () const noexcept

Private Attributes

sqlite3 * database_ { nullptr }
sqlite3_stmt * value_ { nullptr }

Detailed Description

Definition at line 63 of file inbox.cpp.

Constructor & Destructor Documentation

◆ statement() [1/6]

arachne::penelope::anonymous_namespace{inbox.cpp}::statement::statement ( sqlite3 *const database,
const std::string_view sql )
inline

Definition at line 65 of file inbox.cpp.

66 : database_(database) {
67 if (sqlite3_prepare_v2(
68 database, sql.data(), static_cast<int>(sql.size()), &value_,
69 nullptr
70 )
71 != SQLITE_OK) {
72 throw database_error(sqlite_message(database, "prepare statement"));
73 }
74 }
std::string sqlite_message(sqlite3 *const value, const std::string_view operation)
Definition inbox.cpp:56

References database_, and value_.

◆ statement() [2/6]

arachne::penelope::anonymous_namespace{inbox.cpp}::statement::statement ( const statement & )
delete

◆ statement() [3/6]

arachne::penelope::anonymous_namespace{inbox.cpp}::statement::statement ( statement && )
delete

◆ ~statement() [1/2]

arachne::penelope::anonymous_namespace{inbox.cpp}::statement::~statement ( )
inline

Definition at line 81 of file inbox.cpp.

81 {
82 if (value_ != nullptr) {
83 sqlite3_finalize(value_);
84 }
85 }

References value_.

◆ statement() [4/6]

arachne::penelope::anonymous_namespace{inbox.cpp}::statement::statement ( sqlite3 *const database,
const std::string_view sql )
inline

Definition at line 65 of file inbox.cpp.

66 : database_(database) {
67 if (sqlite3_prepare_v2(
68 database, sql.data(), static_cast<int>(sql.size()), &value_,
69 nullptr
70 )
71 != SQLITE_OK) {
72 throw database_error(sqlite_message(database, "prepare statement"));
73 }
74 }

◆ statement() [5/6]

arachne::penelope::anonymous_namespace{inbox.cpp}::statement::statement ( const statement & )
delete

◆ statement() [6/6]

arachne::penelope::anonymous_namespace{inbox.cpp}::statement::statement ( statement && )
delete

◆ ~statement() [2/2]

arachne::penelope::anonymous_namespace{inbox.cpp}::statement::~statement ( )
inline

Definition at line 81 of file inbox.cpp.

81 {
82 if (value_ != nullptr) {
83 sqlite3_finalize(value_);
84 }
85 }

Member Function Documentation

◆ bind() [1/6]

void arachne::penelope::anonymous_namespace{inbox.cpp}::statement::bind ( const int index,
const double value )
inline

Definition at line 103 of file inbox.cpp.

103 {
104 if (sqlite3_bind_double(value_, index, value) != SQLITE_OK) {
105 throw database_error(sqlite_message(database_, "bind real"));
106 }
107 }

References value_.

Referenced by arachne::penelope::anonymous_namespace{inbox.cpp}::upsert_hint().

Here is the caller graph for this function:

◆ bind() [2/6]

void arachne::penelope::anonymous_namespace{inbox.cpp}::statement::bind ( const int index,
const double value )
inline

Definition at line 103 of file inbox.cpp.

103 {
104 if (sqlite3_bind_double(value_, index, value) != SQLITE_OK) {
105 throw database_error(sqlite_message(database_, "bind real"));
106 }
107 }

◆ bind() [3/6]

◆ bind() [4/6]

void arachne::penelope::anonymous_namespace{inbox.cpp}::statement::bind ( const int index,
const std::int64_t value )
inline

Definition at line 97 of file inbox.cpp.

97 {
98 if (sqlite3_bind_int64(value_, index, value) != SQLITE_OK) {
99 throw database_error(sqlite_message(database_, "bind integer"));
100 }
101 }

◆ bind() [5/6]

void arachne::penelope::anonymous_namespace{inbox.cpp}::statement::bind ( const int index,
const std::string_view value )
inline

Definition at line 87 of file inbox.cpp.

87 {
88 if (sqlite3_bind_text(
89 value_, index, value.data(), static_cast<int>(value.size()),
90 SQLITE_TRANSIENT
91 )
92 != SQLITE_OK) {
93 throw database_error(sqlite_message(database_, "bind text"));
94 }
95 }

References value_.

◆ bind() [6/6]

void arachne::penelope::anonymous_namespace{inbox.cpp}::statement::bind ( const int index,
const std::string_view value )
inline

Definition at line 87 of file inbox.cpp.

87 {
88 if (sqlite3_bind_text(
89 value_, index, value.data(), static_cast<int>(value.size()),
90 SQLITE_TRANSIENT
91 )
92 != SQLITE_OK) {
93 throw database_error(sqlite_message(database_, "bind text"));
94 }
95 }

◆ bind_json_value() [1/2]

void arachne::penelope::anonymous_namespace{inbox.cpp}::statement::bind_json_value ( const int index,
const json & value )
inline

Definition at line 115 of file inbox.cpp.

115 {
116 if (value.is_null()) {
117 bind_null(index);
118 } else if (value.is_string()) {
119 bind(index, value.get_ref<const std::string&>());
120 } else if (value.is_boolean()) {
121 bind(index, static_cast<std::int64_t>(value.get<bool>() ? 1 : 0));
122 } else if (value.is_number_integer()) {
123 bind(index, value.get<std::int64_t>());
124 } else if (value.is_number_unsigned()) {
125 const auto number = value.get<std::uint64_t>();
126 if (number
127 > static_cast<std::uint64_t>(
128 std::numeric_limits<std::int64_t>::max()
129 )) {
130 throw database_error("integer is outside SQLite's range");
131 }
132 bind(index, static_cast<std::int64_t>(number));
133 } else if (value.is_number_float()) {
134 bind(index, value.get<double>());
135 } else {
136 bind(index, value.dump());
137 }
138 }
void bind(const int index, const std::string_view value)
Definition inbox.cpp:87

References bind(), and bind_null().

Here is the call graph for this function:

◆ bind_json_value() [2/2]

void arachne::penelope::anonymous_namespace{inbox.cpp}::statement::bind_json_value ( const int index,
const json & value )
inline

Definition at line 115 of file inbox.cpp.

115 {
116 if (value.is_null()) {
117 bind_null(index);
118 } else if (value.is_string()) {
119 bind(index, value.get_ref<const std::string&>());
120 } else if (value.is_boolean()) {
121 bind(index, static_cast<std::int64_t>(value.get<bool>() ? 1 : 0));
122 } else if (value.is_number_integer()) {
123 bind(index, value.get<std::int64_t>());
124 } else if (value.is_number_unsigned()) {
125 const auto number = value.get<std::uint64_t>();
126 if (number
127 > static_cast<std::uint64_t>(
128 std::numeric_limits<std::int64_t>::max()
129 )) {
130 throw database_error("integer is outside SQLite's range");
131 }
132 bind(index, static_cast<std::int64_t>(number));
133 } else if (value.is_number_float()) {
134 bind(index, value.get<double>());
135 } else {
136 bind(index, value.dump());
137 }
138 }

◆ bind_null() [1/2]

void arachne::penelope::anonymous_namespace{inbox.cpp}::statement::bind_null ( const int index)
inline

Definition at line 109 of file inbox.cpp.

109 {
110 if (sqlite3_bind_null(value_, index) != SQLITE_OK) {
111 throw database_error(sqlite_message(database_, "bind null"));
112 }
113 }

References value_.

Referenced by bind_json_value(), and arachne::penelope::anonymous_namespace{inbox.cpp}::bind_optional().

Here is the caller graph for this function:

◆ bind_null() [2/2]

void arachne::penelope::anonymous_namespace{inbox.cpp}::statement::bind_null ( const int index)
inline

Definition at line 109 of file inbox.cpp.

109 {
110 if (sqlite3_bind_null(value_, index) != SQLITE_OK) {
111 throw database_error(sqlite_message(database_, "bind null"));
112 }
113 }

◆ execute() [1/2]

void arachne::penelope::anonymous_namespace{inbox.cpp}::statement::execute ( )
inline

Definition at line 151 of file inbox.cpp.

151 {
152 if (step()) {
153 throw database_error("statement unexpectedly returned a row");
154 }
155 }

References step().

Referenced by arachne::penelope::anonymous_namespace{inbox.cpp}::apply_one_batch(), arachne::penelope::anonymous_namespace{inbox.cpp}::apply_updates(), arachne::penelope::anonymous_namespace{inbox.cpp}::bootstrap_hint_blocks_if_empty(), arachne::penelope::anonymous_namespace{inbox.cpp}::create_assertions(), arachne::penelope::anonymous_namespace{inbox.cpp}::create_entities(), arachne::penelope::anonymous_namespace{inbox.cpp}::create_facts(), arachne::penelope::anonymous_namespace{inbox.cpp}::create_names_and_identifiers(), arachne::penelope::anonymous_namespace{inbox.cpp}::create_sources_and_evidence(), arachne::penelope::anonymous_namespace{inbox.cpp}::delete_merged_entity(), arachne::penelope::anonymous_namespace{inbox.cpp}::insert_hint_block(), arachne::penelope::anonymous_namespace{inbox.cpp}::merge_agents(), arachne::penelope::anonymous_namespace{inbox.cpp}::merge_credits(), arachne::penelope::anonymous_namespace{inbox.cpp}::merge_entity_scoped_rows(), arachne::penelope::anonymous_namespace{inbox.cpp}::merge_financial_facts(), arachne::penelope::anonymous_namespace{inbox.cpp}::merge_parent_guides(), arachne::penelope::anonymous_namespace{inbox.cpp}::merge_work_concepts(), arachne::penelope::anonymous_namespace{inbox.cpp}::transfer_assertion_evidence(), arachne::penelope::anonymous_namespace{inbox.cpp}::update_row(), and arachne::penelope::anonymous_namespace{inbox.cpp}::upsert_hint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ execute() [2/2]

void arachne::penelope::anonymous_namespace{inbox.cpp}::statement::execute ( )
inline

Definition at line 151 of file inbox.cpp.

151 {
152 if (step()) {
153 throw database_error("statement unexpectedly returned a row");
154 }
155 }

◆ integer() [1/2]

◆ integer() [2/2]

std::int64_t arachne::penelope::anonymous_namespace{inbox.cpp}::statement::integer ( const int column) const
inlinenodiscard

Definition at line 157 of file inbox.cpp.

157 {
158 return sqlite3_column_int64(value_, column);
159 }

◆ is_null() [1/2]

bool arachne::penelope::anonymous_namespace{inbox.cpp}::statement::is_null ( const int column) const
inlinenodiscard

Definition at line 173 of file inbox.cpp.

173 {
174 return sqlite3_column_type(value_, column) == SQLITE_NULL;
175 }

References value_.

Referenced by arachne::penelope::anonymous_namespace{inbox.cpp}::prevalidate_semantics().

Here is the caller graph for this function:

◆ is_null() [2/2]

bool arachne::penelope::anonymous_namespace{inbox.cpp}::statement::is_null ( const int column) const
inlinenodiscard

Definition at line 173 of file inbox.cpp.

173 {
174 return sqlite3_column_type(value_, column) == SQLITE_NULL;
175 }

◆ native() [1/2]

sqlite3_stmt * arachne::penelope::anonymous_namespace{inbox.cpp}::statement::native ( ) const
inlinenodiscardnoexcept

Definition at line 177 of file inbox.cpp.

177{ return value_; }

References value_.

Referenced by arachne::penelope::anonymous_namespace{inbox.cpp}::insert_hint_block().

Here is the caller graph for this function:

◆ native() [2/2]

sqlite3_stmt * arachne::penelope::anonymous_namespace{inbox.cpp}::statement::native ( ) const
inlinenodiscardnoexcept

Definition at line 177 of file inbox.cpp.

177{ return value_; }

◆ operator=() [1/4]

statement & arachne::penelope::anonymous_namespace{inbox.cpp}::statement::operator= ( const statement & )
delete

◆ operator=() [2/4]

statement & arachne::penelope::anonymous_namespace{inbox.cpp}::statement::operator= ( const statement & )
delete

◆ operator=() [3/4]

statement & arachne::penelope::anonymous_namespace{inbox.cpp}::statement::operator= ( statement && )
delete

◆ operator=() [4/4]

statement & arachne::penelope::anonymous_namespace{inbox.cpp}::statement::operator= ( statement && )
delete

◆ real() [1/2]

double arachne::penelope::anonymous_namespace{inbox.cpp}::statement::real ( const int column) const
inlinenodiscard

Definition at line 161 of file inbox.cpp.

161 {
162 return sqlite3_column_double(value_, column);
163 }

References value_.

◆ real() [2/2]

double arachne::penelope::anonymous_namespace{inbox.cpp}::statement::real ( const int column) const
inlinenodiscard

Definition at line 161 of file inbox.cpp.

161 {
162 return sqlite3_column_double(value_, column);
163 }

◆ step() [1/2]

bool arachne::penelope::anonymous_namespace{inbox.cpp}::statement::step ( )
inlinenodiscard

Definition at line 140 of file inbox.cpp.

140 {
141 const int status = sqlite3_step(value_);
142 if (status == SQLITE_ROW) {
143 return true;
144 }
145 if (status == SQLITE_DONE) {
146 return false;
147 }
148 throw database_error(sqlite_message(database_, "execute statement"));
149 }

References value_.

Referenced by arachne::penelope::anonymous_namespace{inbox.cpp}::all_blocked_pairs(), arachne::penelope::anonymous_namespace{inbox.cpp}::all_hint_labels(), arachne::penelope::anonymous_namespace{inbox.cpp}::batch_was_applied(), arachne::penelope::anonymous_namespace{inbox.cpp}::bootstrap_hint_blocks_if_empty(), arachne::penelope::anonymous_namespace{inbox.cpp}::calculate_hint_components(), arachne::penelope::anonymous_namespace{inbox.cpp}::database::database(), arachne::penelope::anonymous_namespace{inbox.cpp}::entity_family(), execute(), arachne::penelope::anonymous_namespace{inbox.cpp}::hint_label_for_id(), arachne::penelope::anonymous_namespace{inbox.cpp}::insert_hint_block(), arachne::penelope::anonymous_namespace{inbox.cpp}::insert_hint_blocks(), arachne::penelope::anonymous_namespace{inbox.cpp}::maximum_entity_suffix(), arachne::penelope::anonymous_namespace{inbox.cpp}::maximum_row_id(), arachne::penelope::anonymous_namespace{inbox.cpp}::merge_concept_relations(), arachne::penelope::anonymous_namespace{inbox.cpp}::merge_parent_guides(), arachne::penelope::anonymous_namespace{inbox.cpp}::merge_work_concepts(), arachne::penelope::anonymous_namespace{inbox.cpp}::prevalidate_semantics(), arachne::penelope::anonymous_namespace{inbox.cpp}::query_exists(), arachne::penelope::anonymous_namespace{inbox.cpp}::query_value_set(), arachne::penelope::anonymous_namespace{inbox.cpp}::rebuild_hints(), arachne::penelope::anonymous_namespace{inbox.cpp}::reject_preferred_name_conflict(), arachne::penelope::anonymous_namespace{inbox.cpp}::require_clean_foreign_keys(), arachne::penelope::anonymous_namespace{inbox.cpp}::require_current_product_structure(), and arachne::penelope::anonymous_namespace{inbox.cpp}::row_exists().

Here is the caller graph for this function:

◆ step() [2/2]

bool arachne::penelope::anonymous_namespace{inbox.cpp}::statement::step ( )
inlinenodiscard

Definition at line 140 of file inbox.cpp.

140 {
141 const int status = sqlite3_step(value_);
142 if (status == SQLITE_ROW) {
143 return true;
144 }
145 if (status == SQLITE_DONE) {
146 return false;
147 }
148 throw database_error(sqlite_message(database_, "execute statement"));
149 }

◆ text() [1/2]

◆ text() [2/2]

std::string arachne::penelope::anonymous_namespace{inbox.cpp}::statement::text ( const int column) const
inlinenodiscard

Definition at line 165 of file inbox.cpp.

165 {
166 const auto* bytes = sqlite3_column_text(value_, column);
167 if (bytes == nullptr) {
168 return {};
169 }
170 return reinterpret_cast<const char*>(bytes);
171 }

Member Data Documentation

◆ database_

sqlite3 * arachne::penelope::anonymous_namespace{inbox.cpp}::statement::database_ { nullptr }
private

Definition at line 180 of file inbox.cpp.

180{ nullptr };

Referenced by statement().

◆ value_

sqlite3_stmt * arachne::penelope::anonymous_namespace{inbox.cpp}::statement::value_ { nullptr }
private

Definition at line 181 of file inbox.cpp.

181{ nullptr };

Referenced by bind(), bind(), bind(), bind_null(), integer(), is_null(), native(), real(), statement(), step(), text(), and ~statement().


The documentation for this class was generated from the following file: