#include <stdio.h>
#include "clib.h"
#include "cns_data_structs.h"
#include "acnet_errors.h"
main()
{
db_handle_t *handle;
short acnet_status;
unsigned long rows;
unsigned long bytes_returned;
char my_name[30];
DATA_STRUCT *raw_data;

  acnet_status=db_open(&handle,"ADBS","appdb",300);
  if (acnet_status!=SQL_OK) {
    (void)printf("%s",db_error(handle));
    return(acnet_status);
  }

  rows=1;
  acnet_status=db_select(handle,"select name from users where id=1",
			 &rows, sizeof(my_name),my_name);
  if ((acnet_status!=SQL_MOREROWS)&&(acnet_status!=SQL_OK)) {
    (void)printf("%s",db_error(handle));
    db_close(handle);
    return(acnet_status);
  }
  if (acnet_status==SQL_MOREROWS) printf("more than one name exits for id=1\n");
  if(rows==1) printf("one name for id=1 is %30.30s\n",my_name);
  else printf("no name exists for id=1\n");

  acnet_status=db_modify(handle,"update users set name='new' where id=1",
			 &rows);
  if (acnet_status!=SQL_OK) {
    (void)printf("%s",db_error(handle));
    db_close(handle);
    return(acnet_status);
  }
  printf("%d name(s) for id=1 were set to 'new'\n",rows);

  rows=0;
  acnet_status=db_select(handle,"select col1, col2, col4 from table",
			 &rows,(unsigned long)0,(void *)0);
  raw_data = (DATA_STRUCT *) clib_malloc(sizeof(DATA_STRUCT));
  while(!(acnet_status = db_nextrow(handle,sizeof(DATA_STRUCT),raw_data,
				    &bytes_returned))) {
    if (bytes_returned == 0)
      break;
    /* process raw_data here */
  }
  if (acnet_status!=SQL_OK) {
    (void)printf("%s",db_error(handle));
    db_close(handle);
    return(acnet_status);
  } 
  db_close(handle);
}