/* GtkCAD - A free modular CAD/CAE/CAM software
 *
 * Copyright (C) 2000-2002 H. James Parker <hopeye@cfl.rr.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later 
 * version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General 
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/* --- test_edit_ecpg.pgc ---
 *
 * Change Log:
 *
 * 13 Mar 02 - Created file;
 */

/*
 * --- Include files
 */
#include "test.h"

exec sql include sqlca;


/*
 * --- Define Statements
 */



/*
 * --- Internal Global data structures
 */



/*
 * --- Internal function prototypes
 */
 


/*
 * --- Internal Global Variables
 */

exec sql begin declare section;

  int   point_id;
  float x;
  float y;
  float z;
  int   saved;
  int   modified;
  int   deleted;

exec sql end declare section;



/*
 * --- functions begin here ...
 */


/*
 * db_edit_point ( )
 *
 * Update a row in the points table with new values.
 */
int
db_edit_point (typPoint *point)
{
  exec sql BEGIN WORK;

  point_id = point->id;
  x = point->x;
  y = point->y;
  z = point->z;
  saved = TRUE;
  modified = TRUE;
  deleted = FALSE;

  printf("Attempting to modify: %d, %f, %f, %f, %d, %d, %d\n",
         point_id, x, y, z, saved, modified, deleted);

  exec sql UPDATE tpoints
           SET x = :x,
               y = :y,
               z = :z,
               saved = :saved,
               modified = :modified,
               deleted = :deleted
           WHERE id = :point_id;

  if (sqlca.sqlcode < 0)
  {
    printf("Message 1: Modify points table failed\n");
    exec sql ROLLBACK WORK;

    return (FAILURE);

  } 
  else 
  {
    if (sqlca.sqlerrd[2] != 1)
    {
      printf("Message 2: Modify points table failed\n");
      exec sql ROLLBACK WORK;

      return (FAILURE);
    }
  }

  exec sql COMMIT WORK;
  return (SUCCESS);
}