2013-05-29 14:28:57 +00:00
|
|
|
#include <stdio.h>
|
2013-05-29 16:13:28 +00:00
|
|
|
#include <string.h>
|
2013-05-29 14:28:57 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <sqlite3.h>
|
|
|
|
|
2018-05-17 14:06:50 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2013-06-22 14:55:49 +00:00
|
|
|
#include "lnav.hh"
|
2013-05-29 14:28:57 +00:00
|
|
|
#include "auto_mem.hh"
|
2017-03-27 04:01:49 +00:00
|
|
|
#include "sqlite-extension-func.hh"
|
2017-03-16 00:01:58 +00:00
|
|
|
#include "regexp_vtab.hh"
|
2013-05-29 14:28:57 +00:00
|
|
|
|
|
|
|
struct callback_state {
|
|
|
|
int cs_row;
|
|
|
|
};
|
|
|
|
|
2013-06-22 14:55:49 +00:00
|
|
|
struct _lnav_data lnav_data;
|
|
|
|
|
2013-05-29 14:28:57 +00:00
|
|
|
static int sql_callback(void *ptr,
|
|
|
|
int ncols,
|
|
|
|
char **colvalues,
|
|
|
|
char **colnames)
|
|
|
|
{
|
|
|
|
struct callback_state *cs = (struct callback_state *)ptr;
|
|
|
|
|
|
|
|
printf("Row %d:\n", cs->cs_row);
|
|
|
|
for (int lpc = 0; lpc < ncols; lpc++) {
|
|
|
|
printf(" Column %10s: %s\n", colnames[lpc], colvalues[lpc]);
|
|
|
|
}
|
|
|
|
|
|
|
|
cs->cs_row += 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-06 00:34:30 +00:00
|
|
|
std::string execute_any(exec_context &ec, const std::string &cmdline_with_mode)
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2018-05-10 13:44:03 +00:00
|
|
|
void add_global_vars(exec_context &ec)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-29 14:28:57 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int retval = EXIT_SUCCESS;
|
|
|
|
auto_mem<sqlite3> db(sqlite3_close);
|
2018-05-17 14:06:50 +00:00
|
|
|
std::string stmt;
|
2013-05-29 14:28:57 +00:00
|
|
|
|
2014-05-05 13:44:58 +00:00
|
|
|
log_argv(argc, argv);
|
|
|
|
|
2018-05-17 14:06:50 +00:00
|
|
|
if (argc == 2) {
|
|
|
|
stmt = argv[1];
|
|
|
|
} else {
|
|
|
|
std::getline(std::cin, stmt, '\0');
|
2013-05-29 14:28:57 +00:00
|
|
|
}
|
2018-05-17 14:06:50 +00:00
|
|
|
|
|
|
|
if (sqlite3_open(":memory:", db.out()) != SQLITE_OK) {
|
2013-05-29 14:28:57 +00:00
|
|
|
fprintf(stderr, "error: unable to make sqlite memory database\n");
|
|
|
|
retval = EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
auto_mem<char> errmsg(sqlite3_free);
|
|
|
|
struct callback_state state;
|
|
|
|
|
2013-05-29 16:13:28 +00:00
|
|
|
memset(&state, 0, sizeof(state));
|
|
|
|
|
2013-05-29 14:28:57 +00:00
|
|
|
{
|
|
|
|
int register_collation_functions(sqlite3 * db);
|
|
|
|
|
2013-06-06 14:01:32 +00:00
|
|
|
register_sqlite_funcs(db.in(), sqlite_registration_funcs);
|
2013-05-29 14:28:57 +00:00
|
|
|
register_collation_functions(db.in());
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:01:58 +00:00
|
|
|
register_regexp_vtab(db.in());
|
|
|
|
|
2013-05-29 14:28:57 +00:00
|
|
|
if (sqlite3_exec(db.in(),
|
2018-05-17 14:06:50 +00:00
|
|
|
stmt.c_str(),
|
2013-05-29 14:28:57 +00:00
|
|
|
sql_callback,
|
|
|
|
&state,
|
|
|
|
errmsg.out()) != SQLITE_OK) {
|
|
|
|
fprintf(stderr, "error: sqlite3_exec failed -- %s\n", errmsg.in());
|
|
|
|
retval = EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|