Skip to content

QueryPredicate silently produces malformed SQL when no member matches #22

Description

@jkalias

Problem

In the QueryPredicate constructor (include/query_predicates.h), the member is located by scanning record.member_metadata for an entry whose offset matches the offset derived from the pointer-to-member:

for (auto i = 0; i < record.member_metadata.size(); ++i) {
    if (record.member_metadata[i].offset == offset) {
        member_name_ = record.member_metadata[i].name;
        value_ = ...;
        break;
    }
}

If no entry matches (e.g. an unregistered type — see related issue #23 — or an offset-derivation problem), member_name_ stays empty and no error is raised.

Impact

Evaluate() then emits a clause like = ? (empty column name), producing malformed SQL that fails later at prepare time with a confusing message, rather than failing fast at the point of misuse.

Suggested direction

Throw a clear exception from the constructor when no member matches the pointer-to-member, naming the record type, so the error is reported at construction.

Notes for implementation

  • Best fixed together with Unregistered/misspelled record types silently yield an empty Reflection #23. Once Unregistered/misspelled record types silently yield an empty Reflection #23 makes GetRecordFromTypeId (called at
    include/query_predicates.h:83) throw on an unregistered type, this constructor's own guard
    specifically covers the registered-but-offset-mismatch case; both are needed.
  • Put the throw ONLY in the member-matching QueryPredicate constructor(s) (the templated
    (fn, value, symbol, retrieval) one, which the (fn, value, symbol) overload delegates to). Do
    NOT add it to the (symbol, member_name, value) constructor used by Clone(), and do NOT affect
    EmptyPredicate (the deliberate no-member, fetch-all path) — that must keep working.
  • <stdexcept> may need including in the header.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions