/* 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_db_ecpg.pgc ---
 *
 * Change Log:
 *
 * 05 Mar 02 - Created file;
 *
 * 13 Mar 02 - Removed function from main;
 */

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

exec sql include sqlca;



/*
 * --- Define Statements
 */



/*
 * --- Global variables
 */

exec sql begin declare section;

  char create_str[25];
  char dbname [25];

exec sql end declare section;



/* --- Functions begin here --- */


/* db_createdb ( )
 *
 * Create a new database.
 */
int
db_createdb (char *dbname)
{ 
  /* strcpy (dbname, "test2"); */
  strcpy (create_str, "createdb ");

  strcat(create_str, dbname);

  printf("Attempting to create database, %s\n", dbname);
  system (create_str);
  
  /* exec sql connect to :dbname; */
  db_connect_ecpg(dbname);

  if (sqlca.sqlcode != 0)
  {
    printf("connection to database, %s, failed\n", dbname);
    return (FAILURE);
  } else {
    printf("Successfully created and connected to database, %s\n",dbname);
  }

  exec sql BEGIN WORK;

  exec sql CREATE TABLE TPoints (
             id          int2   PRIMARY KEY,
             x           float4,
             y           float4,
             z           float4,
             saved       int2,
             modified    int2,			
             deleted     int2 );

  if (sqlca.sqlcode != 0)
  {
    printf("Create table, TPoints, failed\n");
    return (FAILURE);
  }

  exec sql COMMIT WORK;

  /* exec sql disconnect all; */

  return(SUCCESS);
}
