/******************************************************************************
**
** Source File Name = tbdefine.sqc
**
** Licensed Materials - Property of IBM
**
** (C) COPYRIGHT International Business Machines Corp. 1995, 1999
** All Rights Reserved.
**
** US Government Users Restricted Rights - Use, duplication or
** disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
**
**
** PURPOSE :
** Shows how to create/alter/drop tables.
**
** For more information about these samples see the README file.
**
** For more information on programming in C, see the:
** - "Programming in C and C++" section of the Application Development Guide
** For more information on Building C Applications, see the:
** - "Building C Applications" section of the Application Building Guide.
**
** For more information on the SQL language see the SQL Reference.
**
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utilemb.h"
int TbCreate( void) ;
int TbAlter( void) ;
int TbDrop( void) ;
EXEC SQL INCLUDE SQLCA;
int main(int argc, char *argv[])
{ int rc = 0;
char dbAlias[15] ;
char user[15] ;
char pswd[15] ;
/* checks the command line arguments */
rc = CmdLineArgsCheck1( argc, argv, dbAlias, user, pswd );
if ( rc != 0 ) return( rc ) ;
printf("\n\nTABLES: HOW TO CREATE/ALTER/DROP TABLES.\n");
/* initialize the embedded application */
rc = EmbAppInit( dbAlias, user, pswd);
if ( rc != 0 ) return( rc ) ;
rc = TbCreate( ) ;
/* rc = TbAlter( ) ; */
rc = TbDrop( ) ;
/* terminate the embedded application */
rc = EmbAppTerm( dbAlias);
return( rc ) ;
} /* end main */
/******************************************************************************
** TbCreate
******************************************************************************/
int TbCreate( void)
{ int rc = 0;
printf("\nSHOW HOW TO CREATE A TABLE:\n");
/* create the table */
printf("\n Execute the statement\n");
printf(" CREATE TABLE TBDEFINE ( \n");
printf(" Col1 SMALLINT, \n");
printf(" Col2 CHAR(7), \n");
printf(" Col3 VARCHAR(7) , \n");
printf(" Col4 DEC(9,2), \n");
printf(" Col5 DATE, \n");
printf(" Col6 BLOB(5000), \n");
printf(" Col7 CLOB(5000) )\n");
EXEC SQL CREATE TABLE TBDEFINE (
Col1 SMALLINT,
Col2 CHAR(7),
Col3 VARCHAR(7) ,
Col4 DEC(9,2),
Col5 DATE,
Col6 BLOB(5000),
Col7 CLOB(5000) ) ;
EMB_SQL_CHECK( "CREATE TABLE");
EXEC SQL COMMIT;
EMB_SQL_CHECK( "COMMIT");
return(rc);
}
/******************************************************************************
** TbDrop
******************************************************************************/
int TbDrop( void)
{ int rc = 0;
printf("\nSHOW HOW TO DROP A TABLE:\n");
/* drop the table */
printf("\n Execute the statement\n");
printf(" DROP TABLE TBDEFINE\n");
EXEC SQL DROP TABLE TBDEFINE ;
EMB_SQL_CHECK( "DROP TABLE");
EXEC SQL COMMIT;
EMB_SQL_CHECK( "COMMIT");
return(rc);
}