Line data Source code
1 : /* File: data_database_borrowed_stmt.inl; Copyright and License: see below */
2 :
3 : #include "u8/u8_log.h"
4 : #include "u8/u8_trace.h"
5 : #include <assert.h>
6 :
7 407 : static inline void data_database_borrowed_stmt_init_void ( data_database_borrowed_stmt_t *this_ )
8 : {
9 407 : (*this_).database = NULL;
10 407 : (*this_).db_statement = NULL;
11 407 : (*this_).borrow_flag = NULL;
12 407 : }
13 :
14 407 : static inline u8_error_t data_database_borrowed_stmt_init ( data_database_borrowed_stmt_t *this_,
15 : data_database_t *database,
16 : sqlite3_stmt *db_statement,
17 : bool *borrow_flag )
18 : {
19 407 : U8_TRACE_BEGIN();
20 407 : assert( database != NULL );
21 407 : assert( db_statement != NULL );
22 407 : assert( borrow_flag != NULL );
23 407 : u8_error_t result = U8_ERROR_NONE;
24 :
25 407 : (*this_).database = database;
26 407 : (*this_).db_statement = db_statement;
27 407 : (*this_).borrow_flag = borrow_flag;
28 407 : if ( *borrow_flag == true )
29 : {
30 0 : result = U8_ERROR_WRONG_STATE;
31 : }
32 : else
33 : {
34 407 : *((*this_).borrow_flag) = true;
35 : }
36 :
37 407 : U8_TRACE_END_ERR( result );
38 407 : return result;
39 : }
40 :
41 814 : static inline u8_error_t data_database_borrowed_stmt_destroy ( data_database_borrowed_stmt_t *this_ )
42 : {
43 814 : U8_TRACE_BEGIN();
44 814 : u8_error_t result = U8_ERROR_NONE;
45 :
46 814 : if ( (*this_).borrow_flag != NULL )
47 : {
48 407 : assert( *((*this_).borrow_flag) == true ); /* noone interfered with the status */
49 407 : assert( (*this_).db_statement != NULL );
50 :
51 407 : const int sqlite_err = sqlite3_reset( (*this_).db_statement );
52 407 : if ( sqlite_err != SQLITE_OK )
53 : {
54 0 : U8_LOG_ERROR_INT( "sqlite3_reset() failed:", sqlite_err );
55 0 : result |= U8_ERROR_AT_DB;
56 : }
57 :
58 407 : *((*this_).borrow_flag) = false;
59 407 : (*this_).borrow_flag = NULL;
60 : }
61 :
62 814 : U8_TRACE_END_ERR( result );
63 814 : return result;
64 : }
65 :
66 2667 : static inline bool data_database_borrowed_stmt_is_valid ( const data_database_borrowed_stmt_t *this_ )
67 : {
68 2667 : return ((*this_).database != NULL ) && ((*this_).db_statement != NULL ) && ((*this_).borrow_flag != NULL );
69 : }
70 :
71 2253 : static inline sqlite3_stmt * data_database_borrowed_stmt_get_statement ( const data_database_borrowed_stmt_t *this_ )
72 : {
73 2253 : assert( (*this_).db_statement != NULL );
74 2253 : return (*this_).db_statement;
75 : }
76 :
77 : static inline data_database_t * data_database_borrowed_stmt_get_database ( data_database_borrowed_stmt_t *this_ )
78 : {
79 : assert( (*this_).database != NULL );
80 : return (*this_).database;
81 : }
82 :
83 :
84 : /*
85 : Copyright 2024-2025 Andreas Warnke
86 :
87 : Licensed under the Apache License, Version 2.0 (the "License");
88 : you may not use this file except in compliance with the License.
89 : You may obtain a copy of the License at
90 :
91 : http://www.apache.org/licenses/LICENSE-2.0
92 :
93 : Unless required by applicable law or agreed to in writing, software
94 : distributed under the License is distributed on an "AS IS" BASIS,
95 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
96 : See the License for the specific language governing permissions and
97 : limitations under the License.
98 : */
|