Line data Source code
1 : /* File: data_database_classifier_reader.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 : /* ================================ private ================================ */
8 :
9 97 : static inline u8_error_t data_database_classifier_reader_private_bind_id_to_statement ( data_database_classifier_reader_t *this_,
10 : sqlite3_stmt *statement_ptr,
11 : data_row_t id )
12 : {
13 97 : assert( NULL != statement_ptr );
14 97 : u8_error_t result = U8_ERROR_NONE;
15 : static const int FIRST_SQL_BIND_PARAM = 1;
16 : int sqlite_err;
17 :
18 97 : sqlite_err = sqlite3_reset( statement_ptr );
19 97 : if ( SQLITE_OK != sqlite_err )
20 : {
21 0 : U8_LOG_ERROR_INT( "sqlite3_reset() failed:", sqlite_err );
22 0 : result |= U8_ERROR_AT_DB;
23 : }
24 :
25 97 : U8_TRACE_INFO_STR( "sqlite3_bind_int64():", sqlite3_sql(statement_ptr) );
26 97 : U8_TRACE_INFO_INT( "sqlite3_bind_int64():", id );
27 97 : sqlite_err = sqlite3_bind_int64( statement_ptr, FIRST_SQL_BIND_PARAM, id );
28 97 : if ( SQLITE_OK != sqlite_err )
29 : {
30 0 : U8_LOG_ERROR_INT( "sqlite3_bind_int64() failed:", sqlite_err );
31 0 : result |= U8_ERROR_AT_DB;
32 : }
33 :
34 97 : return result;
35 : }
36 :
37 23 : static inline u8_error_t data_database_classifier_reader_private_bind_two_ids_to_statement ( data_database_classifier_reader_t *this_,
38 : sqlite3_stmt *statement_ptr,
39 : data_row_t id1,
40 : data_row_t id2 )
41 : {
42 23 : assert( NULL != statement_ptr );
43 23 : u8_error_t result = U8_ERROR_NONE;
44 : static const int FIRST_SQL_BIND_PARAM = 1;
45 : static const int SECOND_SQL_BIND_PARAM = 2;
46 : int sqlite_err;
47 :
48 23 : sqlite_err = sqlite3_reset( statement_ptr );
49 23 : if ( SQLITE_OK != sqlite_err )
50 : {
51 0 : U8_LOG_ERROR_INT( "sqlite3_reset() failed:", sqlite_err );
52 0 : result |= U8_ERROR_AT_DB;
53 : }
54 :
55 23 : U8_TRACE_INFO_STR( "sqlite3_bind_int64():", sqlite3_sql(statement_ptr) );
56 23 : U8_TRACE_INFO_INT_INT( "sqlite3_bind_int64():", id1, id2 );
57 23 : sqlite_err = sqlite3_bind_int64( statement_ptr, FIRST_SQL_BIND_PARAM, id1 );
58 23 : if ( SQLITE_OK != sqlite_err )
59 : {
60 0 : U8_LOG_ERROR_INT( "sqlite3_bind_int64() failed:", sqlite_err );
61 0 : result |= U8_ERROR_AT_DB;
62 : }
63 23 : sqlite_err = sqlite3_bind_int64( statement_ptr, SECOND_SQL_BIND_PARAM, id2 );
64 23 : if ( SQLITE_OK != sqlite_err )
65 : {
66 0 : U8_LOG_ERROR_INT( "sqlite3_bind_int64() failed:", sqlite_err );
67 0 : result |= U8_ERROR_AT_DB;
68 : }
69 :
70 23 : return result;
71 : }
72 :
73 173 : static inline u8_error_t data_database_classifier_reader_private_bind_text_to_statement ( data_database_classifier_reader_t *this_,
74 : sqlite3_stmt *statement_ptr,
75 : const char *text )
76 : {
77 173 : assert( NULL != statement_ptr );
78 173 : assert( NULL != text );
79 173 : u8_error_t result = U8_ERROR_NONE;
80 : static const int FIRST_SQL_BIND_PARAM = 1;
81 : int sqlite_err;
82 :
83 173 : sqlite_err = sqlite3_reset( statement_ptr );
84 173 : if ( SQLITE_OK != sqlite_err )
85 : {
86 0 : U8_LOG_ERROR_INT( "sqlite3_reset() failed:", sqlite_err );
87 0 : result |= U8_ERROR_AT_DB;
88 : }
89 :
90 173 : U8_TRACE_INFO_STR( "sqlite3_bind_text():", sqlite3_sql(statement_ptr) );
91 : /* SQLITE_STATIC vs SQLITE_TRANSIENT: This function is used to perform a SELECT statement. */
92 : /* During the SELECT, the text string is not modified. This is guaranteed by data_database_classifier_reader. */
93 173 : U8_TRACE_INFO_STR( "sqlite3_bind_text():", text );
94 173 : sqlite_err = sqlite3_bind_text( statement_ptr, FIRST_SQL_BIND_PARAM, text, -1, SQLITE_STATIC );
95 173 : if ( SQLITE_OK != sqlite_err )
96 : {
97 0 : U8_LOG_ERROR_INT( "sqlite3_bind_text() failed:", sqlite_err );
98 0 : result |= U8_ERROR_AT_DB;
99 : }
100 :
101 173 : return result;
102 : }
103 :
104 :
105 : /*
106 : Copyright 2016-2025 Andreas Warnke
107 :
108 : Licensed under the Apache License, Version 2.0 (the "License");
109 : you may not use this file except in compliance with the License.
110 : You may obtain a copy of the License at
111 :
112 : http://www.apache.org/licenses/LICENSE-2.0
113 :
114 : Unless required by applicable law or agreed to in writing, software
115 : distributed under the License is distributed on an "AS IS" BASIS,
116 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
117 : See the License for the specific language governing permissions and
118 : limitations under the License.
119 : */
|