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

Function file_outline_build_sql

src/store/store.c:3665–3709  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3663}
3664
3665static bool file_outline_build_sql(char *sql, size_t sql_size, bool count_only, int label_count) {
3666 int written =
3667 snprintf(sql, sql_size,
3668 count_only ? "SELECT COUNT(*) FROM nodes WHERE project = ?1 AND file_path = ?2 "
3669 "AND label NOT IN ('Module','Package','File','Folder','Project')"
3670 : "SELECT name, label, qualified_name, start_line, end_line FROM nodes "
3671 "WHERE project = ?1 AND file_path = ?2 "
3672 "AND label NOT IN ('Module','Package','File','Folder','Project')");
3673 if (written < 0 || (size_t)written >= sql_size) {
3674 return false;
3675 }
3676 size_t used = (size_t)written;
3677 if (label_count > 0) {
3678 written = snprintf(sql + used, sql_size - used, " AND label IN (");
3679 if (written < 0 || (size_t)written >= sql_size - used) {
3680 return false;
3681 }
3682 used += (size_t)written;
3683 for (int i = 0; i < label_count; i++) {
3684 written = snprintf(sql + used, sql_size - used, "%s?%d", i > 0 ? "," : "", i + 3);
3685 if (written < 0 || (size_t)written >= sql_size - used) {
3686 return false;
3687 }
3688 used += (size_t)written;
3689 }
3690 written = snprintf(sql + used, sql_size - used, ")");
3691 if (written < 0 || (size_t)written >= sql_size - used) {
3692 return false;
3693 }
3694 used += (size_t)written;
3695 }
3696 if (!count_only) {
3697 int limit_bind = label_count + 3;
3698 int offset_bind = limit_bind + 1;
3699 written = snprintf(sql + used, sql_size - used,
3700 " ORDER BY start_line, end_line, label COLLATE BINARY, "
3701 "name COLLATE BINARY, qualified_name COLLATE BINARY, id "
3702 "LIMIT ?%d OFFSET ?%d",
3703 limit_bind, offset_bind);
3704 if (written < 0 || (size_t)written >= sql_size - used) {
3705 return false;
3706 }
3707 }
3708 return true;
3709}
3710
3711static void file_outline_bind_common(sqlite3_stmt *stmt, const char *project, const char *file_path,
3712 const char *const *labels, int label_count) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected