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

tstack / lnav / 17589970077-2502

09 Sep 2025 05:00PM UTC coverage: 65.196% (-5.0%) from 70.225%
17589970077-2502

push

github

tstack
[format] add fields for source file/line

Knowing the source file/line context in a log
message can help find log messages when using
log2src.

56 of 70 new or added lines in 2 files covered. (80.0%)

13954 existing lines in 210 files now uncovered.

45516 of 69814 relevant lines covered (65.2%)

404154.37 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 <string>
38
#include <unordered_map>
39
#include <vector>
40

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

45
#include "base/attr_line.hh"
46
#include "base/auto_mem.hh"
47
#include "base/intern_string.hh"
48
#include "base/time_util.hh"
49

50
extern const std::array<const char*, 145> sqlite_keywords;
51
extern const char* sql_function_names[];
52
extern const std::unordered_map<unsigned char, const char*>
53
    sql_constraint_names;
54

55
inline const char*
56
sql_constraint_op_name(unsigned char op)
249✔
57
{
58
    const auto iter = sql_constraint_names.find(op);
249✔
59
    if (iter == sql_constraint_names.end()) {
249✔
UNCOV
60
        return "??";
×
61
    }
62

63
    return iter->second;
249✔
64
}
65

66
using sqlite_exec_callback = int (*)(void*, int, char**, char**);
67
using db_table_list_t = std::vector<std::string>;
68
using db_table_map_t = std::map<std::string, db_table_list_t>;
69

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

81
int walk_sqlite_metadata(sqlite3* db, struct sqlite_metadata_callbacks& smc);
82

83
void dump_sqlite_schema(sqlite3* db, std::string& schema_out);
84

85
void attach_sqlite_db(sqlite3* db, const std::string& filename);
86

87
inline ssize_t
88
sql_strftime(char* buffer,
2,279✔
89
             size_t buffer_size,
90
             lnav::time64_t tim,
91
             int millis,
92
             char sep = ' ')
93
{
94
    return lnav::strftime_rfc3339(buffer, buffer_size, tim, millis, sep);
2,279✔
95
}
96

97
inline ssize_t
98
sql_strftime(char* buffer,
2,271✔
99
             size_t buffer_size,
100
             const struct timeval& tv,
101
             char sep = ' ')
102
{
103
    return sql_strftime(buffer, buffer_size, tv.tv_sec, tv.tv_usec / 1000, sep);
2,271✔
104
}
105

106
void sql_install_logger();
107

108
bool sql_ident_needs_quote(const char* ident);
109

110
auto_mem<char, sqlite3_free> sql_quote_ident(const char* ident);
111

112
std::string sql_safe_ident(const string_fragment& ident);
113

114
std::string sql_quote_text(const std::string& str);
115

116
int guess_type_from_pcre(const std::string& pattern, std::string& collator);
117

118
const char* sqlite3_type_to_string(int type);
119

120
attr_line_t sqlite3_errmsg_to_attr_line(sqlite3* db);
121

122
attr_line_t annotate_sql_with_error(sqlite3* db,
123
                                    const char* sql,
124
                                    const char* tail);
125

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

133
namespace lnav::sql {
134

135
auto_mem<char, sqlite3_free> mprintf(const char* fmt, ...);
136

137
}  // namespace lnav::sql
138

139
#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