tf_write_record(), sf_write_record()

Purpose

Writes a DP4 record to a file

Old names

#define _vwrite tf_write_record
#define _awrite sf_write_record

Syntax (CCOWN)

void tf_write_record(file_handle, short *datarec)
void sf_write_record(int file_handle, short *datarec)

Syntax (DP4DBAPI)

BOOLEAN dp4_sf_write_record(FCONN * fconn,const short * datarec)

Parameters

int file_handle,

File handle of file

 

FCONN * fconn

File handle of file

 

short* datarec

Pointer to the data to write to the file. The first two bytes must specify the length of the record.

Description

The tf_write_record() and sf_write_record() functions write a DP4 record to the current position in a file. You obtain the file handle with a successful call to tf_open() or sf_open().

The sf_write_record() function calls the file handling support in the database manager, and the tf_write_record() function calls the file handling support in the terminal manager. You must not mix up the server file functions with terminal file functions.

A DP4 record is a record corresponding to a structure of the form below:

struct MY_RECORD
{
short l; /* and normally but not necessary */
short typenr;
short generation;
short flags;
long timestamp;
/* other fields */
...
}

The L field is used to determine the number of bytes to write to the file. The file pointer is automatically incremented.

See also

tf_read_record(), tf_open()

Example

/*
C Functions Reference Manual
----------------------------
Filename: TF_WRITE.C
Example: tf_write_record
Purpose: Program fetches all the customer records
and writes them to the file CUSTOMER.EXT.
*/

/*
#db salesord
#c
#tables customer;
#end
*/

#include "dp4.h"
#include "tf_write.h"
/* generate this file by running LIBMAKE */
void process()
{
int fd;
int srch = FIRST;
map_draw(1,RETAIN); /* header map */
/* open CUSTOMER.EXT for read/write, as new, and
write in sequence */
fd = tf_open("CUSTOMER.EXT",VF_RW|VF_NEW|VF_SEQ);
if (fd > 0)
{
map_draw(2,RETAIN); /* progress map */
/* fetch, display and post the records to
CUSTOMER.EXT */
while (rec_fetch_main(srch,&customer.l))
{
srch = NEXT;
show_c(2,1,customer.name);
show_n(2,2,customer.customer_number);
show_c(2,3,customer.address[0]);
trm_refresh();
/* make count visible */
tf_write_record(fd,&customer.l);
}
}
else
askf_special(3,1,0);
/* tell user that file does not exist */
}