/****************************************************************************
** (c) Copyright IBM Corp. 2007 All rights reserved.
**
** The following sample of source code ("Sample") is owned by International
** Business Machines Corporation or one of its subsidiaries ("IBM") and is
** copyrighted and licensed, not sold. You may use, copy, modify, and
** distribute the Sample in any form without payment to IBM, for the purpose of
** assisting you in the development of your applications.
**
** The Sample code is provided to you on an "AS IS" basis, without warranty of
** any kind. IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR
** IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Some jurisdictions do
** not allow for the exclusion or limitation of implied warranties, so the above
** limitations or exclusions may not apply to you. IBM shall not be liable for
** any damages you suffer as a result of using, copying, modifying or
** distributing the Sample, even if IBM has been advised of the possibility of
** such damages.
*****************************************************************************
**
** SOURCE FILE NAME: tbcreate.sqC
**
** SAMPLE: How to create and drop tables
**
** SQL STATEMENTS USED:
** INCLUDE
** CREATE TABLE
** DROP
**
**
*****************************************************************************
**
** For more information on the sample programs, see the README file.
**
** For information on developing C++ applications, see the Application
** Development Guide.
**
** For information on using SQL statements, see the SQL Reference.
**
** For the latest information on programming, compiling, and running DB2
** applications, visit the DB2 Information Center at
** http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp
****************************************************************************/
#include <sqlenv.h>
#include <sqlutil.h>
#include "utilemb.h"
#if ((__cplusplus >= 199711L) && !defined DB2HP && !defined DB2AIX) || \
(DB2LINUX && (__LP64__ || (__GNUC__ >= 3)) )
#include <iostream>
using namespace std;
#else
#include <iostream.h>
#endif
EXEC SQL INCLUDE SQLCA;
class TbCreate
{
public:
int Create();
int Alter();
int Drop();
};
int TbCreate::Create()
{
int rc = 0;
cout << "\n-----------------------------------------------------------";
cout << "\nUSE THE SQL STATEMENT" << endl;
cout << " CREATE TABLE" << endl;
cout << "TO CREATE A TABLE:" << endl;
// create the table
cout << "\n Execute the statement" << endl;
cout << " CREATE TABLE schname.tbname(Col1 SMALLINT," << endl;
cout << " Col2 CHAR(7)," << endl;
cout << " Col3 VARCHAR(7)," << endl;
cout << " Col4 DEC(9, 2)," << endl;
cout << " Col5 DATE," << endl;
cout << " Col6 BLOB(5000)," << endl;
cout << " Col7 CLOB(5000))" << endl;
EXEC SQL CREATE TABLE schname.tbname(col1 SMALLINT,
col2 CHAR(7),
col3 VARCHAR(7),
col4 DEC(9, 2),
col5 DATE,
col6 BLOB(5000),
col7 CLOB(5000));
EMB_SQL_CHECK("Table -- Create");
EXEC SQL COMMIT;
EMB_SQL_CHECK("Transaction -- Commit");
return rc;
} //TbCreate::Create
int TbCreate::Drop()
{
int rc = 0;
cout << "\n-----------------------------------------------------------";
cout << "\nUSE THE SQL STATEMENT" << endl;
cout << " DROP" << endl;
cout << "TO DROP A TABLE:" << endl;
// drop the table
cout << "\n Execute the statement" << endl;
cout << " DROP TABLE schname.tbname" << endl;
EXEC SQL DROP TABLE schname.tbname;
EMB_SQL_CHECK("Table -- Drop");
EXEC SQL COMMIT;
EMB_SQL_CHECK("Transaction -- Commit");
return rc;
} //TbCreate::Drop
int main(int argc, char *argv[])
{
int rc = 0;
CmdLineArgs check;
TbCreate create;
DbEmb db;
// check the command line arguments
rc = check.CmdLineArgsCheck1(argc, argv, db);
if (rc != 0)
{
return rc;
}
cout << "\nTHIS SAMPLE SHOWS HOW TO CREATE AND DROP TABLES." << endl;
// connect to database
rc = db.Connect();
if (rc != 0)
{
return rc;
}
// exam the member functions
rc = create.Create();
rc = create.Drop();
// disconnect from database
rc = db.Disconnect();
return rc;
} //main