//
// Source File Name = static.sqC
//
// Licensed Materials - Property of IBM
//
// (C) COPYRIGHT International Business Machines Corp. 1995, 2000
// All Rights Reserved.
//
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//
//
// PURPOSE: This sample program demonstrates the use of static SQL.
// It will output the entry in the FIRSTNME column where
// the entry in the LASTNAME column equals "JOHNSON".
// Otherwise, an error message is printed.
//
// An external function "check_error" is contained in the file "util.C"
// which must be compiled along with this file.
//
// EXTERNAL DEPENDENCIES :
// - Existing database for precompile purposes.
// - Precompile with the SQL precompiler (PREP in DB2)
// - Binding to a database (BIND in DB2)
// - 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.
//
// 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 <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <sqlca.h>
#include "utilemb.h"
EXEC SQL INCLUDE SQLCA;
class Static {
public:
Static ();
Static (char *, char *);
Select ();
~Static ();
private:
EXEC SQL BEGIN DECLARE SECTION;
char firstname[13];
char userid[9];
char passwd[19];
EXEC SQL END DECLARE SECTION;
};
Static::Static () {
cout << "Connecting to database SAMPLE... \n";
EXEC SQL CONNECT TO sample;
EMB_SQL_CHECK("CONNECT TO SAMPLE") ;
cout << "Connected to database SAMPLE \n";
}
Static::Static (char *user, char *pass) {
strcpy(userid,user);
strcpy(passwd,pass);
cout << "Connecting to database SAMPLE... \n";
EXEC SQL CONNECT TO sample USER :userid USING :passwd;
EMB_SQL_CHECK("CONNECT TO SAMPLE") ;
cout << "Connected to database SAMPLE \n";
}
Static::Select () {
EXEC SQL SELECT FIRSTNME INTO :firstname
FROM employee
WHERE LASTNAME = 'JOHNSON';
EMB_SQL_CHECK("SELECT statement") ;
cout << "First name = " << firstname << '\n';
return 0;
}
Static::~Static () {
EXEC SQL CONNECT RESET;
EMB_SQL_CHECK("CONNECT RESET") ;
}
int main(int argc, char *argv[]) {
cout << "Sample C program: STATIC\n";
if (argc == 1) {
Static sampleStatic;
sampleStatic.Select();
} else if (argc == 3) {
Static sampleStatic (argv[1], argv[2]);
sampleStatic.Select();
} else {
cout << "\nUSAGE: static userid passwd\n\n";
} // end if
return 0;
}
// end of program : static.sqC