• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_BIND_H_
18 #define SRC_TRACE_PROCESSOR_SQLITE_BINDINGS_SQLITE_BIND_H_
19 
20 #include <sqlite3.h>  // IWYU pragma: export
21 #include <cstdint>
22 #include <memory>
23 
24 namespace perfetto::trace_processor::sqlite::bind {
25 
26 // This file contains wraps the SQLite functions which operate on stmt
27 // bindings and start with sqlite3_bind_*.
28 
29 using PointerDestructor = void(void*);
Pointer(sqlite3_stmt * stmt,uint32_t N,void * ptr,const char * name,PointerDestructor destructor)30 inline int Pointer(sqlite3_stmt* stmt,
31                    uint32_t N,
32                    void* ptr,
33                    const char* name,
34                    PointerDestructor destructor) {
35   return sqlite3_bind_pointer(stmt, static_cast<int>(N), ptr, name, destructor);
36 }
37 
38 template <typename T>
UniquePointer(sqlite3_stmt * stmt,uint32_t N,std::unique_ptr<T> ptr,const char * name)39 inline int UniquePointer(sqlite3_stmt* stmt,
40                          uint32_t N,
41                          std::unique_ptr<T> ptr,
42                          const char* name) {
43   return sqlite3_bind_pointer(
44       stmt, static_cast<int>(N), ptr.release(), name,
45       [](void* tab) { std::unique_ptr<T>(static_cast<T*>(tab)); });
46 }
47 
48 }  // namespace perfetto::trace_processor::sqlite::bind
49 
50 #endif  // SRC_TRACE_PROCESSOR_SQLITE_BINDINGS_SQLITE_BIND_H_
51