home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
DBObject.sc
< prev
next >
Wrap
Text File
|
1996-05-31
|
3KB
|
123 lines
/*---------------------------------------------------------------------------
*
* Copyright (c) 1993 by Westmount Technology B.V., Delft, The Netherlands.
*
* 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 Westmount Technology B.V.
*
*---------------------------------------------------------------------------
*
* File : @(#)DBObject_ing.sc 1.7
* Author : frmo
* Original date : 10-3-1993
* Description : Base Class for all Database Classes
*
*---------------------------------------------------------------------------
*/
static const char SccsId[]="@(#)DBObject_ing.sc 1.7 11/5/93 Copyright 1993 Westmount Technology";
#include "stream.h"
#include <rw/cstring.h>
#ifndef DBOBJECT_HXX
#include "DBObject.hxx"
#endif
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION;
#define MAX_NAME_LEN 81
EXEC SQL END DECLARE SECTION;
static unsigned hashInt(const int& i)
{
return i;
}
static unsigned hashName(const RWCString& s)
{
return s.hash();
}
DBObject::DBObject(const RWCString &name) :
dbState(CREATED),
className(name)
{
}
DBObject::~DBObject()
{
}
int DBObject::connectDB(const char *name)
{
const
EXEC SQL BEGIN DECLARE SECTION;
char *dbName = name;
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLERROR CALL SQLPRINT;
EXEC SQL WHENEVER SQLWARNING CALL SQLPRINT;
EXEC SQL CONNECT :dbName;
if (sqlca.sqlcode != 0)
return -1;
return 0;
}
int DBObject::beginWork()
{
// no-op: automatically done by Ingres
return 0;
}
int DBObject::commit()
{
EXEC SQL COMMIT;
return sqlca.sqlcode != 0 ? -1 : 0;
}
int DBObject::rollback()
{
EXEC SQL ROLLBACK;
return sqlca.sqlcode != 0 ? -1 : 0;
}
int DBObject::notFound()
{
return dbState == SQL_ERROR && sqlca.sqlcode == 100;
}
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;
}