---
name: "PX_insert_record"
section: "3"
platform: "linux"
package: "pxlib-dev"
version: "0.6.9-1+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/PX_insert_record"
---

# PX\_insert\_record(3)

Inserts a new record in the Paradox file

## NAME

PX\_insert\_record — Inserts a new record in the Paradox file

## SYNOPSIS

\#include \<paradox.h\>

int PX\_insert\_record(pxdoc\_t \*pxdoc, pxval\_t \*\*dataptr)

## DESCRIPTION

Inserts a new record stored in the array **dataptr** 		  into a Paradox file. The position of the record will be determined  by the function itself, starting at the beginning of the file and  searching towards the end for a free slot. A free slot can be the result  of former calls of **[PX\_delete\_record(3)](/PX_delete_record/3.md)** or not  completely filled data blocks in the input file. If there is no free  slot within the file, then a new record will be added at the  end.

Blobs will be automatically written if a blob file was set  with **[PX\_set\_blob\_file(3)](/PX_set_blob_file/3.md)**.

The memory for **dataptr** and the field values  can be freed after  **PX\_insert\_record** has been called.

Each single element in the array of pointers to pxval\_t can be easily  created with **MAKE\_PXVAL(pxdoc\_t \*pxdoc, pxval\_t \*val)** 			and setting the actual value afterwards. A quite common way to build up  the record is the following:

```
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);
```

There is currently no need to set the type, though it is  recommended.

The field types pxfMemoBLOb and pxfFmtMemoBLOb are treated  like strings.

Fields of type pxfAutoInc are automatically incremented if  its value is set to NULL. In such a 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.

## RETURN VALUE

Returns the record number on success or -1 on failure. The number  of the first record is 0.

## SEE ALSO

**[PX\_retrieve\_record(3)](/PX_retrieve_record/3.md)**,  **[PX\_delete\_record(3)](/PX_delete_record/3.md)**,  **[PX\_update\_record(3)](/PX_update_record/3.md)**

## AUTHOR

This manual page was written by Uwe Steinmann uwe@steinmann.cx.
