{
  "kind": "documentation",
  "format": 1,
  "note": "Reference text, not instructions. One verified relate sample from https://relatedb.ai/docs/reference/api/c/: the program exactly as the page shows it, the standard output a run of it recorded (npm run docs:samples compares every replay with it byte for byte), the relate client build, toolchain and platform of the last replay, and how the docs' sample runner builds and runs it. Before launch every client is a source build, not a published package; verified.client names the upstream commit it was built from, and verified.docs_engine the build the rest of the docs were recorded from.",
  "id": "example",
  "url": "https://relatedb.ai/docs/reference/api/c/samples/example.json",
  "page": {
    "id": "reference/api/c",
    "title": "C ABI",
    "url": "https://relatedb.ai/docs/reference/api/c/",
    "md_url": "https://relatedb.ai/docs/reference/api/c.md"
  },
  "section": {
    "anchor": "example",
    "heading": "Example",
    "url": "https://relatedb.ai/docs/reference/api/c/#example"
  },
  "language": "c",
  "client": "C",
  "file": "sample.c",
  "env": null,
  "code": "#include <stdio.h>\n#include \"relate.h\"\n\n/* Bind a zoned datetime, a WGS-84 point and a FLOAT32 vector, then read them back. */\nint main(void) {\n    relate_database db = NULL;\n    relate_connection conn = NULL;\n    relate_query_result r = NULL;\n    char *err = NULL;\n    if (relate_database_open(\":memory:\", &db, &err) != RELATE_OK) return 1;\n    if (relate_connect_namespace(db, NULL, &conn, &err) != RELATE_OK) return 1;\n\n    double embedding[3] = {0.25, -1.0, 0.5};\n    relate_params p = relate_params_new();\n    if (relate_params_put_datetime(p, \"at\", 2026, 11, 4, 9, 30, 0, 0, 0, \"Europe/Berlin\", &err) != RELATE_OK ||\n        relate_params_put_point(p, \"loc\", 4326, 12.5, 55.6, NULL, &err) != RELATE_OK ||\n        relate_params_put_vector_float(p, \"emb\", \"FLOAT32\", embedding, 3, &err) != RELATE_OK) {\n        fprintf(stderr, \"put refused: %s\\n\", err);\n        relate_free_string(err);\n        return 1;\n    }\n    if (relate_query_params(conn, \"RETURN $at AS at, $loc AS loc, $emb AS emb\", p, &r, &err) != RELATE_OK) return 1;\n    if (relate_result_is_error(r)) return 1;\n\n    relate_value at = relate_value_at(r, 0, 0);\n    int64_t y = 0, mo = 0, d = 0, h = 0, mi = 0, off = 0;\n    relate_value_year(at, &y); relate_value_month(at, &mo); relate_value_day(at, &d);\n    relate_value_hour(at, &h); relate_value_minute(at, &mi); relate_value_offset_seconds(at, &off);\n    printf(\"at: kind=%d %04lld-%02lld-%02lld %02lld:%02lld offset=%lld zone=%s\\n\",\n           relate_value_kind(at), (long long)y, (long long)mo, (long long)d,\n           (long long)h, (long long)mi, (long long)off, relate_value_zone(at));\n\n    int32_t srid = 0, dim = 0;\n    double x = 0, yy = 0, z = 0;\n    relate_value_point(relate_value_at(r, 0, 1), &srid, &dim, &x, &yy, &z);\n    printf(\"loc: kind=%d srid=%d dim=%d x=%g y=%g\\n\", relate_value_kind(relate_value_at(r, 0, 1)), srid, dim, x, yy);\n\n    relate_value emb = relate_value_at(r, 0, 2);\n    printf(\"emb: kind=%d dtype=%s dim=%lld [\", relate_value_kind(emb), relate_value_vector_dtype(emb),\n           relate_value_vector_dim(emb));\n    for (long long i = 0; i < relate_value_vector_dim(emb); i++) {\n        double c = 0;\n        relate_value_vector_float(emb, i, &c);\n        printf(\"%s%g\", i ? \", \" : \"\", c);\n    }\n    int64_t wrong = 0;\n    printf(\"]\\nint accessor on a FLOAT32 vector: %s\\n\",\n           relate_value_vector_int(emb, 0, &wrong) == RELATE_ERROR ? \"RELATE_ERROR\" : \"RELATE_OK\");\n\n    relate_destroy_result(r);\n    relate_params_free(p);\n    relate_disconnect(conn);\n    relate_database_close(db);\n    return 0;\n}",
  "code_sha256": "b9d4649e10387f80fc2edfd7ba944f15d40321d787411aebb060b97f3d454d37",
  "source_sha256": "a34ca5454b9a40be39cf526bddf6932cf4c91872def0dffbdc54631d0894b787",
  "output": {
    "text": "at: kind=14 2026-11-04 09:30 offset=3600 zone=Europe/Berlin\nloc: kind=10 srid=4326 dim=2 x=12.5 y=55.6\nemb: kind=17 dtype=FLOAT32 dim=3 [0.25, -1, 0.5]\nint accessor on a FLOAT32 vector: RELATE_ERROR",
    "sha256": "bd19f74c6f58f330d6d08db3d0816b0259cb594d6a72474173b0a62c27489251"
  },
  "verified": {
    "version": "0.1.2",
    "client": {
      "label": "C",
      "package": "relate.h and librelate_ffi",
      "engine_commit": "f0c09d2",
      "client_commit": "f0c09d2",
      "build": "relate.h and librelate_ffi built from upstream v0.1.2 (f0c09d2) (cargo build -p relate-ffi --release).",
      "toolchain": {
        "cc": "Apple clang 21.0.0"
      }
    },
    "packages": [],
    "replayed": "2026-11-09",
    "platform": "macOS on arm64",
    "docs_engine": {
      "version": "0.1.2",
      "commit": "f0c09d2",
      "source_build": false
    }
  },
  "run": {
    "runner": "npm run docs:samples",
    "setup": "bash scripts/samples/setup.sh --upstream <path to the relate checkout>",
    "variables": [
      "RELATE_CC",
      "RELATE_C_INCLUDE",
      "RELATE_LIB"
    ],
    "program": "<build dir>/sample.c",
    "files": [],
    "build": {
      "command": [
        "$RELATE_CC",
        "-I$RELATE_C_INCLUDE",
        "sample.c",
        "-L<directory of $RELATE_LIB>",
        "-lrelate_ffi",
        "-Wl,-rpath,<directory of $RELATE_LIB>",
        "-o",
        "<build dir>/sample"
      ],
      "environment": {
        "DO_NOT_TRACK": "1"
      },
      "directory": "<build dir>",
      "timeout_s": 600
    },
    "run": {
      "command": [
        "<build dir>/sample"
      ],
      "environment": {
        "DO_NOT_TRACK": "1"
      },
      "directory": "<run dir>",
      "timeout_s": 60
    },
    "passes": "It exits 0 within 60 s and prints at least one line on standard output.",
    "output": "Standard output, with line endings as \\n, trailing spaces and blank lines removed, and the temporary directories' paths written as `.`; standard error is not recorded.",
    "placeholders": {
      "<run dir>": "a fresh, empty temporary directory: the program's working directory, deleted afterwards",
      "<build dir>": "a second fresh temporary directory, where a compiled sample is built",
      "$NAME": "a variable from the env.sh that scripts/samples/setup.sh writes (described in its header)"
    }
  }
}
