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 415 : static inline void data_database_borrowed_stmt_init_void ( data_database_borrowed_stmt_t *this_ ) 8 : { 9 415 : (*this_).database = NULL; 10 415 : (*this_).db_statement = NULL; 11 415 : (*this_).borrow_flag = NULL; 12 415 : } 13 : 14 415 : 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 415 : U8_TRACE_BEGIN(); 20 415 : assert( database != NULL ); 21 415 : assert( db_statement != NULL ); 22 415 : assert( borrow_flag != NULL ); 23 415 : u8_error_t result = U8_ERROR_NONE; 24 : 25 415 : (*this_).database = database; 26 415 : (*this_).db_statement = db_statement; 27 415 : (*this_).borrow_flag = borrow_flag; 28 415 : if ( *borrow_flag == true ) 29 : { 30 0 : result = U8_ERROR_WRONG_STATE; 31 : } 32 : else 33 : { 34 415 : *((*this_).borrow_flag) = true; 35 : } 36 : 37 415 : U8_TRACE_END_ERR( result ); 38 415 : return result; 39 : } 40 : 41 830 : static inline u8_error_t data_database_borrowed_stmt_destroy ( data_database_borrowed_stmt_t *this_ ) 42 : { 43 830 : U8_TRACE_BEGIN(); 44 830 : u8_error_t result = U8_ERROR_NONE; 45 : 46 830 : if ( (*this_).borrow_flag != NULL ) 47 : { 48 415 : assert( *((*this_).borrow_flag) == true ); /* noone interfered with the status */ 49 415 : assert( (*this_).db_statement != NULL ); 50 : 51 415 : const int sqlite_err = sqlite3_reset( (*this_).db_statement ); 52 415 : 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 415 : *((*this_).borrow_flag) = false; 59 415 : (*this_).borrow_flag = NULL; 60 : } 61 : 62 830 : U8_TRACE_END_ERR( result ); 63 830 : return result; 64 : } 65 : 66 2711 : static inline bool data_database_borrowed_stmt_is_valid ( const data_database_borrowed_stmt_t *this_ ) 67 : { 68 2711 : return ((*this_).database != NULL ) && ((*this_).db_statement != NULL ) && ((*this_).borrow_flag != NULL ); 69 : } 70 : 71 2265 : static inline sqlite3_stmt * data_database_borrowed_stmt_get_statement ( const data_database_borrowed_stmt_t *this_ ) 72 : { 73 2265 : assert( (*this_).db_statement != NULL ); 74 2265 : 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 : */