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

          Line data    Source code
       1             : /* File: data_database_diagram_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        1116 : static inline u8_error_t data_database_diagram_reader_private_prepare_statement ( data_database_diagram_reader_t *this_,
      10             :                                                                                   const char *string_statement,
      11             :                                                                                   int string_size,
      12             :                                                                                   sqlite3_stmt **out_statement_ptr )
      13             : {
      14        1116 :     assert( NULL != string_statement );
      15        1116 :     assert( NULL != out_statement_ptr );
      16        1116 :     u8_error_t result = U8_ERROR_NONE;
      17        1116 :     const char *first_unused_statement_char;
      18        1116 :     int sqlite_err;
      19        1116 :     sqlite3 *db;
      20             : 
      21        1116 :     db = data_database_get_database_ptr ( (*this_).database );
      22             : 
      23        1116 :     TRACE_INFO_STR( "sqlite3_prepare_v2():", string_statement );
      24        1116 :     sqlite_err = sqlite3_prepare_v2( db,
      25             :                                      string_statement,
      26             :                                      string_size,
      27             :                                      out_statement_ptr,
      28             :                                      &first_unused_statement_char
      29             :                                    );
      30        1116 :     if (( SQLITE_OK != sqlite_err )
      31        1116 :         || ( 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        1116 :     return result;
      40             : }
      41             : 
      42        1116 : static inline u8_error_t data_database_diagram_reader_private_finalize_statement ( data_database_diagram_reader_t *this_, sqlite3_stmt *statement_ptr )
      43             : {
      44        1116 :     assert( NULL != statement_ptr );
      45        1116 :     u8_error_t result = U8_ERROR_NONE;
      46        1116 :     int sqlite_err;
      47             : 
      48        1116 :     TRACE_INFO_STR( "sqlite3_finalize():", sqlite3_sql(statement_ptr) );
      49        1116 :     sqlite_err = sqlite3_finalize( statement_ptr );
      50        1116 :     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        1116 :     return result;
      58             : }
      59             : 
      60          59 : static inline u8_error_t data_database_diagram_reader_private_bind_void_to_statement ( data_database_diagram_reader_t *this_,
      61             :                                                                                        sqlite3_stmt *statement_ptr )
      62             : {
      63          59 :     assert( NULL != statement_ptr );
      64          59 :     u8_error_t result = U8_ERROR_NONE;
      65          59 :     int sqlite_err;
      66             : 
      67          59 :     sqlite_err = sqlite3_reset( statement_ptr );
      68          59 :     if ( SQLITE_OK != sqlite_err )
      69             :     {
      70           0 :         TSLOG_ERROR_INT( "sqlite3_reset() failed:", sqlite_err );
      71           0 :         result |= U8_ERROR_AT_DB;
      72             :     }
      73             : 
      74          59 :     return result;
      75             : }
      76             : 
      77       16035 : static inline u8_error_t data_database_diagram_reader_private_bind_id_to_statement ( data_database_diagram_reader_t *this_,
      78             :                                                                                      sqlite3_stmt *statement_ptr,
      79             :                                                                                      data_row_id_t id )
      80             : {
      81       16035 :     assert( NULL != statement_ptr );
      82       16035 :     u8_error_t result = U8_ERROR_NONE;
      83       16035 :     static const int FIRST_SQL_BIND_PARAM = 1;
      84       16035 :     int sqlite_err;
      85             : 
      86       16035 :     sqlite_err = sqlite3_reset( statement_ptr );
      87       16035 :     if ( SQLITE_OK != sqlite_err )
      88             :     {
      89           0 :         TSLOG_ERROR_INT( "sqlite3_reset() failed:", sqlite_err );
      90           0 :         result |= U8_ERROR_AT_DB;
      91             :     }
      92             : 
      93       16035 :     TRACE_INFO_STR( "sqlite3_bind_int64():", sqlite3_sql(statement_ptr) );
      94       16035 :     TRACE_INFO_INT( "sqlite3_bind_int64():", id );
      95       16035 :     sqlite_err = sqlite3_bind_int64( statement_ptr, FIRST_SQL_BIND_PARAM, id );
      96       16035 :     if ( SQLITE_OK != sqlite_err )
      97             :     {
      98           0 :         TSLOG_ERROR_INT( "sqlite3_bind_int64() failed:", sqlite_err );
      99           0 :         result |= U8_ERROR_AT_DB;
     100             :     }
     101             : 
     102       16035 :     return result;
     103             : }
     104             : 
     105          12 : static inline u8_error_t data_database_diagram_reader_private_bind_text_to_statement ( data_database_diagram_reader_t *this_,
     106             :                                                                                        sqlite3_stmt *statement_ptr,
     107             :                                                                                        const char *text )
     108             : {
     109          12 :     assert( NULL != statement_ptr );
     110          12 :     assert( NULL != text );
     111          12 :     u8_error_t result = U8_ERROR_NONE;
     112          12 :     static const int FIRST_SQL_BIND_PARAM = 1;
     113          12 :     int sqlite_err;
     114             : 
     115          12 :     sqlite_err = sqlite3_reset( statement_ptr );
     116          12 :     if ( SQLITE_OK != sqlite_err )
     117             :     {
     118           0 :         TSLOG_ERROR_INT( "sqlite3_reset() failed:", sqlite_err );
     119           0 :         result |= U8_ERROR_AT_DB;
     120             :     }
     121             : 
     122          12 :     TRACE_INFO_STR( "sqlite3_bind_text():", sqlite3_sql(statement_ptr) );
     123             :     /* SQLITE_STATIC vs SQLITE_TRANSIENT: This function is used to perform a SELECT statement. */
     124             :     /* During the SELECT, the text string is not modified. This is guaranteed by data_database_diagram_reader. */
     125          12 :     TRACE_INFO_STR( "sqlite3_bind_text():", text );
     126          12 :     sqlite_err = sqlite3_bind_text( statement_ptr, FIRST_SQL_BIND_PARAM, text, -1, SQLITE_STATIC );
     127          12 :     if ( SQLITE_OK != sqlite_err )
     128             :     {
     129           0 :         TSLOG_ERROR_INT( "sqlite3_bind_text() failed:", sqlite_err );
     130           0 :         result |= U8_ERROR_AT_DB;
     131             :     }
     132             : 
     133          12 :     return result;
     134             : }
     135             : 
     136             : 
     137             : /*
     138             : Copyright 2016-2022 Andreas Warnke
     139             : 
     140             : Licensed under the Apache License, Version 2.0 (the "License");
     141             : you may not use this file except in compliance with the License.
     142             : You may obtain a copy of the License at
     143             : 
     144             :     http://www.apache.org/licenses/LICENSE-2.0
     145             : 
     146             : Unless required by applicable law or agreed to in writing, software
     147             : distributed under the License is distributed on an "AS IS" BASIS,
     148             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     149             : See the License for the specific language governing permissions and
     150             : limitations under the License.
     151             : */

Generated by: LCOV version 1.14