|
Sequential read
This example demonstrates how to retrieve records sequentially from an APPDS table. In the code the appds_read_record routine is called twice, first to read the first three records and then again to read the next three records. Critical elements are shown in bold.
#include <stdio.h>
#include "clib.h"
#include "acnet_errors.h"
#include "appds.h"
struct NAME_STRUCT {
char *last_name;
char *first_name;
};
void printout_record(struct NAME_STRUCT *record)
{
printf("First name:%s\n",record->first_name);
printf("Last Name:%s\n",record->record->last_name);
}
main()
{
struct NAME_STRUCT record_array[3];
int records_wanted = 3;
int records_returned;
char error_text[512];
int return_code; /* ACNET return code */
int i;
/* read the first 3 records */
return_code = appds_read_record("MY_TABLE",records_wanted,(void *) NULL,
record_array,&records_returned,error_text,"APPDB","ADBS");
if (return_code == APPDS_SUCCESS)
{
for(i=0;i < records_returned;i++)
printout_record(&record_array[i]);
} else {
printf("ERROR:%s\n",error_text);
}
/* Read the next 3 records */
return_code = appds_read_record("MY_TABLE",records_wanted,(void *) NULL,
record_array,&records_returned,error_text,"APPDB","ADBS");
if (return_code == APPDS_SUCCESS)
{
for(i=0;i< records_returned;i++)
printout_record(&record_array[i]);
} else {
printf("ERROR:%s\n",error_text);
}
}
|
Indexed read
This example demonstrates how to retrieve records via indexes from an APPDS table. In the code the appds_read_record routine is called twice, first to read the records who's record Id's are [1,4,6] and then again to read the records with Id's [10,22,45]. Critical elements are shown in bold.
#include <stdio.h>
#include "clib.h"
#include "acnet_errors.h"
#include "appds.h"
struct NAME_STRUCT {
char *last_name;
char *first_name;
};
void printout_record(struct NAME_STRUCT *record)
{
printf("First name:%s\n",record->first_name);
printf("Last Name:%s\n",record->record->last_name);
}
main()
{
struct NAME_STRUCT record_array[3];
int records_wanted = 3;
int records_returned;
char error_text[512];
int return_code; /* ACNET return code */
long id_array[3];
int i;
/* read the first 3 records */
id_array[0]=1;
id_array[1]=4;
id_array[2]=6;
return_code = appds_read_record("MY_TABLE",records_wanted,id_array,
record_array,&records_returned,error_text,"APPDB","ADBS");
if (return_code == APPDS_SUCCESS)
{
for(i=0;i<records_returned;i++)
printout_record(&record_array[i]);
} else {
printf("ERROR:%s\n",error_text);
}
/* Read the next 3 records */
id_array[0]=10;
id_array[1]=22;
id_array[2]=45;
return_code = appds_read_record("MY_TABLE",records_wanted,id_array,
record_array,&records_returned,error_text,"APPDB","ADBS");
if (return_code == APPDS_SUCCESS)
{
for(i=0;i<records_returned;i++)
printout_record(&record_array[i]);
} else {
printf("ERROR:%s\n",error_text);
}
}
|
Keyed read
This example demonstrates how to retrieve records via a key from an APPDS table. In the code the appds_read_record routine is called passing "FERMI" for the key value. Critical elements are shown in bold.
#include <stdio.h>
#include "clib.h"
#include "acnet_errors.h"
#include "appds.h"
struct NAME_STRUCT {
char *last_name;
char *first_name;
};
void printout_record(struct NAME_STRUCT *record)
{
printf("First name:%s\n",record->first_name);
printf("Last Name:%s\n",record->record->last_name);
}
main()
{
struct NAME_STRUCT record_array[3];
int max_records_allowed = 3;
int records_returned;
char error_text[512];
int return_code; /* ACNET return code */
char key_value = "FERMI";
int i;
return_code = appds_read_recod("MY_TABLE",max_records_allowed,key_value,
record_array,&records_returned,error_text,"APPDB","ADBS");
if (return_code == APPDS_SUCCESS)
{
for(i=0;i<records_returned;i++)
printout_record(&record_array[i]);
} else {
printf("ERROR:%s\n",error_text);
}
}
|
webmaster@adwww.fnal.gov
Last modified: Fri Feb 12 16:06:58 CST 1999
|