PX_INSERT_RECORD(3)

πŸ’– PX_INSERT_RECORD(3) πŸ’–

okay bestie, so this one is PX_insert_record β€” it lives in the Library Functions Manual and it's your girl for adding brand-new records to a Paradox file. let's get into it ✨


✨ SYNOPSIS ✨

#include <paradox.h>

int PX_insert_record(pxdoc_t *pxdoc, pxval_t **dataptr)

🌸 DESCRIPTION 🌸

So basically, PX_insert_record takes a brand-new record that's already chillin' in the array dataptr and drops it into a Paradox file. 🫢

Where does it go? the function decides that itself. It starts at the beginning of the file and hunts towards the end looking for a free slot. and a "free slot" can be two things, no cap:

  • a slot that got freed up by a previous call to PX_delete_record(3), or
  • a data block in the input file that wasn't completely filled

and if there's literally no free slot anywhere in the file, then a new record just gets tacked onto the end. slay, problem solved πŸ’…

Blobs get written automatically if a blob file was set with PX_set_blob_file(3). πŸ¦‹

the memory for dataptr and the field values can be freed after PX_insert_record has been called. so you don't need to keep it alive, bestie, it's done its job.

πŸŽ€ building the record πŸŽ€

Every single element in that array of pointers to pxval_t can be built super easily with MAKE_PXVAL(pxdoc_t *pxdoc, pxval_t *val) β€” you just set the actual value afterwards. the way that this is the most common way to build up the record?? iconic:

dataptr = (pxval_t **) malloc(PX_get_num_fields(pxdoc)*sizeof(pxval_t *));
MAKE_PXVAL(pxdoc, dataptr[0]);
dataptr[0]->type = pxfLong;
dataptr[0]->value.lval = 45;
dataptr[1]->type = pxfAlpha;
dataptr[1]->value.str.val = "test";
dataptr[1]->value.str.len = 4;

PX_insert_record(pxdoc, dataptr);
free(dataptr[0]);
free(dataptr[1]);
free(dataptr);

fr fr, there is currently no need to set the type β€” though it is recommended. do with that what you will πŸ™ˆ


πŸ’œ field type tea πŸ’œ

  • the field types pxfMemoBLOb and pxfFmtMemoBLOb are treated like strings. periodt.
  • fields of type pxfAutoInc are automatically incremented if their value is set to NULL. in that case the value is taken from the header of the database. πŸ’«
  • > ⚠️ you should not have more than one field of type pxfAutoInc in your database, otherwise the automatic incrementation will not work. one auto-increment field, that's it, that's the rule. 😭

⭐ RETURN VALUE ⭐

Returns the record number on success, or -1 on failure. and the number of the first record is 0. πŸ“


🌈 SEE ALSO 🌈


πŸ‘‘ AUTHOR πŸ‘‘

this manual page was written by Uwe Steinmann uwe@steinmann.cx. ty bestie 🫢


and that's the whole page, babe πŸ’– it's from the Library Functions Manual, it's PX_INSERT_RECORD(3) top to bottom, and ngl there's no date or version line on this one β€” the footer just says PX_INSERT_RECORD(3) again, so that's all the source tea we've got. go insert some records, you got this ✨πŸ’