LCOV - code coverage report
Current view: top level - data/include/storage - data_database_classifier_reader.inl (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.42.0_alltests Lines: 61 82 74.4 %
Date: 2022-10-01 11:23:42 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /* File: data_database_classifier_reader.inl; Copyright and License: see below */
       2             : 
       3             : #include "tslog/tslog.h"
       4             : #include "trace/trace.h"
       5             : #include <assert.h>
       6             : 
       7             : /* ================================ private ================================ */
       8             : 
       9       15994 : static inline u8_error_t data_database_classifier_reader_private_prepare_statement ( data_database_classifier_reader_t *this_,
      10             :                                                                                      const char *string_statement,
      11             :                                                                                      int string_size,
      12             :                                                                                      sqlite3_stmt **out_statement_ptr )
      13             : {
      14       15994 :     assert( NULL != string_statement );
      15       15994 :     assert( NULL != out_statement_ptr );
      16       15994 :     u8_error_t result = U8_ERROR_NONE;
      17       15994 :     const char *first_unused_statement_char;
      18       15994 :     int sqlite_err;
      19       15994 :     sqlite3 *db;
      20             : 
      21       15994 :     db = data_database_get_database_ptr ( (*this_).database );
      22             : 
      23       15994 :     TRACE_INFO_STR( "sqlite3_prepare_v2():", string_statement );
      24       15994 :     sqlite_err = sqlite3_prepare_v2( db,
      25             :                                      string_statement,
      26             :                                      string_size,
      27             :                                      out_statement_ptr,
      28             :                                      &first_unused_statement_char
      29             :                                    );
      30       15994 :     if (( SQLITE_OK != sqlite_err )
      31       15994 :         || ( first_unused_statement_char != &(string_statement[string_size-1]) ))
      32             :     {
      33           0 :         TSLOG_ERROR_STR( "sqlite3_prepare_v2() failed:", string_statement );
      34           0 :         TSLOG_ERROR_INT( "sqlite3_prepare_v2() failed:", sqlite_err );
      35           0 :         TSLOG_ERROR_STR( "sqlite3_prepare_v2() failed:", sqlite3_errmsg( db ) );
      36           0 :         result |= U8_ERROR_AT_DB;
      37             :     }
      38             : 
      39       15994 :     return result;
      40             : }
      41             : 
      42        1209 : static inline u8_error_t data_database_classifier_reader_private_finalize_statement ( data_database_classifier_reader_t *this_, sqlite3_stmt *statement_ptr )
      43             : {
      44        1209 :     assert( NULL != statement_ptr );
      45        1209 :     u8_error_t result = U8_ERROR_NONE;
      46        1209 :     int sqlite_err;
      47             : 
      48        1209 :     TRACE_INFO_STR( "sqlite3_finalize():", sqlite3_sql(statement_ptr) );
      49        1209 :     sqlite_err = sqlite3_finalize( statement_ptr );
      50        1209 :     if ( SQLITE_OK != sqlite_err )
      51             :     {
      52           0 :         TSLOG_ERROR_STR( "sqlite3_finalize() failed:", sqlite3_sql(statement_ptr) );
      53           0 :         TSLOG_ERROR_INT( "sqlite3_finalize() failed:", sqlite_err );
      54           0 :         result |= U8_ERROR_AT_DB;
      55             :     }
      56             : 
      57        1209 :     return result;
      58             : }
      59             : 
      60      591438 : static inline u8_error_t data_database_classifier_reader_private_bind_id_to_statement ( data_database_classifier_reader_t *this_,
      61             :                                                                                         sqlite3_stmt *statement_ptr,
      62             :                                                                                         data_row_id_t id )
      63             : {
      64      591438 :     assert( NULL != statement_ptr );
      65      591438 :     u8_error_t result = U8_ERROR_NONE;
      66      591438 :     static const int FIRST_SQL_BIND_PARAM = 1;
      67      591438 :     int sqlite_err;
      68             : 
      69      591438 :     sqlite_err = sqlite3_reset( statement_ptr );
      70      591438 :     if ( SQLITE_OK != sqlite_err )
      71             :     {
      72           0 :         TSLOG_ERROR_INT( "sqlite3_reset() failed:", sqlite_err );
      73           0 :         result |= U8_ERROR_AT_DB;
      74             :     }
      75             : 
      76      591438 :     TRACE_INFO_STR( "sqlite3_bind_int64():", sqlite3_sql(statement_ptr) );
      77      591438 :     TRACE_INFO_INT( "sqlite3_bind_int64():", id );
      78      591438 :     sqlite_err = sqlite3_bind_int64( statement_ptr, FIRST_SQL_BIND_PARAM, id );
      79      591438 :     if ( SQLITE_OK != sqlite_err )
      80             :     {
      81           0 :         TSLOG_ERROR_INT( "sqlite3_bind_int64() failed:", sqlite_err );
      82           0 :         result |= U8_ERROR_AT_DB;
      83             :     }
      84             : 
      85      591438 :     return result;
      86             : }
      87             : 
      88      159583 : static inline u8_error_t data_database_classifier_reader_private_bind_two_ids_to_statement ( data_database_classifier_reader_t *this_,
      89             :                                                                                              sqlite3_stmt *statement_ptr,
      90             :                                                                                              data_row_id_t id1,
      91             :                                                                                              data_row_id_t id2 )
      92             : {
      93      159583 :     assert( NULL != statement_ptr );
      94      159583 :     u8_error_t result = U8_ERROR_NONE;
      95      159583 :     static const int FIRST_SQL_BIND_PARAM = 1;
      96      159583 :     static const int SECOND_SQL_BIND_PARAM = 2;
      97      159583 :     int sqlite_err;
      98             : 
      99      159583 :     sqlite_err = sqlite3_reset( statement_ptr );
     100      159583 :     if ( SQLITE_OK != sqlite_err )
     101             :     {
     102           0 :         TSLOG_ERROR_INT( "sqlite3_reset() failed:", sqlite_err );
     103           0 :         result |= U8_ERROR_AT_DB;
     104             :     }
     105             : 
     106      159583 :     TRACE_INFO_STR( "sqlite3_bind_int64():", sqlite3_sql(statement_ptr) );
     107      159583 :     TRACE_INFO_INT_INT( "sqlite3_bind_int64():", id1, id2 );
     108      159583 :     sqlite_err = sqlite3_bind_int64( statement_ptr, FIRST_SQL_BIND_PARAM, id1 );
     109      159583 :     if ( SQLITE_OK != sqlite_err )
     110             :     {
     111           0 :         TSLOG_ERROR_INT( "sqlite3_bind_int64() failed:", sqlite_err );
     112           0 :         result |= U8_ERROR_AT_DB;
     113             :     }
     114      159583 :     sqlite_err = sqlite3_bind_int64( statement_ptr, SECOND_SQL_BIND_PARAM, id2 );
     115      159583 :     if ( SQLITE_OK != sqlite_err )
     116             :     {
     117           0 :         TSLOG_ERROR_INT( "sqlite3_bind_int64() failed:", sqlite_err );
     118           0 :         result |= U8_ERROR_AT_DB;
     119             :     }
     120             : 
     121      159583 :     return result;
     122             : }
     123             : 
     124         123 : static inline u8_error_t data_database_classifier_reader_private_bind_text_to_statement ( data_database_classifier_reader_t *this_,
     125             :                                                                                           sqlite3_stmt *statement_ptr,
     126             :                                                                                           const char *text )
     127             : {
     128         123 :     assert( NULL != statement_ptr );
     129         123 :     assert( NULL != text );
     130         123 :     u8_error_t result = U8_ERROR_NONE;
     131         123 :     static const int FIRST_SQL_BIND_PARAM = 1;
     132         123 :     int sqlite_err;
     133             : 
     134         123 :     sqlite_err = sqlite3_reset( statement_ptr );
     135         123 :     if ( SQLITE_OK != sqlite_err )
     136             :     {
     137           0 :         TSLOG_ERROR_INT( "sqlite3_reset() failed:", sqlite_err );
     138           0 :         result |= U8_ERROR_AT_DB;
     139             :     }
     140             : 
     141         123 :     TRACE_INFO_STR( "sqlite3_bind_text():", sqlite3_sql(statement_ptr) );
     142             :     /* SQLITE_STATIC vs SQLITE_TRANSIENT: This function is used to perform a SELECT statement. */
     143             :     /* During the SELECT, the text string is not modified. This is guaranteed by data_database_classifier_reader. */
     144         123 :     TRACE_INFO_STR( "sqlite3_bind_text():", text );
     145         123 :     sqlite_err = sqlite3_bind_text( statement_ptr, FIRST_SQL_BIND_PARAM, text, -1, SQLITE_STATIC );
     146         123 :     if ( SQLITE_OK != sqlite_err )
     147             :     {
     148           0 :         TSLOG_ERROR_INT( "sqlite3_bind_text() failed:", sqlite_err );
     149           0 :         result |= U8_ERROR_AT_DB;
     150             :     }
     151             : 
     152         123 :     return result;
     153             : }
     154             : 
     155             : 
     156             : /*
     157             : Copyright 2016-2022 Andreas Warnke
     158             : 
     159             : Licensed under the Apache License, Version 2.0 (the "License");
     160             : you may not use this file except in compliance with the License.
     161             : You may obtain a copy of the License at
     162             : 
     163             :     http://www.apache.org/licenses/LICENSE-2.0
     164             : 
     165             : Unless required by applicable law or agreed to in writing, software
     166             : distributed under the License is distributed on an "AS IS" BASIS,
     167             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     168             : See the License for the specific language governing permissions and
     169             : limitations under the License.
     170             : */

Generated by: LCOV version 1.14