/*******************************************************************************
**
** Source File Name = ebcdicdb.c 1.1
**
** Licensed Materials - Property of IBM
**
** (C) COPYRIGHT International Business Machines Corp. 1999
** All Rights Reserved.
**
** US Government Users Restricted Rights - Use, duplication or
** disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
**
**
** PURPOSE :
** This program is an example of how APIs are implemented in order to
** CREATE a DATABASE with the EBCDIC 037 standard collating sequence,
** then DROP the DATABASE.
**
** A user-defined collating sequence allows the user to specify the
** collating behavieour of the database. This can be used by
** applications that require compatibility to the collating
** behaviour of host database products. For example, simulating
** the collating behaviour of DB2/MVS CCSID 500 (EBCDIC International)
** can be achived by specifying a colating sequence that maps
** codepage 819 characters to CCSID 500 characters when the
** database is created.
**
** APIs USED :
** INSTANCE ATTACH sqleatin()
** CREATE DATABASE sqlecrea()
** DROP DATABASE sqledrpd()
**
** STRUCTURES USED :
** sqlca
** sqledbdesc
** sqledbcountryinfo
**
** OTHER FUNCTIONS USED :
** 'C' COMPILER LIBRARY :
** stdio.h - printf
**
** external :
** check_error : Checks for SQLCODE error, and prints out any
** [in util.c] related information available.
** This procedure is located in the util.c file.
**
**
** EXTERNAL DEPENDENCIES :
** - Compiling and linking with the IBM Cset++ compiler (AIX and OS/2)
** or the Microsoft Visual C++ compiler (Windows)
** or the compiler supported on your platform.
** - a database by the name of "DBUDCS" does not exist.
**
** 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 <sqle850b.h> /* Definition of the collating sequence */
#include <sqlutil.h>
#include <sqlenv.h>
#include "util.h"
#define CHECKERR(CE_STR) if (check_error (CE_STR, &sqlca) != 0) return 1;
int main (int argc, char* argv[]) {
struct sqlca sqlca;
struct sqledbdesc db_desc;
struct sqledbcountryinfo dbCountryInfo;
char userid[9];
char passwd[19];
char nodename[9];
strcpy(db_desc.sqldbdid, SQLE_DBDESC_2);
db_desc.sqldbccp = 0;
db_desc.sqldbcss = SQL_CS_USER;
memcpy(db_desc.sqldbudc, sqle_850_037, SQL_CS_SZ);
strcpy(db_desc.sqldbcmt, "EBCDIC");
db_desc.sqldbsgp = 0;
db_desc.sqldbnsg = 10;
db_desc.sqltsext = -1;
db_desc.sqlcatts = NULL;
db_desc.sqlusrts = NULL;
db_desc.sqltmpts = NULL;
if (argc == 4) {
strcpy (userid, argv[1]);
strcpy (passwd, argv[2]);
strcpy (nodename, argv[3]);
/*************************/
/* ATTACH API called */
/*************************/
sqleatin (nodename, userid, passwd, &sqlca);
}
else if (argc != 1) {
printf("USAGE: ebcdicdb [userid password remote_nodename]\n");
return 1;
}
strcpy(dbCountryInfo.sqldbcodeset, "IBM-850");
strcpy(dbCountryInfo.sqldblocale, "C");
printf ("CREATing the temporary database DBEBCDIC...\n");
printf ("please wait... this will take a while...\n");
/****************************\
* CREATE DATABASE API called *
\****************************/
sqlecrea( "DBEBCDIC",
"DBEBCDIC",
"",
&db_desc,
&dbCountryInfo,
'\0',
NULL,
&sqlca
) ;
CHECKERR("creating the database");
printf ("database DBEBCDIC with the EBCDIC 037 standard\n");
printf ("collating sequence created successfully.\n");
printf ("DROPping the database DBEBCDIC\n");
/**************************\
* DROP DATABASE API called *
\**************************/
sqledrpd ("DBEBCDIC", &sqlca);
CHECKERR("dropping the database");
return 0;
}