MCPcopy Create free account
hub / github.com/ElementsProject/lightning / process_json_obj

Function process_json_obj

plugins/sql.c:669–834  ·  view source on GitHub ↗

Returns NULL on success, otherwise has failed cmd. */

Source from the content-addressed store, hash-verified

667
668/* Returns NULL on success, otherwise has failed cmd. */
669static struct command_result *process_json_obj(struct command *cmd,
670 const char *buf,
671 const jsmntok_t *t,
672 const struct table_desc *td,
673 size_t row,
674 u64 this_rowid,
675 const u64 *parent_rowid,
676 size_t *sqloff,
677 sqlite3_stmt *stmt,
678 u64 *last_created_index,
679 u64 *last_updated_index)
680{
681 struct sql *sql = sql_of(cmd->plugin);
682 int err;
683
684 /* Subtables have row, arrindex as first two columns. */
685 if (parent_rowid) {
686 sqlite3_bind_int64(stmt, (*sqloff)++, *parent_rowid);
687 sqlite3_bind_int64(stmt, (*sqloff)++, row);
688 }
689
690 /* FIXME: This is O(n^2): hash td->columns and look up the other way. */
691 for (size_t i = 0; i < tal_count(td->columns); i++) {
692 const struct column *col = td->columns[i];
693 const jsmntok_t *coltok;
694
695 if (col->sub) {
696 struct command_result *ret;
697 /* Handle sub-tables below: we need rowid! */
698 if (!col->sub->is_subobject)
699 continue;
700
701 /* This can happen if the field is missing */
702 if (!t)
703 coltok = NULL;
704 else
705 coltok = json_get_member(buf, t, col->jsonname);
706 ret = process_json_obj(cmd, buf, coltok, col->sub, row, this_rowid,
707 NULL, sqloff, stmt, last_created_index, last_updated_index);
708 if (ret)
709 return ret;
710 continue;
711 }
712
713 /* This can happen if subobject does not exist in output! */
714 if (!t)
715 coltok = NULL;
716 else {
717 /* Array of primitives? */
718 if (!col->jsonname)
719 coltok = t;
720 else
721 coltok = json_get_member(buf, t, col->jsonname);
722 }
723
724 if (!coltok) {
725 if (td->parent)
726 plugin_log(cmd->plugin, LOG_DBG,

Callers 1

process_json_listFunction · 0.85

Calls 12

sql_ofFunction · 0.85
json_get_memberFunction · 0.85
json_to_doubleFunction · 0.85
process_json_subobjsFunction · 0.85
plugin_logFunction · 0.70
command_failFunction · 0.70
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50
json_to_u64Function · 0.50
json_to_boolFunction · 0.50
json_to_msatFunction · 0.50
json_tok_bin_from_hexFunction · 0.50

Tested by

no test coverage detected