GENDERS_TESTQUERY(3)

πŸ’– GENDERS_TESTQUERY πŸ’–

ok so this is a page from libgenders(3) and it's literally all about one lil function that answers the question: does this node match this query or not πŸ¦‹


✨ NAME ✨

genders_testquery β€” ask the genders database if a node matches a query, bestie


🌸 SYNOPSIS 🌸

#include <genders.h>

int genders_testquery(genders_t handle, const char *node, const char *query);

πŸ’… DESCRIPTION πŸ’…

ok so genders_testquery() checks if the node that node points to matches all the conditions you put in query. and if node is NULL? no worries, it just tests the current node instead 🫢

the queries are built out of set operations on genders attributes and values β€” union, intersection, difference, and complement. you pass the whole thing as a string through the query parameter. here's the tea on the operators:

  • union β†’ two pipe symbols: '||'
  • intersection β†’ two ampersand symbols: '&&'
  • difference β†’ two minus symbols: '--'
  • complement β†’ a tilde: '~'

set operations get performed left to right, periodt. but you can use parentheses to change the order of operations, so go off πŸ‘‘

and if query is NULL? it retrieves all the nodes from the genders database. iconic behavior honestly.

a whole list of query examples is below, keep scrolling ⬇️


πŸ”₯ EXAMPLES πŸ”₯

these are the example queries you can pass to genders_testquery().

  • test if a node contains the mgmt or login attribute:
"mgmt||login"
  • test if a node is not a login node:
"all--login"
  • test if a node is both a login node and ntp server:
"login&&ntpserv"
  • test if a node is not a mgmt or login node:
"~(mgmt||login)"

⭐ RETURN VALUES ⭐

  • if the node has met the conditions of the query β†’ 1 is returned ✨
  • if the node does not meet the conditions β†’ 0 is returned πŸ™ˆ
  • on error β†’ -1 is returned, and an error code is returned in handle

you can grab that error code with genders_errnum(3), and a lil description of it with genders_strerror(3). the error codes themselves are defined in genders.h πŸ’–


πŸ’€ ERRORS πŸ’€

  • GENDERS_ERR_NULLHANDLE β€” the handle parameter is NULL. your genders handle has to be created with genders_handle_create(3) first, no skipping steps bestie.
  • GENDERS_ERR_NOTLOADED β€” genders_load_data(3) hasn't been called yet to load the genders data. nothing to query if you never loaded it 😭
  • GENDERS_ERR_PARAMETERS β€” an incorrect parameter has been passed in.
  • GENDERS_ERR_SYNTAX β€” there's a syntax error in the query. typo core πŸ’…
  • GENDERS_ERR_OUTMEM β€” malloc(3) failed internally, meaning the system is out of memory.
  • GENDERS_ERR_MAGIC β€” handle has an incorrect magic number. that means handle does not point to a genders handle, or handle has been destroyed by genders_handle_destroy(3). she's gone, girl πŸ’€
  • GENDERS_ERR_INTERNAL β€” an internal system error has occurred.

πŸŽ€ FILES πŸŽ€

  • /usr/include/genders.h

🌈 SEE ALSO 🌈


ngl this whole page is from LLNL, dated June 2004, and it's giving certified classic energy πŸ’œ go query something, main character πŸ¦‹βœ¨