home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
DBObject.pc
< prev
next >
Wrap
Text File
|
1996-05-31
|
3KB
|
141 lines
/*---------------------------------------------------------------------------
*
* Copyright (c) 1995 by Cadre Technologies Inc.
*
* This software is furnished under a license and may be used only in
* accordance with the terms of such license and with the inclusion of
* the above copyright notice. This software or any other copies thereof
* may not be provided or otherwise made available to any other person.
* No title to and ownership of the software is hereby transferred.
*
* The information in this software is subject to change without notice
* and should not be construed as a commitment by Cadre Technologies Inc.
*
*---------------------------------------------------------------------------
*
* File : @(#)DBObject.pc 1.1
* Original date : November 1995
* Description : Base Class for all Database Classes
*
*---------------------------------------------------------------------------
*/
static const char SccsId[]="@(#)DBObject.pc 1.1\t20 Dec 1995 Copyright 1995 Cadre Technologies Inc.";
EXEC SQL INCLUDE sqlca;
#include "stream.h"
#include <string.h>
#ifndef DBOBJECT_HXX
#include "DBObject.hxx"
#endif
#ifndef SQLPRINT_HXX
#include "SqlPrint.hxx"
#endif
EXEC SQL WHENEVER SQLERROR DO sqlprint();
DBObject::DBObject(const RWCString &name) :
dbState(CREATED),
className(name)
{
}
DBObject::~DBObject()
{
}
//
// Connect database for automatic logons (OPS$username accounts)
//
int DBObject::connectDB()
{
EXEC SQL BEGIN DECLARE SECTION;
char name[2];
EXEC SQL END DECLARE SECTION;
strcpy(name, "/");
EXEC SQL CONNECT :name;
if (sqlca.sqlcode != 0)
return -1;
return 0;
}
//
// Connect database using name and password
//
int DBObject::connectDB(const char *userName, const char *password)
{
EXEC SQL BEGIN DECLARE SECTION;
char name[81];
char word[81];
EXEC SQL END DECLARE SECTION;
strcpy(name, userName);
strcpy(word, password);
EXEC SQL CONNECT :name IDENTIFIED BY :word;
if (sqlca.sqlcode != 0)
return -1;
return 0;
}
int DBObject::beginWork()
{
//
// Not needed in Oracle: you are always inside a transaction
//
return 0;
}
int DBObject::commit()
{
EXEC SQL COMMIT work;
return sqlca.sqlcode != 0 ? -1 : 0;
}
int DBObject::rollback()
{
EXEC SQL ROLLBACK work;
return sqlca.sqlcode != 0 ? -1 : 0;
}
int DBObject::notFound()
{
return ((dbState == SQL_ERROR) && (sqlca.sqlcode > 0));
}
void DBObject::resetState()
{
dbState = CREATED;
}
int DBObject::processSqlStatus()
{
switch (dbState) {
case CREATED:
case NORMAL:
if (sqlca.sqlcode != 0) {
dbState = SQL_ERROR;
return -1;
} else {
dbState = NORMAL;
return 0;
}
case SQL_ERROR:
case TYPE_ERROR:
return -1;
}
return -1;
}