LCOV - code coverage report
Current view: top level - data/include/storage - data_database_borrowed_stmt.inl (source / functions) Coverage Total Hit
Test: crystal-facet-uml_v1.70.2_covts Lines: 94.7 % 38 36
Test Date: 2026-05-03 11:56:31 Functions: 100.0 % 5 5

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

Generated by: LCOV version 2.0-1