MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / sc_table

Function sc_table

src/store/store_content_digest.c:84–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84static bool sc_table(sqlite3 *db, const sc_query_t *q, const char *project, cbm_sha256_ctx *ctx) {
85 sqlite3_stmt *st = NULL;
86 if (sqlite3_prepare_v2(db, q->sql, -1, &st, NULL) != SQLITE_OK) {
87 return false;
88 }
89 bool ok = sqlite3_bind_text(st, 1, project, -1, SQLITE_TRANSIENT) == SQLITE_OK;
90 sc_frame(ctx, 'T', q->name, strlen(q->name));
91 uint64_t rows = 0;
92 int rc = SQLITE_ROW;
93 while (ok && (rc = sqlite3_step(st)) == SQLITE_ROW) {
94 int columns = sqlite3_column_count(st);
95 unsigned char width[4] = {(unsigned char)(columns >> 24), (unsigned char)(columns >> 16),
96 (unsigned char)(columns >> 8), (unsigned char)columns};
97 sc_frame(ctx, 'R', width, sizeof(width));
98 for (int c = 0; c < columns; c++) {
99 switch (sqlite3_column_type(st, c)) {
100 case SQLITE_NULL:
101 sc_frame(ctx, 'N', NULL, 0);
102 break;
103 case SQLITE_INTEGER: {
104 char text[32];
105 long long value = (long long)sqlite3_column_int64(st, c);
106 int n = snprintf(text, sizeof(text), "%lld", value);
107 sc_frame(ctx, 'I', text, (uint64_t)n);
108 break;
109 }
110 case SQLITE_FLOAT: {
111 char text[64];
112 double value = sqlite3_column_double(st, c);
113 int n = snprintf(text, sizeof(text), "%.17g", value);
114 sc_frame(ctx, 'F', text, (uint64_t)n);
115 break;
116 }
117 case SQLITE_BLOB:
118 sc_frame(ctx, 'B', sqlite3_column_blob(st, c),
119 (uint64_t)sqlite3_column_bytes(st, c));
120 break;
121 default:
122 sc_frame(ctx, 'S', sqlite3_column_text(st, c),
123 (uint64_t)sqlite3_column_bytes(st, c));
124 break;
125 }
126 }
127 rows++;
128 }
129 ok = ok && rc == SQLITE_DONE;
130 sqlite3_finalize(st);
131 unsigned char count[8];
132 for (int i = 0; i < 8; i++) {
133 count[i] = (unsigned char)(rows >> (56 - 8 * i));
134 }
135 sc_frame(ctx, 'C', count, sizeof(count));
136 return ok;
137}
138
139static int sc_digest(cbm_store_t *s, const char *project, const char *domain,
140 const sc_query_t *queries, size_t query_count,

Callers 1

sc_digestFunction · 0.85

Calls 1

sc_frameFunction · 0.85

Tested by

no test coverage detected