#ifndef SRC_TRACE_PROCESSOR_SQLITE_SQLITE_UTILS_H_
#define SRC_TRACE_PROCESSOR_SQLITE_SQLITE_UTILS_H_
#include <sqlite3.h>
#include <bitset>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <functional>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "perfetto/base/logging.h"
#include "perfetto/base/status.h"
#include "perfetto/ext/base/status_or.h"
#include "perfetto/trace_processor/basic_types.h"
#include "src/trace_processor/sqlite/bindings/sqlite_result.h"
#define SQLITE_RETURN_IF_ERROR(vtab, expr) …
#define SQLITE_ASSIGN_OR_RETURN(vtab, lhs, rhs) …
namespace perfetto::trace_processor::sqlite::utils {
const auto kSqliteStatic = …;
const auto kSqliteTransient = …;
inline bool IsOpEq(int op) { … }
inline bool IsOpLe(int op) { … }
inline bool IsOpLt(int op) { … }
inline bool IsOpGe(int op) { … }
inline bool IsOpGt(int op) { … }
inline SqlValue::Type SqliteTypeToSqlValueType(int sqlite_type) { … }
inline SqlValue SqliteValueToSqlValue(sqlite3_value* value) { … }
inline std::optional<std::string> SqlValueToString(SqlValue value) { … }
inline void ReportSqlValue(
sqlite3_context* ctx,
const SqlValue& value,
sqlite3_destructor_type string_destructor = kSqliteTransient,
sqlite3_destructor_type bytes_destructor = kSqliteTransient) { … }
inline int SetError(sqlite3_vtab* tab, const char* status) { … }
inline void SetError(sqlite3_context* ctx, const char* status) { … }
inline int SetError(sqlite3_vtab* tab, base::Status s) { … }
inline void SetError(sqlite3_context* ctx, const base::Status& status) { … }
inline void SetError(sqlite3_context* ctx,
const std::string& function_name,
const base::Status& status) { … }
inline base::Status ValidateFunctionArguments(
sqlite3_index_info* info,
size_t arg_count,
const std::function<bool(size_t)>& is_arg_column) { … }
inline const char* SqlValueTypeToString(SqlValue::Type type) { … }
inline std::string SqlValueTypeToSqliteTypeName(SqlValue::Type type) { … }
base::Status ExtractFromSqlValue(const SqlValue& value,
std::optional<int64_t>&);
base::Status ExtractFromSqlValue(const SqlValue& value,
std::optional<int32_t>&);
base::Status ExtractFromSqlValue(const SqlValue& value,
std::optional<uint32_t>&);
base::Status ExtractFromSqlValue(const SqlValue& value, std::optional<double>&);
base::Status ExtractFromSqlValue(const SqlValue& value,
std::optional<const char*>&);
base::Status GetColumnsForTable(
sqlite3* db,
const std::string& raw_table_name,
std::vector<std::pair<SqlValue::Type, std::string>>& columns);
std::wstring SqliteValueToWString(sqlite3_value* value);
const char* SqliteTypeToFriendlyString(SqlValue::Type type);
base::Status CheckArgCount(const char* function_name,
size_t argc,
size_t expected_argc);
base::StatusOr<int64_t> ExtractIntArg(const char* function_name,
const char* arg_name,
sqlite3_value* value);
base::StatusOr<double> ExtractDoubleArg(const char* function_name,
const char* arg_name,
sqlite3_value* value);
base::StatusOr<std::string> ExtractStringArg(const char* function_name,
const char* arg_name,
sqlite3_value* value);
base::Status TypeCheckSqliteValue(sqlite3_value* value,
SqlValue::Type expected_type);
base::Status TypeCheckSqliteValue(sqlite3_value* value,
SqlValue::Type expected_type,
const char* expected_type_str);
namespace internal {
static_assert …;
ExpectedTypesSet;
template <typename... args>
constexpr ExpectedTypesSet ToExpectedTypesSet(args... expected_type_args) { … }
base::StatusOr<SqlValue> ExtractArgument(size_t argc,
sqlite3_value** argv,
const char* argument_name,
size_t arg_index,
ExpectedTypesSet expected_types);
base::Status InvalidArgumentTypeError(const char* argument_name,
size_t arg_index,
SqlValue::Type actual_type,
ExpectedTypesSet expected_types);
}
template <typename... args>
base::Status InvalidArgumentTypeError(const char* argument_name,
size_t arg_index,
SqlValue::Type actual_type,
SqlValue::Type expected_type,
args... expected_type_args) { … }
base::Status MissingArgumentError(const char* argument_name);
base::Status ToInvalidArgumentError(const char* argument_name,
size_t arg_index,
const base::Status& error);
template <typename... args>
base::StatusOr<SqlValue> ExtractArgument(size_t argc,
sqlite3_value** argv,
const char* argument_name,
size_t arg_index,
SqlValue::Type expected_type,
args... expected_type_args) { … }
}
#endif