• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tstack / lnav / 25348852825-3024

04 May 2026 11:18PM UTC coverage: 69.963% (+0.7%) from 69.226%
25348852825-3024

push

github

tstack
[ui] horizontal scroll should work on columns

Related to #1685

7 of 141 new or added lines in 5 files covered. (4.96%)

7760 existing lines in 84 files now uncovered.

57014 of 81492 relevant lines covered (69.96%)

622491.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/src/sql_util.hh
1
/**
2
 * Copyright (c) 2013, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 * @file sql_util.hh
30
 */
31

32
#ifndef lnav_sql_util_hh
33
#define lnav_sql_util_hh
34

35
#include <array>
36
#include <map>
37
#include <set>
38
#include <string>
39
#include <unordered_map>
40
#include <vector>
41

42
#include <sqlite3.h>
43
#include <sys/time.h>
44
#include <time.h>
45

46
#include "base/attr_line.hh"
47
#include "base/auto_mem.hh"
48
#include "base/intern_string.hh"
49
#include "base/lnav.console.hh"
50
#include "base/time_util.hh"
51

52
extern const std::array<const char*, 145> sqlite_keywords;
53
extern const char* sql_function_names[];
54
extern const std::unordered_map<unsigned char, const char*>
55
    sql_constraint_names;
56
extern const char* const LNAV_ATTACH_DB;
57

58
inline const char*
59
sql_constraint_op_name(unsigned char op)
336✔
60
{
61
    const auto iter = sql_constraint_names.find(op);
336✔
62
    if (iter == sql_constraint_names.end()) {
336✔
UNCOV
63
        return "??";
×
64
    }
65

66
    return iter->second;
336✔
67
}
68

69
using sqlite_exec_callback = int (*)(void*, int, char**, char**);
70
using db_table_list_t = std::vector<std::string>;
71
using db_table_map_t = std::map<std::string, db_table_list_t>;
72

73
struct sqlite_metadata_callbacks {
74
    sqlite_exec_callback smc_collation_list;
75
    sqlite_exec_callback smc_database_list;
76
    sqlite_exec_callback smc_table_list;
77
    sqlite_exec_callback smc_table_info;
78
    sqlite_exec_callback smc_foreign_key_list;
79
    void* smc_userdata{nullptr};
80
    std::string smc_table_name;
81
    db_table_map_t smc_db_list{};
82
};
83

84
int walk_sqlite_metadata(sqlite3* db, struct sqlite_metadata_callbacks& smc);
85

86
void dump_sqlite_schema(sqlite3* db, std::string& schema_out);
87

88
void attach_sqlite_db(sqlite3* db, const std::string& filename);
89

90
inline ssize_t
91
sql_strftime(char* buffer,
3,693✔
92
             size_t buffer_size,
93
             std::chrono::microseconds micros,
94
             char sep = ' ')
95
{
96
    return lnav::strftime_rfc3339(buffer, buffer_size, micros, sep);
3,693✔
97
}
98

99
inline ssize_t
100
sql_strftime(char* buffer,
3,038✔
101
             size_t buffer_size,
102
             const timeval& tv,
103
             char sep = ' ')
104
{
105
    return sql_strftime(buffer, buffer_size, to_us(tv), sep);
3,038✔
106
}
107

108
void sql_install_logger();
109

110
bool sql_ident_needs_quote(const char* ident);
111

112
auto_mem<char, sqlite3_free> sql_quote_ident(const char* ident);
113

114
std::string sql_safe_ident(const string_fragment& ident);
115

116
std::string sql_quote_text(const std::string& str);
117

118
int guess_type_from_pcre(const std::string& pattern, std::string& collator);
119

120
const char* sqlite3_type_to_string(int type);
121

122
attr_line_t sqlite3_errmsg_to_attr_line(sqlite3* db);
123

124
attr_line_t annotate_sql_with_error(sqlite3* db,
125
                                    const char* sql,
126
                                    const char* tail);
127

128
int sqlite_authorizer(void* pUserData,
129
                      int action_code,
130
                      const char* detail1,
131
                      const char* detail2,
132
                      const char* detail3,
133
                      const char* detail4);
134

135
// RAII helper that, while in scope, collects the names of every table
136
// accessed by subsequent sqlite3_prepare_v2 calls on this thread into
137
// the supplied set.  Used by execute_sql to tell whether the user's
138
// query reads from log-backed vtables.  Nested guards restore the
139
// previous capture target on destruction.
140
class sql_table_capture_guard {
141
public:
142
    explicit sql_table_capture_guard(std::set<std::string>& into);
143
    ~sql_table_capture_guard();
144

145
    sql_table_capture_guard(const sql_table_capture_guard&) = delete;
146
    sql_table_capture_guard& operator=(const sql_table_capture_guard&) = delete;
147

148
private:
149
    std::set<std::string>* stcg_prev;
150
};
151

152
namespace lnav::sql {
153

154
auto_mem<char, sqlite3_free> mprintf(const char* fmt, ...);
155

156
}  // namespace lnav::sql
157

158
namespace lnav::prql {
159

160
Result<std::string, console::user_message> compile(const std::string& src);
161

162
}
163

164
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc