xref: /aosp_15_r20/external/perfetto/src/trace_processor/sqlite/bindings/sqlite_column.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SRC_TRACE_PROCESSOR_SQLITE_BINDINGS_SQLITE_COLUMN_H_
18 #define SRC_TRACE_PROCESSOR_SQLITE_BINDINGS_SQLITE_COLUMN_H_
19 
20 #include <sqlite3.h>  // IWYU pragma: export
21 #include <cstdint>
22 
23 #include "src/trace_processor/sqlite/bindings/sqlite_type.h"
24 
25 namespace perfetto::trace_processor::sqlite::column {
26 
27 // This file contains wraps the SQLite functions which operate on stmt
28 // columns and start with sqlite3_column_*.
29 
Name(sqlite3_stmt * stmt,uint32_t N)30 inline const char* Name(sqlite3_stmt* stmt, uint32_t N) {
31   return sqlite3_column_name(stmt, static_cast<int>(N));
32 }
33 
Count(sqlite3_stmt * stmt)34 inline uint32_t Count(sqlite3_stmt* stmt) {
35   return static_cast<uint32_t>(sqlite3_column_count(stmt));
36 }
37 
Type(sqlite3_stmt * stmt,uint32_t N)38 inline sqlite::Type Type(sqlite3_stmt* stmt, uint32_t N) {
39   return static_cast<sqlite::Type>(
40       sqlite3_column_type(stmt, static_cast<int>(N)));
41 }
42 
Int64(sqlite3_stmt * stmt,uint32_t N)43 inline int64_t Int64(sqlite3_stmt* stmt, uint32_t N) {
44   return sqlite3_column_int64(stmt, static_cast<int>(N));
45 }
46 
Text(sqlite3_stmt * stmt,uint32_t N)47 inline const char* Text(sqlite3_stmt* stmt, uint32_t N) {
48   return reinterpret_cast<const char*>(
49       sqlite3_column_text(stmt, static_cast<int>(N)));
50 }
51 
Double(sqlite3_stmt * stmt,uint32_t N)52 inline double Double(sqlite3_stmt* stmt, uint32_t N) {
53   return sqlite3_column_double(stmt, static_cast<int>(N));
54 }
55 
Value(sqlite3_stmt * stmt,uint32_t N)56 inline sqlite3_value* Value(sqlite3_stmt* stmt, uint32_t N) {
57   return sqlite3_column_value(stmt, static_cast<int>(N));
58 }
59 
60 using PointerDestructor = void(void*);
BindPointer(sqlite3_stmt * stmt,uint32_t N,void * ptr,const char * name,PointerDestructor destructor)61 inline int BindPointer(sqlite3_stmt* stmt,
62                        uint32_t N,
63                        void* ptr,
64                        const char* name,
65                        PointerDestructor destructor) {
66   return sqlite3_bind_pointer(stmt, static_cast<int>(N), ptr, name, destructor);
67 }
68 
69 }  // namespace perfetto::trace_processor::sqlite::column
70 
71 #endif  // SRC_TRACE_PROCESSOR_SQLITE_BINDINGS_SQLITE_COLUMN_H_
72