Line data Source code
1 : /* File: data_database_text_search.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 : 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 : #if 0
40 : static inline u8_error_t data_database_text_search_private_bind_two_texts_to_statement ( data_database_text_search_t *this_,
41 : sqlite3_stmt *statement_ptr,
42 : const char *text_1,
43 : const char *text_2 )
44 : {
45 : assert( NULL != statement_ptr );
46 : assert( NULL != text_1 );
47 : assert( NULL != text_2 );
48 : u8_error_t result = U8_ERROR_NONE;
49 : static const int FIRST_SQL_BIND_PARAM = 1;
50 : static const int SECOND_SQL_BIND_PARAM = 2;
51 : int sqlite_err;
52 :
53 : sqlite_err = sqlite3_reset( statement_ptr );
54 : if ( SQLITE_OK != sqlite_err )
55 : {
56 : U8_LOG_ERROR_INT( "sqlite3_reset() failed:", sqlite_err );
57 : result |= U8_ERROR_AT_DB;
58 : }
59 :
60 : U8_TRACE_INFO_STR( "sqlite3_bind_text():", sqlite3_sql(statement_ptr) );
61 : /* SQLITE_STATIC vs SQLITE_TRANSIENT: This function is used to perform a SELECT statement. */
62 : /* During the SELECT, the text string is not modified. This is guaranteed by data_database_text_search. */
63 : U8_TRACE_INFO_STR( "sqlite3_bind_text():", text_1 );
64 : sqlite_err = sqlite3_bind_text( statement_ptr, FIRST_SQL_BIND_PARAM, text_1, -1, SQLITE_STATIC );
65 : if ( SQLITE_OK != sqlite_err )
66 : {
67 : U8_LOG_ERROR_INT( "sqlite3_bind_text() failed:", sqlite_err );
68 : result |= U8_ERROR_AT_DB;
69 : }
70 : U8_TRACE_INFO_STR( "sqlite3_bind_text():", text_2 );
71 : sqlite_err = sqlite3_bind_text( statement_ptr, SECOND_SQL_BIND_PARAM, text_2, -1, SQLITE_STATIC );
72 : if ( SQLITE_OK != sqlite_err )
73 : {
74 : U8_LOG_ERROR_INT( "sqlite3_bind_text() failed:", sqlite_err );
75 : result |= U8_ERROR_AT_DB;
76 : }
77 :
78 : return result;
79 : }
80 : #endif
81 :
82 0 : static inline u8_error_t data_database_text_search_private_bind_three_texts_to_statement ( data_database_text_search_t *this_,
83 : sqlite3_stmt *statement_ptr,
84 : const char *text_1,
85 : const char *text_2,
86 : const char *text_3 )
87 : {
88 0 : assert( NULL != statement_ptr );
89 0 : assert( NULL != text_1 );
90 0 : assert( NULL != text_2 );
91 0 : assert( NULL != text_3 );
92 0 : u8_error_t result = U8_ERROR_NONE;
93 : static const int FIRST_SQL_BIND_PARAM = 1;
94 : static const int SECOND_SQL_BIND_PARAM = 2;
95 : static const int THIRD_SQL_BIND_PARAM = 3;
96 : int sqlite_err;
97 :
98 0 : sqlite_err = sqlite3_reset( statement_ptr );
99 0 : if ( SQLITE_OK != sqlite_err )
100 : {
101 0 : U8_LOG_ERROR_INT( "sqlite3_reset() failed:", sqlite_err );
102 0 : result |= U8_ERROR_AT_DB;
103 : }
104 :
105 0 : U8_TRACE_INFO_STR( "sqlite3_bind_text():", sqlite3_sql(statement_ptr) );
106 : /* SQLITE_STATIC vs SQLITE_TRANSIENT: This function is used to perform a SELECT statement. */
107 : /* During the SELECT, the text string is not modified. This is guaranteed by data_database_text_search. */
108 0 : U8_TRACE_INFO_STR( "sqlite3_bind_text():", text_1 );
109 0 : sqlite_err = sqlite3_bind_text( statement_ptr, FIRST_SQL_BIND_PARAM, text_1, -1, SQLITE_STATIC );
110 0 : if ( SQLITE_OK != sqlite_err )
111 : {
112 0 : U8_LOG_ERROR_INT( "sqlite3_bind_text() failed:", sqlite_err );
113 0 : result |= U8_ERROR_AT_DB;
114 : }
115 0 : U8_TRACE_INFO_STR( "sqlite3_bind_text():", text_2 );
116 0 : sqlite_err = sqlite3_bind_text( statement_ptr, SECOND_SQL_BIND_PARAM, text_2, -1, SQLITE_STATIC );
117 0 : if ( SQLITE_OK != sqlite_err )
118 : {
119 0 : U8_LOG_ERROR_INT( "sqlite3_bind_text() failed:", sqlite_err );
120 0 : result |= U8_ERROR_AT_DB;
121 : }
122 0 : U8_TRACE_INFO_STR( "sqlite3_bind_text():", text_3 );
123 0 : sqlite_err = sqlite3_bind_text( statement_ptr, THIRD_SQL_BIND_PARAM, text_3, -1, SQLITE_STATIC );
124 0 : if ( SQLITE_OK != sqlite_err )
125 : {
126 0 : U8_LOG_ERROR_INT( "sqlite3_bind_text() failed:", sqlite_err );
127 0 : result |= U8_ERROR_AT_DB;
128 : }
129 :
130 0 : return result;
131 : }
132 :
133 :
134 : /*
135 : Copyright 2020-2024 Andreas Warnke
136 :
137 : Licensed under the Apache License, Version 2.0 (the "License");
138 : you may not use this file except in compliance with the License.
139 : You may obtain a copy of the License at
140 :
141 : http://www.apache.org/licenses/LICENSE-2.0
142 :
143 : Unless required by applicable law or agreed to in writing, software
144 : distributed under the License is distributed on an "AS IS" BASIS,
145 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
146 : See the License for the specific language governing permissions and
147 : limitations under the License.
148 : */
|