LCOV - code coverage report
Current view: top level - data/include/storage - data_database_text_search.inl (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.42.0_alltests Lines: 0 83 0.0 %
Date: 2022-10-01 11:23:42 Functions: 0 4 0.0 %

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

Generated by: LCOV version 1.14