#define _SQL_OS_DOS386
#line 1 "dbcore.sqp"
// Embeded C++ Watcom SQL Database core
// $Id: dbcore.sqp 1.1 1994/11/02 10:53:36 leon Exp leon $
#include "dbcore.hpp"
#include <stdio.h>
#include <string.h>
#include <iostream.h>
#include <sqldef.h>
/////////////////////////////////////////////////////////////
/*
EXEC SQL INCLUDE SQLCA;
*/
#line 14 "dbcore.sqp"
#include "sqlca.h"
#ifdef __cplusplus
extern "C" {
#endif
extern SQLCA sqlca;
extern SQLCA _fd_ *sqlcaptr;
extern short int _ESQL_Version2_;
extern short int _ESQL_OS_DOS386_;
#ifdef __cplusplus
}
#endif
#include "sqlda.h"
#line 14 "dbcore.sqp"
static struct {
char _sqlfar *userid;
char _sqlfar *password;
short int num;
SQLCA _fd_ * _sqlfar *sqlca;
short int _sqlfar *sqlpp_version;
short int _sqlfar *sqlpp_os;
} __SQLV_dbcore_1 = { SQLFARNULL, SQLFARNULL, 0, &sqlcaptr, &_ESQL_Version2_, &_ESQL_OS_DOS386_ };
static char __SQLV_dbcore_2[] = "BEGIN SUBTRANSACTION";
static char __SQLV_dbcore_3[] = "BEGIN SUBTRANSACTION";
static char __SQLV_dbcore_4[] = "ROLLBACK SUBTRANSACTION";
/*
EXEC SQL INCLUDE SQLDA;
*/
#line 15 "dbcore.sqp"
static a_dblib_info _fd_ *DBParms;
SQLDA *SqlDA;
/*
EXEC SQL BEGIN DECLARE SECTION;
*/
#line 20 "dbcore.sqp"
char cursname[20];
/*
EXEC SQL END DECLARE SECTION;
*/
#line 22 "dbcore.sqp"
/** {secret} **/
#define CheckSQL(DB_SQL_ERROR) \
if (SQLCODE != SQLE_NOERROR) \
ErrorHandler(DB_SQL_ERROR)
/**
** Nastavi generator izpisa napake na funkcijo /userHandler/
**/
void Database::SetErrorHandler (void (* userHandler) (int))
{
ErrorHandler = userHandler;
}
void defaultHandler (int err)
{
char buffer[200];
if (err > 0)
{
sqlerror_message (&sqlca, buffer, sizeof (buffer));
cout << "SQL Napaka: " << buffer << endl;
}
}
void (*(Database::ErrorHandler)) (int err) = defaultHandler;
/**
** Kreira nov dostop do zunanje baze podatkov
**/
Database::Database ()
{
DBOpen = FALSE;
if (!db_init (&sqlca))
{
cout << "Napaka pri inicializaciji SQLCA\n";
}
}
/**
** Odpre bazo podatkov z imenom uporabnika /userName/, "sifro
** /password/ in "startnim stringom /startStr/
**/
BOOL Database::Open (const char *userName, const char *password,
const char *startStr)
{
String paramStr;
paramStr += userName;
paramStr += String (",");
paramStr += password;
DBParms = db_build_parms (&sqlca, (char *)(const char *)paramStr,
(char *)startStr);
CheckSQL (SQLE_UNABLE_TO_CONNECT);
db_parms_connect (&sqlca, DBParms);
CheckSQL (SQLE_UNABLE_TO_CONNECT);
DBOpen = TRUE;
return (TRUE);
}
/** Testira: Ali je baza odprta? **/
BOOL Database::IsOpen ()
{
if (DBOpen == TRUE)
return TRUE;
else
return FALSE;
}
/** Zapre bazo **/
void Database::Close ()
{
/*
EXEC SQL DISCONNECT;
*/
#line 113 "dbcore.sqp"
#line 113 "dbcore.sqp"
{
#line 113 "dbcore.sqp"
db_disconnect( &__SQLV_dbcore_1, SQLNULL );
#line 113 "dbcore.sqp"
}
db_destroy_parms (&sqlca, DBParms);
db_fini (&sqlca);
DBOpen = FALSE;
}
/** Vrne ime baze podatkov **/
const char * Database::GetDatabaseName ()
{
return (char _fd_ *) DBParms->database_name;
}
/*
EXEC SQL WHENEVER SQLERROR {ErrorHandler(SQLE_ERROR); return (FALSE);};
*/
#line 126 "dbcore.sqp"
/** naredi Commit v bazo **/
BOOL Database::Commit()
{
/*
EXEC SQL COMMIT WORK;
*/
#line 131 "dbcore.sqp"
#line 131 "dbcore.sqp"
{
#line 131 "dbcore.sqp"
db_commit( &__SQLV_dbcore_1, 0 );
#line 131 "dbcore.sqp"
if( SQLCODE < 0 ) {ErrorHandler(SQLE_ERROR); return (FALSE);};
#line 131 "dbcore.sqp"
}
return TRUE;
}
/** Izvede Rollback na celotni transakciji **/
BOOL Database::Rollback()
{
/*
EXEC SQL ROLLBACK WORK;
*/
#line 138 "dbcore.sqp"
#line 138 "dbcore.sqp"
{
#line 138 "dbcore.sqp"
db_rollback( &__SQLV_dbcore_1, 0 );
#line 138 "dbcore.sqp"
if( SQLCODE < 0 ) {ErrorHandler(SQLE_ERROR); return (FALSE);};
#line 138 "dbcore.sqp"
}
return TRUE;
}
/** Ozna"ci podtransakcijo **/
BOOL Database::BeginSubTrans()
{
/*
EXEC SQL BEGIN SUBTRANSACTION;
*/
#line 145 "dbcore.sqp"
#line 145 "dbcore.sqp"
{
#line 145 "dbcore.sqp"
{
#line 145 "dbcore.sqp"
db_execute_imm( &__SQLV_dbcore_1, __SQLV_dbcore_2, 2 );
#line 145 "dbcore.sqp"
if( SQLCODE < 0 ) {ErrorHandler(SQLE_ERROR); return (FALSE);};
#line 145 "dbcore.sqp"
}
#line 145 "dbcore.sqp"
}
return (TRUE);
}
/** Kon"ca podtransakcijo **/
BOOL Database::EndSubTrans()
{
/*
EXEC SQL BEGIN SUBTRANSACTION;
*/
#line 152 "dbcore.sqp"
#line 152 "dbcore.sqp"
{
#line 152 "dbcore.sqp"
{
#line 152 "dbcore.sqp"
db_execute_imm( &__SQLV_dbcore_1, __SQLV_dbcore_3, 2 );
#line 152 "dbcore.sqp"
if( SQLCODE < 0 ) {ErrorHandler(SQLE_ERROR); return (FALSE);};
#line 152 "dbcore.sqp"
}
#line 152 "dbcore.sqp"
}
return (TRUE);
}
/** Unici podtransakcijo **/
BOOL Database::RollbackSubTrans()
{
/*
EXEC SQL ROLLBACK SUBTRANSACTION;
*/
#line 159 "dbcore.sqp"
#line 159 "dbcore.sqp"
{
#line 159 "dbcore.sqp"
{
#line 159 "dbcore.sqp"
db_execute_imm( &__SQLV_dbcore_1, __SQLV_dbcore_4, 2 );
#line 159 "dbcore.sqp"
if( SQLCODE < 0 ) {ErrorHandler(SQLE_ERROR); return (FALSE);};
#line 159 "dbcore.sqp"
}
#line 159 "dbcore.sqp"
}
return (TRUE);
}
/** Direktmo izvede ukaz SQL, ki ne vra"ca rezultata **/
BOOL Database::ExecuteSQL (const char *sqlStm)
{
/*
EXEC SQL BEGIN DECLARE SECTION;
*/
#line 166 "dbcore.sqp"
char *buffer;
/*
EXEC SQL END DECLARE SECTION;
*/
#line 168 "dbcore.sqp"
buffer = (char *)sqlStm;
/*
EXEC SQL EXECUTE IMMEDIATE :buffer;
*/
#line 172 "dbcore.sqp"
#line 172 "dbcore.sqp"
{
#line 172 "dbcore.sqp"
db_execute_imm( &__SQLV_dbcore_1, buffer, 1 );
#line 172 "dbcore.sqp"
if( SQLCODE < 0 ) {ErrorHandler(SQLE_ERROR); return (FALSE);};
#line 172 "dbcore.sqp"
}
return (TRUE);
}
#if 0
main ()
{
Database hw;
hw.Open ("dba", "sql", "");
if (hw.IsOpen())
cout << "Baza je odprta\n";
else
cout << "Baza ni odprta\n";
hw.ExecuteSQL("insert into leon values ('A')");
hw.Commit();
hw.Close ();
return (0);
}
#endif
syntax highlighted by Code2HTML, v. 0.9.1