/////////////////////////
Posting #1 of 2
/////////////////////////
====================================================
Oracle8
Oracle Pro*C/C++ Precompiler, Release 8.0
Sun WorkShop Compiler C++ 4.2
RogueWave Tools.h++ 7.0
SunOS 5.6
====================================================
====================================================
============== List Of Program Files ===============
The algorithm contains the following files :
1. oraw.h classes
2. oraw.pc functions, methods
====================================================
---> ################################### <---
---> This posting contains file 'oraw.h' <---
---> ################################### <---
#########################################################
=== File #1 of 2 : oraw.h ===============================
------------------- Pro*C/C++ code : BEGIN --------------
// ==============================================================
//
// Copyright (c) 2000 by Alex Vinokur. This work and all works
// derived from it may be copied and modified without any
// restrictions other than that a copy of this copyright notice
// must be included in any copy of this work or any derived work.
//
// ==============================================================
static char id_h[] = "@(#)Author ## "__FILE__" ::: Alex Vinokur";
// ##############################################################
// =========================
// C++Wrapper Around Oracle
// =========================
//
// FILE : oraw.h
//
// AUTHOR : Alex Vinokur
//
// DESCRIPTION :
// Classes :
// - OraDatabase;
// - OraTableColumn
//
// DATE VERSION
// ---- -------
// Feb-10-2000 Version 1.0
//
// ##############################################################
#ifndef ORAW_H
#define ORAW_H
//==========================
#include <limits.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <signal.h>
#include <iostream.h>
#include <fstream.h>
#include <strstream.h>
#include <iomanip.h>
#include <ctype.h>
#include <assert.h>
#include <errno.h>
#include <typeinfo.h>
#include <time.h>
#include <pwd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <rw/compiler.h>
#include <rw/cstring.h>
#include <rw/tvordvec.h>
#include <rw/tvsrtvec.h>
#include <rw/tpordvec.h>
#include <rw/tpsrtvec.h>
#include <rw/rstream.h>
#include <rw/rwerr.h>
#include <rw/coreerr.h>
#include <sqlca.h>
#include <sqlda.h>
#include <sqlcpr.h>
#include <oraca.h>
//==========================
//###################################################################
//################ DEFINES ##########################################
//###################################################################
//=========================
//-------------------------------------------------------------------
#define THIS_MESSAGE(msg) msg << " [ " << __FILE__ << ", #" << __LINE__
<< "; " << funcName << " ]" << endl
//#define INFO_BEFORE_ORACLE_ACTION(msg) cout << "INFO (BEFORE ACTION) :
" << THIS_MESSAGE(msg);
#define INFO_BEFORE_ORACLE_ACTION(msg)
#define WARNING_BEFORE_ORACLE_ACTION(msg) cout << "WARNING (BEFORE
ACTION): " << THIS_MESSAGE(msg);
#define ERROR_BEFORE_ORACLE_ACTION(msg) cout << "ERROR (BEFORE ACTION) :
" << THIS_MESSAGE(msg);
#define FATAL_BEFORE_ORACLE_ACTION(msg) cout << "FATAL (BEFORE ACTION) :
" << THIS_MESSAGE(msg);
//#define INFO_AFTER_ORACLE_ACTION(msg) cout << "INFO (AFTER ACTION;
sqlcode = " << sqlca.sqlcode << ") : " << THIS_MESSAGE(msg);
#define INFO_AFTER_ORACLE_ACTION(msg)
#define WARNING_AFTER_ORACLE_ACTION(msg) cout << "WARNING (AFTER ACTION)
: " << THIS_MESSAGE(msg);
#define ERROR_AFTER_ORACLE_ACTION(msg) cout << "ERROR (AFTER ACTION) : "
<< THIS_MESSAGE(msg);
#define FATAL_AFTER_ORACLE_ACTION(msg) cout << "FATAL (AFTER ACTION) : "
<< THIS_MESSAGE(msg);
#define FATAL_ASSERT(msg) cout << "FATAL (ASSERT) : " <<
THIS_MESSAGE(msg);
//=========================================
#define MAX_VALUE(x,y) ((x) > (y) ? (x) : (y))
//=========================================
#define PRINT_VALUE(col_no, col_value, col_indicator) \
cout << "" \
<< " \t" \
<< "col [" \
<< col_no \
<< "] : " \
<< "value = <" \
<< col_value \
<< ">" \
<< ", " \
<< "indicator = <" \
<< col_indicator \
<< ">" \
<< endl
//=========================================
#define STR_LOCATION RWCString (" [ ") + RWCString (__FILE__) + ", #" +
to_rwstring (__LINE__) + " ]"
#define sql_ERROR_PRINT(msg, reason) sql_error_print (msg, STR_LOCATION,
reason)
#define sql_ERROR_ACTION(msg) sql_error_action (msg, STR_LOCATION)
//###################################################################
//################# FUNCTIONS DECLARATIONS ##########################
//###################################################################
//=========================================
void sql_error_print (
const RWCString& msg_i,
const RWCString& location_i,
const RWCString& conclusion_i
);
//=========================================
void sql_error_action (
const RWCString& msg_i,
const RWCString& location_i
);
//=========================================
void sql_bug();
//###################################################################
//################# ENUMS ###########################################
//###################################################################
//##################################################
enum OracleTypeEnum
{
UNDEF_OracleTypeEnum,
NUMBER_OracleType,
VARCHAR2_OracleType,
LAST_OracleTypeEnum
};
//##################################################
enum Oracle_sqlcode_Enum
{
NO_STATEMENT_PARSE__1003 = -1003,
TABLE_OR_VIEW_DOES_NOT_EXIST__942 = -942,
INVALID_COLUMN_NAME__904 = -904,
INVALID_SQL_STATEMENT__900 = -900,
UNIQUE_CONSTRAINT_VIOLATED__1 = -1,
NO_ERRORS__0 = 0,
NO_DATA_FOUND__1403 = 1403,
LAST_Oracle_sqlcode_Enum
};
//###################################################################
//################# CONSTANTS #######################################
//###################################################################
const RWCString ALL_tables_ORA_CNS = "ALL_TABLES";
const RWCString USER_tables_ORA_CNS = "USER_TABLES";
const RWCString USER_tab_columns_ORA_CNS = "USER_TAB_COLUMNS";
const RWCString BA_META_DATA_class_attr_desc_PROJ_CNS =
"BA_META_DATA_class_attr_desc";
const RWCString NO_VALUE_ORA_CNS = "---NO_VALUE---";
const RWCString TRUNCATED_VALUE_ORA_CNS = "---TRUNCATED_VALUE---";
//###################################################################
//#################### TEMPLATE FUNCTIONS ###########################
//###################################################################
template <class T>
RWCString to_rwstring (T value_i, int width_i = -1, char fill_i = ' ')
{
RWCString ret_stringValue;
strstream tmp_strstream;
//=================================
if (width_i > 0)
{
tmp_strstream.width (width_i);
tmp_strstream.fill (fill_i);
}
tmp_strstream << value_i;
//=================================
tmp_strstream << ends;
ret_stringValue = tmp_strstream.str();
tmp_strstream.rdbuf()->freeze (0);
//=================================
return ret_stringValue;
} // RWCString to_rwstring (T value_i)
//###################################################################
//###################################################################
//################# class OraTableColumn ############################
//###################################################################
//===============================
class OraDatabase;
//===============================
class OraTableColumn
{
friend RWBoolean operator== (const OraTableColumn& inst1_i, const
OraTableColumn& inst2_i);
friend ostream& operator<< (ostream& ostr_io, const OraTableColumn&
inst_i);
friend class OraDatabase;
private :
RWCString colName_;
OracleTypeEnum colTypeEnum_;
RWCString colTypeString_;
int colSize_;
RWCString colStringedValue_;
short colValueIndicator_;
//-----------------------------
static long long createdInstances_s;
static long long destroyedInstances_s;
//-----------------------------
public :
OraTableColumn ();
// Constructor-1
// Description-Constructor
OraTableColumn (
const RWCString& colName_i,
OracleTypeEnum colTypeEnum_i,
int colSize_i = 0
);
// Constructor-2
// Description-Constructor
OraTableColumn (
const RWCString& colName_i,
const RWCString& colTypeString_i,
int colSize_i
);
// Constructor-3
// Value-Constructor
OraTableColumn (
const RWCString& colName_i,
const RWCString& colStringedValue_i = RWCString ()
);
virtual ~OraTableColumn ();
void foo ();
void doStatistics () const;
RWCString get_colName () const {return colName_;}
OracleTypeEnum get_colTypeEnum () const {return colTypeEnum_;}
RWCString get_colTypeString () const {return colTypeString_;}
int get_colSize () const {return colSize_;}
RWCString get_colStringedValue () const {return colStringedValue_;}
short get_colValueIndicator () const {return colValueIndicator_;}
RWCString gstr_colDescription () const;
};
//===============================
RWBoolean operator==(const OraTableColumn& inst1_i, const
OraTableColumn& inst2_i);
ostream& operator<< (ostream& ostr_io, const OraTableColumn& inst_i);
//===============================
//###################################################################
//################# class OraDatabase ###############################
//###################################################################
//=======================================
const int MAX_SELECT_ITEMS = 55;
const int FETCH_SIZE = 5;
const int MAX_ITEM_VALUE_SIZE = 450;
const int MAX_ITEM_NAME_SIZE = 45;
const int MAX_TABLE_NAME_SIZE = 35;
//=======================================
//=======================================
class OraDatabase
{
private :
static int singletonCount_s;
static OraDatabase* pInstance_s;
RWBoolean connectionStatus_;
//------------------------------
static int sqlda_count_s;
//------------------------------
//------------------------------
RWBoolean init_sqlda (
SQLDA*& ptr_sqlda_descriptors_io,
int max_items_i,
int fetch_size_i,
int max_name_size_i,
int max_value_size_i
) const;
RWBoolean free_sqlda (SQLDA*& ptr_sqlda_descriptors_io) const;
//------------------------------
public :
// Constructor-0
OraDatabase ();
// Destructor
virtual ~OraDatabase ();
static OraDatabase* getPtrInstance();
static RWBoolean isInstanciated () { return (!(pInstance_s == NULL));
}
static RWBoolean connectToDatabase_S (
const RWCString& username_i,
const RWCString& password_i
);
void foo ();
RWBoolean connectToDatabase (
const RWCString& username_i,
const RWCString& password_i
);
static RWBoolean disconnectFromDatabase_S ();
RWBoolean disconnectFromDatabase ();
RWBoolean isConnected () const {return connectionStatus_;}
void commitWork (const RWCString& msg_i) const;
RWBoolean tableExists (const RWCString& tableName_i) const;
RWBoolean tableThomasExists (const RWCString& tableName_i) const;
RWBoolean tableSpecificProperty (
const RWCString& tableName_i,
const RWCString& propertyName_i,
RWCString& propertyValue_o,
short& propertyIndicator_o
) const;
int getTotalRows (
const RWCString& tableName_i,
const RWCString& whereString_i = RWCString ()
) const;
RWTValSortedVector<RWCString> getAllTablesNames (const RWCString&
containsSubString_i = RWCString ()) const;
RWCString gstr_AllTablesNames (const RWCString& containsSubString_i
= RWCString ()) const;
RWCString gstr_TableContent (const RWCString& tableName_i) const;
RWCString gstr_TablesContent (
const RWTValSortedVector<RWCString>& vectTablesNames_i =
RWTValSortedVector<RWCString> ()
) const;
RWTValOrderedVector<OraTableColumn> getTableColunmsDescription (
const RWCString& tableName_i,
const RWCString& colName_i = RWCString ()
) const;
RWTValOrderedVector<RWCString> getTableColunmsNames (
const RWCString& tableName_i
) const;
RWCString gstr_TableColunmsNames (
const RWCString& tableName_i
) const;
RWBoolean tableContainsColunm (
const RWCString& tableName_i,
const RWCString& colName_i
) const;
RWTValOrderedVector<RWCString> checkingColumnsNamesValidity (
const RWCString& tableName_i,
const RWTValOrderedVector<RWCString>& checkedColNames_i
) const;
RWCString gstr_InvalidColumnsNames (
const RWCString& tableName_i,
const RWTValOrderedVector<RWCString>& checkedColNames_i
) const;
RWCString gstr_InvalidColumnsNames (
const RWCString& tableName_i,
const RWTValOrderedVector<OraTableColumn>& checkedCol_i
) const;
RWBoolean createTable (
const RWCString& tableName_i,
const RWTValOrderedVector<OraTableColumn>& tableColumns_i
);
RWBoolean dropTable (
const RWCString& tableName_i
);
//------------------------------------------------
RWBoolean insertRow (
const RWCString& tableName_i,
const RWTValOrderedVector<OraTableColumn>& col_i
);
//------------------------------------------------
RWBoolean updateRow (
const RWCString& tableName_i,
const RWTValOrderedVector<OraTableColumn>& colUpdate_i,
const RWCString& whereString_i = RWCString ()
);
RWBoolean updateRow (
const RWCString& tableName_i,
const RWTValOrderedVector<OraTableColumn>& colUpdate_i,
const RWTValOrderedVector<OraTableColumn>& colWhereAnd_i,
const RWTValOrderedVector<OraTableColumn>& colWhereOr_i =
RWTValOrderedVector<OraTableColumn> ()
);
RWBoolean updateRow (
const RWCString& tableName_i,
const RWTValOrderedVector<OraTableColumn>& colUpdate_i,
const OraTableColumn& colWhereEq_i
);
//------------------------------------------------
RWBoolean deleteRow (
const RWCString& tableName_i,
const RWCString& whereString_i
);
RWBoolean deleteRow (
const RWCString& tableName_i,
const RWTValOrderedVector<OraTableColumn>& colWhereAnd_i,
const RWTValOrderedVector<OraTableColumn>& colWhereOr_i =
RWTValOrderedVector<OraTableColumn> ()
);
//------------------------------------------------
RWBoolean selectRow (
const RWCString& tableName_i,
const RWTValOrderedVector<RWCString>& colSelectName_i, // if Empty
-> select all columns
RWTValOrderedVector<RWTValOrderedVector<OraTableColumn> >&
selectedRows_o,
const RWCString& whereString_i = RWCString ()
) const;
RWBoolean selectRow (
const RWCString& tableName_i,
const RWTValOrderedVector<RWCString>& colSelectName_i,
RWTValOrderedVector<RWTValOrderedVector<OraTableColumn> >&
selectedRows_o,
const RWTValOrderedVector<OraTableColumn>& colWhereAnd_i,
const RWTValOrderedVector<OraTableColumn>& colWhereOr_i =
RWTValOrderedVector<OraTableColumn> ()
) const;
//------------------------------------------------
static void test_001_existing_table (
const RWCString& username_i,
const RWCString& password_i,
int argc,
char** argv
);
static void test_002_all_tables (
const RWCString& username_i,
const RWCString& password_i,
int argc,
char** argv
);
static void test_003_create_table (
const RWCString& username_i,
const RWCString& password_i,
int argc,
char** argv
);
};
//###################################################################
//===================================================================
//###################################################################
#endif
//###################################################################
//# END OF FILE
//###################################################################
------------------- Pro*C/C++C++ code : END -------------
=== File #1 of 2 : oraw.h ===============================
===========================
Alex Vinokur
mailto:ale...@bigfoot.com
mailto:ale...@dr.com
http://up.to/alexvn
http://go.to/alexv_math
===========================
/////////////////////////
Posting #2 of 2
/////////////////////////
====================================================
Oracle8
Oracle Pro*C/C++ Precompiler, Release 8.0
Sun WorkShop Compiler C++ 4.2
RogueWave Tools.h++ 7.0
SunOS 5.6
====================================================
====================================================
============== List Of Program Files ===============
The algorithm contains the following files :
1. oraw.h classes
2. oraw.pc functions, methods
====================================================
---> #################################### <---
---> This posting contains file 'oraw.pc' <---
---> #################################### <---
#########################################################
=== File #2 of 2 : oraw.pc ==============================
------------------- Pro*C/C++ code : BEGIN --------------
// ==============================================================
//
// Copyright (c) 2000 by Alex Vinokur. This work and all works
// derived from it may be copied and modified without any
// restrictions other than that a copy of this copyright notice
// must be included in any copy of this work or any derived work.
//
// ==============================================================
static char id[] = "@(#)Author ## "__FILE__" ::: Alex Vinokur";
// ##############################################################
// =========================
// C++Wrapper Around Oracle
// =========================
//
// FILE : oraw.pc
//
// AUTHOR : Alex Vinokur
//
// DESCRIPTION :
// Functions :
// - sql_error_print
// - sql_error_action
// - sql_bug
// Methods :
// - OraDatabase methods
// - OraTableColumn methods
//
// DATE VERSION
// ---- -------
// Feb-10-2000 Version 1.0
//
// ##############################################################
#include "oraw.h"
// EXEC SQL INCLUDE oraw.h;
// ==========================
// ###################################################################
// ###################################################################
EXEC SQL BEGIN DECLARE SECTION;
const int HOST_chars_max_size_ORA_CNS = 2001;
EXEC SQL END DECLARE SECTION;
// ###################################################################
// ###################################################################
typedef char asci_str [HOST_chars_max_size_ORA_CNS];
// ###################################################################
// ###################################################################
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL TYPE asci_str IS STRING(HOST_chars_max_size_ORA_CNS) REFERENCE;
EXEC SQL END DECLARE SECTION;
// ###################################################################
// ###################################################################
const RWCString QUOTE_CNS ("\"");
// ###################################################################
// =========================================
#define PRINT_VALUE(col_no, col_value, col_indicator) \
cout << "" \
<< " \t" \
<< "col [" \
<< col_no \
<< "] : " \
<< "value = <" \
<< col_value \
<< ">" \
<< ", " \
<< "indicator = <" \
<< col_indicator \
<< ">" \
<< endl
// =========================================
void sql_error_print (
const RWCString& msg_i,
const RWCString& location_i,
const RWCString& conclusion_i
)
{
EXEC SQL WHENEVER SQLERROR CONTINUE;
cout << endl;
cout << "######## ORA ERROR : BEGIN ########";
cout << endl;
cout << msg_i
<< location_i
<< " : "
<< conclusion_i
<< "; sqlca.sqlcode = "
<< sqlca.sqlcode
<< endl;
cout << ""
// << sqlca.sqlerrm.sqlerrml
// << " ---> "
<< sqlca.sqlerrm.sqlerrmc
<< endl;
cout << ""
<< "in "
// << oraca.orastxt.orastxtl
// << " ---> "
<< oraca.orastxt.orastxtc
<< "..."
<< endl;
cout << ""
<< "on line "
<< oraca.oraslnr
<< " "
// << oraca.orasfnm.orasfnml
// << " ---> "
<< "of "
<< oraca.orasfnm.orasfnmc
<< endl;
cout << endl;
cout << "######## ORA ERROR : END ##########";
cout << endl;
cout << endl;
EXEC SQL WHENEVER SQLERROR CONTINUE;
// EXEC SQL ROLLBACK RELEASE;
} // void sql_error_print ()
// =========================================
void sql_error_action (
const RWCString& msg_i,
const RWCString& location_i
)
{
EXEC SQL WHENEVER SQLERROR CONTINUE;
sql_error_print (msg_i, location_i, "Cannot Do It");
EXEC SQL WHENEVER SQLERROR CONTINUE;
// EXEC SQL ROLLBACK WORK RELEASE;
ASSERTION (0);
} // void sql_error_action ()
// =========================================
void sql_bug ()
{
EXEC SQL WHENEVER SQLERROR CONTINUE;
ASSERTION (0);
} // void sql_bug ()
// ###################################################################
// ################# static #########################################
int OraDatabase::singletonCount_s (0);
int OraDatabase::sqlda_count_s (0);
OraDatabase* OraDatabase::pInstance_s (NULL);
long long OraTableColumn::createdInstances_s (0);
long long OraTableColumn::destroyedInstances_s (0);
static const int DELTA_INSTANCES_NUMBER_TO_PRINT_CNS = 10000;
// ###################################################################
// ################# class OraTableColumn ############################
// ###################################################################
// ###################################################################
RWBoolean operator==(const OraTableColumn& inst1_i, const OraTableColumn&
inst2_i)
{
EXEC SQL WHENEVER SQLERROR CONTINUE;
// --------------------------------
if (inst1_i.colName_ != inst2_i.colName_) return FALSE;
if (inst1_i.colTypeEnum_ != inst2_i.colTypeEnum_) return FALSE;
if (inst1_i.colSize_ != inst2_i.colSize_) return FALSE;
// ----------------------------------
return TRUE;
} // RWBoolean operator== (const OraTableColumn& inst2_i)
// ###################################################################
ostream& operator<< (ostream& ostr_io, const OraTableColumn& inst_i)
{
EXEC SQL WHENEVER SQLERROR CONTINUE;
ostr_io << inst_i.gstr_colDescription ();
return ostr_io;
}
// ###################################################################
// Constructor-0
OraTableColumn::OraTableColumn()
{
const RWCString funcName = "Constructor-0 OraTableColumn::OraTableColumn";
colValueIndicator_ = -999;
// ------------------
createdInstances_s++;
doStatistics ();
// ------------------
EXEC SQL WHENEVER SQLERROR CONTINUE;
}
// ###################################################################
// Constructor-1
OraTableColumn::OraTableColumn(
const RWCString& colName_i,
OracleTypeEnum colTypeEnum_i,
int colSize_i
)
{
const RWCString funcName = "Constructor-1 OraTableColumn::OraTableColumn";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// ------------------
createdInstances_s++;
doStatistics ();
// ------------------
colName_ = colName_i;
colTypeEnum_ = colTypeEnum_i;
colTypeString_ = RWCString (); // TBD
colSize_ = colSize_i;
colValueIndicator_ = -998;
// -----------------------
switch (colTypeEnum_)
{
case NUMBER_OracleType :
ASSERTION (colSize_ == 0);
break;
case VARCHAR2_OracleType :
ASSERTION (colSize_ > 0);
break;
default :
ASSERTION (0);
break;
}
} // OraTableColumn::OraTableColum Constructor-1
// ###################################################################
// Constructor-2
OraTableColumn::OraTableColumn(
const RWCString& colName_i,
const RWCString& colTypeString_i,
int colSize_i
)
{
const RWCString funcName = "Constructor-2 OraTableColumn::OraTableColumn";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// ------------------
createdInstances_s++;
doStatistics ();
// ------------------
colName_ = colName_i;
colTypeEnum_ = UNDEF_OracleTypeEnum; // TBD
colTypeString_ = colTypeString_i;
colSize_ = colSize_i;
colValueIndicator_ = -997;
ASSERTION (colSize_ > 0);
} // OraTableColumn::OraTableColum Constructor-2
// ###################################################################
// Constructor-3
OraTableColumn::OraTableColumn(
const RWCString& colName_i,
const RWCString& colStringedValue_i
)
{
const RWCString funcName = "Constructor-3 OraTableColumn::OraTableColumn";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// ------------------
createdInstances_s++;
doStatistics ();
// ------------------
colName_ = colName_i;
colTypeEnum_ = UNDEF_OracleTypeEnum; // TBD
colTypeString_ = "###";
colSize_ = -1;
colStringedValue_ = colStringedValue_i;
colValueIndicator_ = -996;
ASSERTION (colSize_ < 0);
// ASSERTION (!(colStringedValue_.isNull ()));
} // OraTableColumn::OraTableColum Constructor-2
// ###################################################################
OraTableColumn::~OraTableColumn()
{
const RWCString funcName = "Destructor OraTableColumn::~OraTableColumn";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// ------------------
destroyedInstances_s++;
doStatistics ();
// ------------------
}
// ###################################################################
void OraTableColumn::doStatistics() const
{
#ifdef TRACK_STATISTICS
// ##############################
const char funcName [] = "OraTableColumn::doStatistics";
const long long aliveInstances = createdInstances_s - destroyedInstances_s;
// -----------------------------------
if ((aliveInstances%DELTA_INSTANCES_NUMBER_TO_PRINT_CNS) == 0)
{
if (aliveInstances > 0)
{
INFO_MSG_DBM ("OraTableColumn STATISTICS : CREATED = "
<< createdInstances_s
<< ", DESTROYED = "
<< destroyedInstances_s
<< ", ALIVE = "
<< aliveInstances
);
}
}
// -----------------------------------
// ##############################
#endif
} // void OraTableColumn::doStatistics() const
// ###################################################################
void OraTableColumn::foo()
{
const RWCString funcName = "OraTableColumn::foo";
EXEC SQL WHENEVER SQLERROR CONTINUE;
}
// ###################################################################
RWCString OraTableColumn::gstr_colDescription() const
{
const RWCString funcName = "OraTableColumn::gstr_colDescription";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWCString ret_stringValue;
ret_stringValue = "Column -> { "
+ get_colName ()
+ ", enumType = "
+ to_rwstring (get_colTypeEnum ())
+ ", OraType = "
+ get_colTypeString ()
+ ", ColOraSize = "
+ to_rwstring (get_colSize ())
+ ", ColIndicator = "
+ to_rwstring (get_colValueIndicator ())
+ ", Value = <"
+ get_colStringedValue ()
+ "> }";
// ====================
return ret_stringValue;
// ====================
} // OraTableColumn::gstr_colDescription()
// ###################################################################
// ###################################################################
// ################# class OraDatabase ###############################
// ###################################################################
// ###################################################################
OraDatabase* OraDatabase::getPtrInstance()
{
const char funcName [] = "OraDatabase::getPtrInstance";
EXEC SQL WHENEVER SQLERROR CONTINUE;
if (pInstance_s == NULL)
{
ERROR_MSG_DBA ("OraDatabase Instance doesn't exist");
}
// ASSERTION (!(pInstance_s == NULL));
// ASSERTION (pInstance_s);
return pInstance_s;
} // OraDatabase* OraDatabase::getPtrInstance()
// ###################################################################
// Constructor-0
OraDatabase::OraDatabase()
{
const RWCString funcName = "Constructor OraDatabase::OraDatabase";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// =============================
singletonCount_s++;
ASSERTION (singletonCount_s == 1);
// =============================
ASSERTION (!connectionStatus_);
connectionStatus_ = FALSE;
pInstance_s = this;
}
// ###################################################################
// Destructor
OraDatabase::~OraDatabase()
{
const RWCString funcName = "Destructor OraDatabase::~OraDatabase";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// =============================
singletonCount_s--;
ASSERTION (singletonCount_s == 0);
ASSERTION (!connectionStatus_);
pInstance_s = NULL;
// =============================
} // OraDatabase::~OraDatabase()
// ###################################################################
void OraDatabase::foo()
{
const RWCString funcName = "OraDatabase::foo";
EXEC SQL WHENEVER SQLERROR CONTINUE;
}
// ###################################################################
RWBoolean OraDatabase::connectToDatabase(
const RWCString& username_i,
const RWCString& password_i
)
{
const RWCString funcName = "OraDatabase::connectToDatabase";
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL BEGIN DECLARE SECTION;
const char *host_username = ((const char*)username_i);
const char *host_password = ((const char*)password_i);
EXEC SQL END DECLARE SECTION;
// ======================================
EXEC SQL WHENEVER SQLERROR GOTO case_error;
oraca.orastxtf = ORASTFERR;
// ======================================
RWCString tmp_string;
tmp_string = " to ORACLE as user <"
+ username_i
+ ">, password <"
+ password_i
+ ">";
// ---------------------------------------
EXEC SQL CONNECT :host_username IDENTIFIED BY :host_password;
INFO_AFTER_ORACLE_ACTION ("Connected" << tmp_string);
connectionStatus_ = TRUE;
return TRUE;
// ---------------------------------------
case_error :
connectionStatus_ = FALSE;
sql_ERROR_PRINT ("EXEC SQL CONNECT", "Cannot Do It");
FATAL_AFTER_ORACLE_ACTION ("Unable to connect" << tmp_string);
return FALSE;
} // RWBoolean OraDatabase::connectToDatabase(
// ###################################################################
// static
RWBoolean OraDatabase::connectToDatabase_S(
const RWCString& username_i,
const RWCString& password_i
)
{
const RWCString funcName = "OraDatabase::connectToDatabase_S";
EXEC SQL WHENEVER SQLERROR CONTINUE;
ASSERTION (!(getPtrInstance() == NULL));
RWBoolean ret_boolValue = (!(getPtrInstance() == NULL));
ASSERTION (ret_boolValue);
if (ret_boolValue)
{
ASSERTION (!(pInstance_s == NULL));
ASSERTION (!(getPtrInstance() == NULL));
// -------------------------------
ret_boolValue = getPtrInstance()->connectToDatabase (username_i,
password_i);
// -------------------------------
// ======================
if (ret_boolValue)
{
SCREEN_MSG (" ===> Connected to Oracle as user <"
<< username_i
<< ">, password <"
<< password_i
<< ">"
);
INFO_MSG_DBA ("Connected to Oracle as user <"
<< username_i
<< ">, password <"
<< password_i
<< ">"
);
}
else
{
SCREEN_MSG (" ===> Cannot connect to Oracle as user <"
<< username_i
<< ">, password <"
<< password_i
<< ">"
);
INFO_MSG_DBA ("Cannot connect to Oracle as user <"
<< username_i
<< ">, password <"
<< password_i
<< ">"
);
}
// ======================
ASSERTION (ret_boolValue == pInstance_s->connectionStatus_);
ASSERTION (ret_boolValue == getPtrInstance()->connectionStatus_);
// ======================
}
else
{
ASSERTION (0);
}
return ret_boolValue;
} // RWBoolean OraDatabase::connectToDatabase_S(
// ###################################################################
RWBoolean OraDatabase::disconnectFromDatabase()
{
const RWCString funcName = "OraDatabase::disconnectFromDatabase";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// ======================================
EXEC SQL WHENEVER SQLERROR GOTO case_error;
// ======================================
EXEC SQL COMMIT WORK RELEASE;
INFO_AFTER_ORACLE_ACTION ("Disconected from ORACLE");
connectionStatus_ = FALSE;
return TRUE;
case_error :
sql_ERROR_PRINT ("EXEC SQL COMMIT WORL RELEASE", "Cannot Do It");
FATAL_AFTER_ORACLE_ACTION ("Unable to disconnected from ORACLE");
return FALSE;
} // RWBoolean OraDatabase::disconnectFromDatabase()
// ###################################################################
RWBoolean OraDatabase::disconnectFromDatabase_S()
{
const RWCString funcName = "OraDatabase::disconnectFromDatabase_S";
EXEC SQL WHENEVER SQLERROR CONTINUE;
ASSERTION (!(getPtrInstance() == NULL));
RWBoolean ret_boolValue = (!(getPtrInstance() == NULL));
ASSERTION (ret_boolValue);
if (ret_boolValue)
{
ASSERTION (!(pInstance_s == NULL));
ASSERTION (!(getPtrInstance() == NULL));
// -------------------------------
ret_boolValue = getPtrInstance()->disconnectFromDatabase ();
// -------------------------------
// -------------------------------
// ======================
if (ret_boolValue)
{
SCREEN_MSG (" ===> Disonnected from Oracle");
INFO_MSG_DBA ("Disonnected from Oracle");
}
else
{
SCREEN_MSG (" ===> Cannot disonnected from Oracle as user");
INFO_MSG_DBA ("Cannot disonnected from Oracle as user");
}
// ==========================
ASSERTION (pInstance_s->connectionStatus_ == FALSE);
ASSERTION (getPtrInstance()->connectionStatus_ == FALSE);
// ==========================
}
else
{
ASSERTION (0);
}
return ret_boolValue;
} // RWBoolean OraDatabase::disconnectFromDatabase_S()
// ###################################################################
void OraDatabase::commitWork(const RWCString& msg_i) const
{
const RWCString funcName = "OraDatabase::commitWork";
// EXEC SQL COMMIT WORK RELEASE;
EXEC SQL COMMIT;
INFO_MSG_DBA ("Current COMMIT executed : " << msg_i);
} // void OraDatabase::commitWork()
// ###################################################################
RWBoolean OraDatabase::tableExists(const RWCString& tableName_i) const
{
const RWCString funcName = "OraDatabase::tableExists";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWBoolean ret_boolValue = FALSE;
RWCString tmp_str;
// ====================================
ASSERTION (!(tableName_i.isNull ()));
// ====================================
tmp_str = "SELECT TABLE_NAME FROM "
+ USER_tables_ORA_CNS
+ " WHERE TABLE_NAME='"
+ tableName_i
+ "'";
EXEC SQL BEGIN DECLARE SECTION;
const char *host_command_line = ((const char*)tmp_str);
asci_str host_chars;
short host_ind;
EXEC SQL END DECLARE SECTION;
// ===========================
EXEC SQL WHENEVER SQLERROR GOTO case_PREPARE_error;
INFO_BEFORE_ORACLE_ACTION (host_command_line);
EXEC SQL PREPARE the_exec__in__tableExists FROM :host_command_line;
INFO_AFTER_ORACLE_ACTION (host_command_line);
ASSERTION (sqlca.sqlcode == 0);
// ===========================
EXEC SQL WHENEVER SQLERROR GOTO case_DECLARE_error;
EXEC SQL DECLARE the_cursor_tableExists CURSOR FOR
the_exec__in__tableExists;
ASSERTION (sqlca.sqlcode == 0);
// ===========================
EXEC SQL WHENEVER SQLERROR GOTO case_OPEN_error;
EXEC SQL OPEN the_cursor_tableExists;
ASSERTION (sqlca.sqlcode == 0);
// =============================================
// =============================================
int count;
for(count = 0; ;count++)
{
EXEC SQL WHENEVER SQLERROR DO sql_ERROR_ACTION ("FETCH
the_cursor_tableExists");
EXEC SQL FETCH the_cursor_tableExists INTO :host_chars INDICATOR
:host_ind;
INFO_AFTER_ORACLE_ACTION (host_command_line);
// ======================================
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (count == 0);
// Empty
break;
case NO_DATA_FOUND__1403 :
ASSERTION ((count == 0) | (count == 1));
// Empty
break;
default :
sql_ERROR_PRINT ("in" + funcName, "ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// =======================================
// =======================================
if (sqlca.sqlcode == NO_DATA_FOUND__1403)
{
break;
}
ASSERTION (sqlca.sqlcode == NO_ERRORS__0);
ASSERTION (host_ind == 0);
// =======================================
ret_boolValue = TRUE;
// ===========================================
tmp_str = "select ["
+ to_rwstring (count)
+ "] : \t"
+ RWCString ("sqlca.sqlcode = <")
+ to_rwstring (sqlca.sqlcode)
+ ">; selected value = <"
+ host_chars
+ ">";
INFO_AFTER_ORACLE_ACTION (tmp_str);
// ===========================================
} // for(int i = 1; ;i++)
ASSERTION ((count == 0) | (count == 1));
EXEC SQL WHENEVER SQLERROR GOTO case_CLOSE_error;
EXEC SQL CLOSE the_cursor_tableExists;
ASSERTION (sqlca.sqlcode == 0);
// ============
return ret_boolValue;
// ============
// #################################
// =================================
case_PREPARE_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("PREPARE the_exec__in__tableExists");
sql_ERROR_PRINT ("in" + funcName, "PREPARE the_exec__in__tableExists :
ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
return FALSE;
// -----------
// =================================
case_DECLARE_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("DECLARE the_cursor_tableExists");
sql_ERROR_PRINT ("in" + funcName, "DECLARE the_cursor_tableExists :
ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
return FALSE;
// -----------
// =================================
case_OPEN_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("OPEN the_cursor_tableExists");
sql_ERROR_PRINT ("in" + funcName, "OPEN the_cursor_tableExists : ILLEGAL
sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
return FALSE;
// -----------
// =================================
case_CLOSE_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("CLOSE the_cursor_tableExists");
sql_ERROR_PRINT ("in" + funcName, "CLOSE the_cursor_tableExists :
ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
return FALSE;
// -----------
} // RWBoolean OraDatabase::tableExists(const RWCString&
// ###################################################################
RWBoolean OraDatabase::tableThomasExists(const RWCString& tableName_i) const
{
const RWCString funcName = "OraDatabase::tableThomasExists";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWBoolean ret_boolValue = FALSE;
RWCString tmp_str;
// ====================================
ASSERTION (!(tableName_i.isNull ()));
// ====================================
tmp_str = "SELECT * FROM ";
tmp_str += QUOTE_CNS;
tmp_str += tableName_i;
tmp_str += QUOTE_CNS;
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL BEGIN DECLARE SECTION;
const char *host_command_line = ((const char*)tmp_str);
EXEC SQL END DECLARE SECTION;
EXEC SQL PREPARE S FROM :host_command_line;
INFO_AFTER_ORACLE_ACTION (host_command_line);
// ======================================
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
case TABLE_OR_VIEW_DOES_NOT_EXIST__942 :
// Empty
break;
default :
sql_ERROR_PRINT ("in" + funcName, "ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// =======================================
ret_boolValue = ((sqlca.sqlcode == 0) ? TRUE : FALSE);
EXEC SQL WHENEVER SQLERROR DO sql_ERROR_ACTION ("EXEC SQL PREPARE S FROM
:host_command_line");
// ===========================
return ret_boolValue;
// ============
} // RWBoolean OraDatabase::tableThomasExists(const RWCString&
// ###################################################################
RWBoolean OraDatabase::tableSpecificProperty(
const RWCString& tableName_i,
const RWCString& propertyName_i,
RWCString& propertyValue_o,
short& propertyIndicator_o
) const
{
const RWCString funcName = "OraDatabase::tableSpecificProperty";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWBoolean ret_boolValue = FALSE;
RWCString tmp_str;
const RWCString CANNOT_GET_VALUE_CNS = "CANNOT GET VALUE";
// ====================================
ASSERTION (!(tableName_i.isNull ()));
// ====================================
tmp_str = "SELECT "
+ propertyName_i
+ " FROM "
+ USER_tables_ORA_CNS
+ " WHERE TABLE_NAME='"
+ tableName_i
+ "'";
EXEC SQL BEGIN DECLARE SECTION;
const char *host_command_line = ((const char*)tmp_str);
asci_str host_chars;
short host_ind;
EXEC SQL END DECLARE SECTION;
// ===========================
EXEC SQL WHENEVER SQLERROR GOTO case_PREPARE_error;
INFO_BEFORE_ORACLE_ACTION (host_command_line);
EXEC SQL PREPARE the_exec__in__tableSpecificProperty FROM
:host_command_line;
INFO_AFTER_ORACLE_ACTION (host_command_line);
ASSERTION (sqlca.sqlcode == 0);
// ===========================
EXEC SQL WHENEVER SQLERROR GOTO case_DECLARE_error;
EXEC SQL DECLARE the_cursor_tableSpecificProperty CURSOR FOR
the_exec__in__tableSpecificProperty;
ASSERTION (sqlca.sqlcode == 0);
// ===========================
EXEC SQL WHENEVER SQLERROR GOTO case_OPEN_error;
EXEC SQL OPEN the_cursor_tableSpecificProperty;
ASSERTION (sqlca.sqlcode == 0);
// =============================================
// =============================================
int count;
for(count = 0; ;count++)
{
EXEC SQL WHENEVER SQLERROR DO sql_ERROR_ACTION ("FETCH
the_cursor_tableSpecificProperty");
EXEC SQL FETCH the_cursor_tableSpecificProperty INTO :host_chars INDICATOR
:host_ind;
INFO_AFTER_ORACLE_ACTION (host_command_line);
// ======================================
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (count == 0);
// Empty
break;
case NO_DATA_FOUND__1403 :
ASSERTION ((count == 0) | (count == 1));
// Empty
break;
default :
sql_ERROR_PRINT ("in" + funcName, "ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// =======================================
// =======================================
if (sqlca.sqlcode == NO_DATA_FOUND__1403)
{
break;
}
// ==============================
tmp_str = "select ["
+ to_rwstring (count)
+ "] : \t"
+ RWCString ("sqlca.sqlcode = <")
+ to_rwstring (sqlca.sqlcode)
+ ">; selected value = <"
+ host_chars
+ ">";
INFO_AFTER_ORACLE_ACTION (tmp_str);
// =======================================
ASSERTION (sqlca.sqlcode == NO_ERRORS__0);
// =======================================
// ASSERTION (host_ind == 0);
ASSERTION (((host_ind == 0) && (!RWCString (host_chars).isNull ())) ||
((host_ind == -1) & (RWCString (host_chars).isNull ())));
propertyValue_o = host_chars;
propertyIndicator_o = host_ind;
ret_boolValue = TRUE;
// ===========================================
// ===========================================
} // for(int i = 1; ;i++)
// ASSERTION ((count == 0) | (count == 1));
ASSERTION (count == 1);
EXEC SQL WHENEVER SQLERROR GOTO case_CLOSE_error;
EXEC SQL CLOSE the_cursor_tableSpecificProperty;
ASSERTION (sqlca.sqlcode == 0);
// ============
return ret_boolValue;
// ============
// #################################
// =================================
case_PREPARE_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("PREPARE the_exec__in__tableSpecificProperty");
sql_ERROR_PRINT ("in" + funcName, "PREPARE
the_exec__in__tableSpecificProperty : ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
propertyValue_o = CANNOT_GET_VALUE_CNS;
propertyIndicator_o = -2; // Never mind
return FALSE;
// -----------
// =================================
case_DECLARE_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("DECLARE the_cursor_tableSpecificProperty");
sql_ERROR_PRINT ("in" + funcName, "DECLARE
the_cursor_tableSpecificProperty : ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
propertyValue_o = CANNOT_GET_VALUE_CNS;
propertyIndicator_o = -2; // Never mind
return FALSE;
// -----------
// =================================
case_OPEN_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("OPEN the_cursor_tableSpecificProperty");
sql_ERROR_PRINT ("in" + funcName, "OPEN the_cursor_tableSpecificProperty
: ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
propertyValue_o = CANNOT_GET_VALUE_CNS;
propertyIndicator_o = -2; // Never mind
return FALSE;
// -----------
// =================================
case_CLOSE_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("CLOSE the_cursor_tableSpecificProperty");
sql_ERROR_PRINT ("in" + funcName, "CLOSE
the_cursor_tableSpecificProperty : ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
propertyValue_o = CANNOT_GET_VALUE_CNS;
propertyIndicator_o = -2; // Never mind
return FALSE;
// -----------
} // RWCString OraDatabase::tableSpecificProperty(const RWCString&
// ###################################################################
int OraDatabase::getTotalRows(const RWCString& tableName_i, const RWCString&
whereString_i) const
{
const RWCString funcName = "OraDatabase::getTotalRows";
int ret_intValue = -1;
// ---------------------------------------
// MUST BE UPDATED with using count (*)
// ---------------------------------------
RWTValOrderedVector<RWTValOrderedVector<OraTableColumn> > vect_select;
RWBoolean cur_boolValue = selectRow (
tableName_i,
RWTValOrderedVector<RWCString> (),
vect_select,
whereString_i
);
if (cur_boolValue)
{
ret_intValue = vect_select.entries ();
}
else
{
ASSERTION (0);
}
// ---------------------------------------
ASSERTION (ret_intValue >= 0);
return ret_intValue;
} // int OraDatabase::getTotalRows(const RWCString&
// ###################################################################
RWTValSortedVector<RWCString> OraDatabase::getAllTablesNames(const
RWCString& containsSubString_i) const
{
const RWCString funcName = "OraDatabase::getAllTablesNames";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWTValSortedVector<RWCString> ret_vectorValue;
RWCString tmp_str;
RWCString tmp2_str;
tmp_str = "SELECT TABLE_NAME FROM "
+ USER_tables_ORA_CNS;
EXEC SQL BEGIN DECLARE SECTION;
const char *host_command_line = ((const char*)tmp_str);
asci_str host_chars;
short host_ind;
EXEC SQL END DECLARE SECTION;
// ===========================
EXEC SQL WHENEVER SQLERROR GOTO case_PREPARE_error;
INFO_BEFORE_ORACLE_ACTION (host_command_line);
EXEC SQL PREPARE the_exec__in__getAllTablesNames FROM :host_command_line;
INFO_AFTER_ORACLE_ACTION (host_command_line);
ASSERTION (sqlca.sqlcode == 0);
// ===========================
EXEC SQL WHENEVER SQLERROR GOTO case_DECLARE_error;
EXEC SQL DECLARE the_cursor_getAllTablesNames CURSOR FOR
the_exec__in__getAllTablesNames;
ASSERTION (sqlca.sqlcode == 0);
// ===========================
EXEC SQL WHENEVER SQLERROR GOTO case_OPEN_error;
EXEC SQL OPEN the_cursor_getAllTablesNames;
ASSERTION (sqlca.sqlcode == 0);
// =============================================
int count;
for(count = 0; ;count++)
{
EXEC SQL WHENEVER SQLERROR DO sql_ERROR_ACTION ("FETCH
the_cursor_getAllTablesNames");
EXEC SQL FETCH the_cursor_getAllTablesNames INTO :host_chars INDICATOR
:host_ind;
INFO_AFTER_ORACLE_ACTION (host_command_line);
// ======================================
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
case NO_DATA_FOUND__1403 :
// Empty
break;
default :
sql_ERROR_PRINT ("in" + funcName, "ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// =======================================
// =======================================
if (sqlca.sqlcode == NO_DATA_FOUND__1403)
{
break;
}
ASSERTION (sqlca.sqlcode == NO_ERRORS__0);
ASSERTION (host_ind == 0);
// =======================================
if (!(RWCString (host_chars).index (containsSubString_i) == RW_NPOS))
{
ret_vectorValue.insert (host_chars);;
}
// ===========================================
tmp_str = "select ["
+ to_rwstring (count)
+ "] : \t"
+ RWCString ("sqlca.sqlcode = <")
+ to_rwstring (sqlca.sqlcode)
+ ">; selected value = <"
+ host_chars
+ ">";
INFO_AFTER_ORACLE_ACTION (tmp_str);
// ===========================================
} // for(count = 0; ;count++)
EXEC SQL WHENEVER SQLERROR GOTO case_CLOSE_error;
EXEC SQL CLOSE the_cursor_getAllTablesNames;
ASSERTION (sqlca.sqlcode == 0);
// ============
return ret_vectorValue;
// ============
// #################################
// =================================
case_PREPARE_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("PREPARE the_exec__in__getAllTablesNames");
sql_ERROR_PRINT ("in" + funcName, "PREPARE
the_exec__in__getAllTablesNames : ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
return RWTValSortedVector<RWCString> ();
// -----------
// =================================
case_DECLARE_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("DECLARE the_cursor_getAllTablesNames");
sql_ERROR_PRINT ("in" + funcName, "DECLARE the_cursor_getAllTablesNames
: ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
return RWTValSortedVector<RWCString> ();
// -----------
// =================================
case_OPEN_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("OPEN the_cursor_getAllTablesNames");
sql_ERROR_PRINT ("in" + funcName, "OPEN the_cursor_getAllTablesNames :
ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
return RWTValSortedVector<RWCString> ();
// -----------
// =================================
case_CLOSE_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("CLOSE the_cursor_getAllTablesNames");
sql_ERROR_PRINT ("in" + funcName, "CLOSE the_cursor_getAllTablesNames :
ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
return RWTValSortedVector<RWCString> ();
// -----------
} // RWTValSortedVector<RWCString> OraDatabase::getAllTablesName
// ###################################################################
RWCString OraDatabase::gstr_AllTablesNames(const RWCString&
containsSubString_i) const
{
const RWCString funcName = "OraDatabase::gstr_AllTablesNames";
RWCString ret_stringValue;
RWTValSortedVector<RWCString> vect_names = getAllTablesNames
(containsSubString_i);
if (vect_names.isEmpty ())
{
ret_stringValue += "Database doesn't contain any table";
if (!containsSubString_i.isNull ())
{
ret_stringValue += " name of which contains <";
ret_stringValue += containsSubString_i;
ret_stringValue += ">";
}
}
else
{
ret_stringValue += "Here are names of tables containing in Database : ";
for (int the_index = 0; the_index < vect_names.entries (); the_index++)
{
ret_stringValue += vect_names [the_index];
if (the_index < (vect_names.entries () - 1))
{
ret_stringValue += ", ";
}
}
}
// ---------------------
return ret_stringValue;
// ---------------------
} // RWCString OraDatabase::gstr_AllTablesNames()
// ###################################################################
RWCString OraDatabase::gstr_TableContent (
const RWCString& tableName_i
) const
{
const RWCString funcName = "OraDatabase::gstr_TableContent";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWCString ret_stringValue;
const RWCString shiftik_CNS = " ";
const int setWidth_CNS = 45;
int start_len;
int end_len;
// ====================================
ASSERTION (!(tableName_i.isNull ()));
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
// ====================================
RWTValOrderedVector<RWTValOrderedVector<OraTableColumn> > vectSelectedRows;
RWTValOrderedVector<RWCString> vectColNames = getTableColunmsNames (tabl
eName_i);
ASSERTION (vectColNames.entries () >= 1);
ret_stringValue += "\n";
ret_stringValue += "============ Table : ";
ret_stringValue += tableName_i;
ret_stringValue += " (BEGIN) ";
ret_stringValue += " ============";
if (!selectRow(tableName_i, vectColNames, vectSelectedRows))
{
ASSERTION (0);
}
else
{
for (int rowNo = 0; rowNo < vectSelectedRows.entries (); rowNo++)
{
ret_stringValue += "\n";
ret_stringValue += "--------------------------------------";
ret_stringValue += "\n";
ret_stringValue += "Row#";
ret_stringValue += to_rwstring (rowNo + 1);
ret_stringValue += " [ Table : ";
ret_stringValue += tableName_i;
ret_stringValue += " ]";
for (int colNo = 0; colNo < vectSelectedRows [rowNo].entries (); colNo++)
{
ret_stringValue += "\n";
ret_stringValue += shiftik_CNS;
ret_stringValue += " \t";
start_len = ret_stringValue.length ();
ret_stringValue += "[ ";
ret_stringValue += vectSelectedRows [rowNo] [colNo].get_colName ();
ret_stringValue += ", ";
ret_stringValue += vectSelectedRows [rowNo] [colNo].get_colTypeString
();
ret_stringValue += ", ";
ret_stringValue += to_rwstring (vectSelectedRows [rowNo]
[colNo].get_colSize ());
ret_stringValue += " ]";
end_len = ret_stringValue.length ();
if ((end_len - start_len + 1) <= setWidth_CNS)
{
ret_stringValue += RWCString (' ', (setWidth_CNS - (end_len - start_len
+ 1)));
}
ret_stringValue += " \t";
ret_stringValue += "<";
ret_stringValue += vectSelectedRows [rowNo] [colNo].get_colStringedValue
();
ret_stringValue += ">";
}
} // for (int rowNo = 0
// -------------------------------
if (vectSelectedRows.isEmpty ())
{
ret_stringValue += "\n";
ret_stringValue += " [ Table : ";
ret_stringValue += tableName_i;
ret_stringValue += " ]";
ret_stringValue += " -> EMPTY";
}
}
ret_stringValue += "\n";
ret_stringValue += "============ Table : ";
ret_stringValue += tableName_i;
ret_stringValue += " (END) ";
ret_stringValue += " ==============";
ret_stringValue += "\n";
// ============
return ret_stringValue;
// ============
} // RWTValOrderedVector<OraTableColumn> OraDatabase::gstr_TableContent
// ###################################################################
RWCString OraDatabase::gstr_TablesContent (
const RWTValSortedVector<RWCString>& vectTablesNames_i
) const
{
const RWCString funcName = "OraDatabase::gstr_TablesContent";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWCString ret_stringValue;
RWTValSortedVector<RWCString> tablesNames;
if (vectTablesNames_i.isEmpty ())
{
tablesNames = getAllTablesNames ();
}
else
{
tablesNames = vectTablesNames_i;
}
ASSERTION (!tablesNames.isEmpty ());
int the_index;
for (the_index = 0; the_index < tablesNames.entries (); the_index++)
{
ret_stringValue += gstr_TableContent (tablesNames [the_index]);
}
// ============
return ret_stringValue;
// ============
} // RWTValOrderedVector<OraTableColumn> OraDatabase::gstr_TablesContent
// ###################################################################
RWTValOrderedVector<OraTableColumn> OraDatabase::getTableColunmsDescription
(
const RWCString& tableName_i,
const RWCString& colName_i
) const
{
const RWCString funcName = "OraDatabase::getTableColunmsDescription";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWTValOrderedVector<OraTableColumn> ret_vectorValue;
RWCString tmp_str;
// ====================================
ASSERTION (!(tableName_i.isNull ()));
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
// ====================================
tmp_str = "SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH FROM "
+ USER_tab_columns_ORA_CNS
+ " WHERE "
+ "("
+ " TABLE_NAME="
+ "'"
+ tableName_i
+ "'";
if (!colName_i.isNull ())
{
tmp_str += " AND COLUMN_NAME=";
tmp_str += "'";
tmp_str += colName_i;
tmp_str += "'";
}
tmp_str += ")";
EXEC SQL BEGIN DECLARE SECTION;
const char *host_command_line = ((const char*)tmp_str);
asci_str host_chars_column_name;
short host_ind_column_name;
asci_str host_chars_column_value_type;
short host_ind_column_value_type;
int host_int_column_value_size;
short host_ind_column_value_size;
EXEC SQL END DECLARE SECTION;
// ===========================
EXEC SQL WHENEVER SQLERROR GOTO case_PREPARE_error;
INFO_BEFORE_ORACLE_ACTION (host_command_line);
EXEC SQL PREPARE the_exec__in__getTableColunmsDescription FROM
:host_command_line;
INFO_AFTER_ORACLE_ACTION (host_command_line);
ASSERTION (sqlca.sqlcode == 0);
// ===========================
EXEC SQL WHENEVER SQLERROR GOTO case_DECLARE_error;
EXEC SQL DECLARE the_cursor_getTableColunmsDescription CURSOR FOR
the_exec__in__getTableColunmsDescription;
ASSERTION (sqlca.sqlcode == 0);
// ===========================
EXEC SQL WHENEVER SQLERROR GOTO case_OPEN_error;
EXEC SQL OPEN the_cursor_getTableColunmsDescription;
ASSERTION (sqlca.sqlcode == 0);
// =============================================
int count;
for(count = 0; ;count++)
{
EXEC SQL WHENEVER SQLERROR DO sql_ERROR_ACTION ("FETCH
the_cursor_getTableColunmsDescription");
INFO_BEFORE_ORACLE_ACTION (host_command_line);
EXEC SQL FETCH the_cursor_getTableColunmsDescription INTO
:host_chars_column_name INDICATOR :host_ind_column_name,
:host_chars_column_value_type INDICATOR :host_ind_column_value_type,
:host_int_column_value_size INDICATOR :host_ind_column_value_size;
INFO_AFTER_ORACLE_ACTION (host_command_line);
// ======================================
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
// Empty
break;
case NO_DATA_FOUND__1403 :
// Empty
break;
case INVALID_COLUMN_NAME__904 :
sql_ERROR_PRINT ("in" + funcName, "INVALID Column Name");
ASSERTION (0);
break; // unused
default :
sql_ERROR_PRINT ("in" + funcName, "ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
break; // unused
} // switch (sqlca.sqlcode)
// =======================================
// =======================================
if (sqlca.sqlcode == NO_DATA_FOUND__1403)
{
break; // from for(count = 0; ;count++)
}
ASSERTION (sqlca.sqlcode == NO_ERRORS__0);
ASSERTION (host_ind_column_name == 0);
ASSERTION (host_ind_column_value_type == 0);
ASSERTION (host_ind_column_value_size == 0);
// =======================================
ret_vectorValue.insert (OraTableColumn (
host_chars_column_name,
host_chars_column_value_type,
host_int_column_value_size
));
// ===========================================
tmp_str = "select ["
+ to_rwstring (count)
+ "] : \t"
+ RWCString ("sqlca.sqlcode = <")
+ to_rwstring (sqlca.sqlcode)
+ ">; selected value = "
+ "<"
+ host_chars_column_name
+ ", "
+ to_rwstring (host_ind_column_name)
+ ">"
+ " "
+ "<"
+ host_chars_column_value_type
+ ", "
+ to_rwstring (host_ind_column_value_type)
+ ">";
INFO_AFTER_ORACLE_ACTION (tmp_str);
// ===========================================
} // for(count = 0; ;count++)
// =============================
// KKK ??? ASSERTION ((count == 0) | (count == 1));
EXEC SQL WHENEVER SQLERROR GOTO case_CLOSE_error;
EXEC SQL CLOSE the_cursor_getTableColunmsDescription;
ASSERTION (sqlca.sqlcode == 0);
// =============================
// ============
return ret_vectorValue;
// ============
// #################################
// =================================
case_PREPARE_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("PREPARE the_exec__in__getTableColunmsDescription");
sql_ERROR_PRINT ("in" + funcName, "PREPARE
the_exec__in__getTableColunmsDescription : ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
return RWTValOrderedVector<OraTableColumn> ();
// -----------
// =================================
case_DECLARE_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("DECLARE the_cursor_getTableColunmsDescription");
sql_ERROR_PRINT ("in" + funcName, "DECLARE
the_cursor_getTableColunmsDescription : ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
return RWTValOrderedVector<OraTableColumn> ();
// -----------
// =================================
case_OPEN_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("OPEN the_cursor_getTableColunmsDescription");
sql_ERROR_PRINT ("in" + funcName, "OPEN
the_cursor_getTableColunmsDescription : ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
return RWTValOrderedVector<OraTableColumn> ();
// -----------
// =================================
case_CLOSE_error :
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
default :
sql_ERROR_ACTION ("CLOSE the_cursor_getTableColunmsDescription");
sql_ERROR_PRINT ("in" + funcName, "CLOSE
the_cursor_getTableColunmsDescription : ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// -----------
return RWTValOrderedVector<OraTableColumn> ();
// -----------
} // RWTValOrderedVector<OraTableColumn>
OraDatabase::getTableColunmsDescription
// ###################################################################
RWBoolean OraDatabase::tableContainsColunm (
const RWCString& tableName_i,
const RWCString& colName_i
) const
{
const RWCString funcName = "OraDatabase::tableContainsColunm";
ASSERTION (!tableName_i.isNull ());
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
RWBoolean ret_boolValue = (!(getTableColunmsDescription (tableName_i,
colName_i).isEmpty ()));
return ret_boolValue;
} // RWTValOrderedVector<OraTableColumn> OraDatabase::tableContainsColunm
// ###################################################################
RWTValOrderedVector<RWCString> OraDatabase::checkingColumnsNamesValidity (
const RWCString& tableName_i,
const RWTValOrderedVector<RWCString>& checkedColNames_i
) const
{
const RWCString funcName = "OraDatabase::checkingColumnsNamesValidity";
ASSERTION (!tableName_i.isNull ());
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
RWTValOrderedVector<RWCString> ret_vectValue;
for (int the_index = 0; the_index < checkedColNames_i.entries ();
the_index++)
{
if (!(tableContainsColunm (tableName_i, checkedColNames_i [the_index])))
{
ret_vectValue.append (checkedColNames_i [the_index]);
}
} // for (i = 0; i < checkedColNames_i
return ret_vectValue;
} // RWTValOrderedVector<RWCString>
OraDatabase::checkingColumnsNamesValidity
// ###################################################################
RWCString OraDatabase::gstr_InvalidColumnsNames (
const RWCString& tableName_i,
const RWTValOrderedVector<RWCString>& checkedColNames_i
) const
{
const RWCString funcName = "OraDatabase::gstr_InvalidColumnsNames";
ASSERTION (!tableName_i.isNull ());
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
RWCString ret_stringValue;
RWTValOrderedVector<RWCString> vect_InvalidColumnsNames =
checkingColumnsNamesValidity (
tableName_i,
checkedColNames_i
);
for (int the_index = 0; the_index < vect_InvalidColumnsNames.entries ();
the_index++)
{
ret_stringValue += vect_InvalidColumnsNames [the_index];
if (the_index < (vect_InvalidColumnsNames.entries () - 1))
{
ret_stringValue += ", ";
}
} //
return ret_stringValue;
} // RWCString OraDatabase::gstr_InvalidColumnsNames
// ###################################################################
RWCString OraDatabase::gstr_InvalidColumnsNames (
const RWCString& tableName_i,
const RWTValOrderedVector<OraTableColumn>& checkedCol_i
) const
{
const RWCString funcName = "OraDatabase::gstr_InvalidColumnsNames";
ASSERTION (!tableName_i.isNull ());
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
RWCString ret_stringValue;
RWTValOrderedVector<RWCString> vect_checkedColumnsNames;
for (int the_index = 0; the_index < checkedCol_i.entries (); the_index++)
{
vect_checkedColumnsNames.append (checkedCol_i [the_index].get_colName ());
} //
ret_stringValue = gstr_InvalidColumnsNames (tableName_i,
vect_checkedColumnsNames);
return ret_stringValue;
} // RWCString OraDatabase::gstr_InvalidColumnsNames
// ###################################################################
RWTValOrderedVector<RWCString> OraDatabase::getTableColunmsNames (
const RWCString& tableName_i
) const
{
const RWCString funcName = "OraDatabase::getTableColunmsNames";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWTValOrderedVector<RWCString> ret_vectorValue;
RWCString tmp_str;
// ====================================
ASSERTION (!(tableName_i.isNull ()));
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
// ====================================
RWTValOrderedVector<OraTableColumn> vectColumnsDescription =
getTableColunmsDescription (tableName_i);
ASSERTION (vectColumnsDescription.entries () >= 1);
for (int colNo = 0; colNo < vectColumnsDescription.entries (); colNo++)
{
ret_vectorValue.append (vectColumnsDescription [colNo].get_colName ());
}
ASSERTION (vectColumnsDescription.entries () == ret_vectorValue.entries
());
// ============
return ret_vectorValue;
// ============
} // RWTValOrderedVector<RWCString> OraDatabase::getTableColunmsNames
// ###################################################################
RWCString OraDatabase::gstr_TableColunmsNames (
const RWCString& tableName_i
) const
{
const RWCString funcName = "OraDatabase::gstr_TableColunmsNames";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWCString ret_stringValue;
// ====================================
ASSERTION (!(tableName_i.isNull ()));
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
// ====================================
RWTValOrderedVector<RWCString> vectColumnsNames = getTableColunmsNames
(tableName_i);
ASSERTION (vectColumnsNames.entries () >= 1);
for (int colNo = 0; colNo < vectColumnsNames.entries (); colNo++)
{
ret_stringValue += vectColumnsNames [colNo];
if (colNo < (vectColumnsNames.entries () - 1))
{
ret_stringValue += ", ";
}
}
// ============
return ret_stringValue;
// ============
} // RWCString OraDatabase::gstr_TableColunmsNames
// ###################################
RWBoolean OraDatabase::createTable (
const RWCString& tableName_i,
const RWTValOrderedVector<OraTableColumn>& tableColumns_i
)
{
const RWCString funcName = "OraDatabase::createTable";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWCString tmp_str;
// ====================================
ASSERTION (!(tableName_i.isNull ()));
ASSERTION (!(tableColumns_i.isEmpty ()));
// ====================================
ASSERTION (!tableExists (tableName_i));
ASSERTION (!tableThomasExists (tableName_i));
ASSERTION (tableColumns_i.entries () > 0);
// =========================================
EXEC SQL WHENEVER SQLERROR GOTO case_create_error;
// -----------------------------------------
// -----------------------------------------
tmp_str = "CREATE TABLE ";
tmp_str += QUOTE_CNS;
tmp_str += tableName_i;
tmp_str += QUOTE_CNS;
tmp_str += " (";
for (int i = 0; i < tableColumns_i.entries (); i++)
{
tmp_str += QUOTE_CNS;
tmp_str += tableColumns_i [i].get_colName ();
tmp_str += QUOTE_CNS;
tmp_str += " ";
switch (tableColumns_i [i].get_colTypeEnum ())
{
case NUMBER_OracleType :
tmp_str += "NUMBER";
ASSERTION (tableColumns_i [i].get_colSize () == 0);
break;
case VARCHAR2_OracleType :
tmp_str += "VARCHAR2";
tmp_str += "(";
ASSERTION (tableColumns_i [i].get_colSize () > 0);
tmp_str += to_rwstring (tableColumns_i [i].get_colSize ());
tmp_str += ")";
break;
default :
ASSERTION (0);
}
if (i < (tableColumns_i.entries () - 1))
{
tmp_str += ", ";
}
}
tmp_str += ")";
// -----------------------------------------
// -----------------------------------------
EXEC SQL BEGIN DECLARE SECTION;
const char* host_command_line = ((const char*)tmp_str);
EXEC SQL END DECLARE SECTION;
// -----------------------------------------
// -----------------------------------------
INFO_BEFORE_ORACLE_ACTION (host_command_line);
EXEC SQL EXECUTE IMMEDIATE : host_command_line;
// -----------------------------------------
// ---------
return TRUE;
// ---------
// =====================================
case_create_error:
EXEC SQL WHENEVER SQLERROR DO sql_bug();
sql_ERROR_PRINT (host_command_line, "Cannot Do It");
FATAL_AFTER_ORACLE_ACTION ("Unable to create Table <"
<< tableName_i
<< ">"
);
return FALSE;
// =====================================
} // RWBoolean OraDatabase::createTable
// ###################################
RWBoolean OraDatabase::dropTable (
const RWCString& tableName_i
)
{
const RWCString funcName = "OraDatabase::dropTable";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWCString tmp_str;
// ====================================
ASSERTION (!(tableName_i.isNull ()));
// ====================================
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
// =========================================
EXEC SQL WHENEVER SQLERROR GOTO case_drop_error;
// -----------------------------------------
// -----------------------------------------
tmp_str = "DROP TABLE ";
tmp_str += QUOTE_CNS;
tmp_str += tableName_i;
tmp_str += QUOTE_CNS;
// -----------------------------------------
// -----------------------------------------
EXEC SQL BEGIN DECLARE SECTION;
const char* host_command_line = ((const char*)tmp_str);
EXEC SQL END DECLARE SECTION;
// -----------------------------------------
// -----------------------------------------
INFO_BEFORE_ORACLE_ACTION (host_command_line);
EXEC SQL EXECUTE IMMEDIATE : host_command_line;
// -----------------------------------------
// ---------
return TRUE;
// ---------
// =====================================
case_drop_error:
EXEC SQL WHENEVER SQLERROR DO sql_bug();
sql_ERROR_PRINT (host_command_line, "Cannot Do It");
FATAL_AFTER_ORACLE_ACTION ("Unable to drop Table <"
<< tableName_i
<< ">"
);
return FALSE;
// =====================================
} // RWBoolean OraDatabase::dropTable
// ###################################
RWBoolean OraDatabase::insertRow (
const RWCString& tableName_i,
const RWTValOrderedVector<OraTableColumn>& col_i
)
{
const RWCString funcName = "OraDatabase::insertRow";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// ====================================
ASSERTION (!(tableName_i.isNull ()));
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
ASSERTION (!(col_i.isEmpty ()));
// ====================================
RWCString tmp_str;
RWCString tmp_repeating_key_values;
int i;
// -----------------------------------------
tmp_str = "INSERT INTO ";
tmp_str += QUOTE_CNS;
tmp_str += tableName_i;
tmp_str += QUOTE_CNS;
// -----------------------------------------
tmp_str += " (";
for (i = 0; i < col_i.entries (); i++)
{
tmp_str += QUOTE_CNS;
tmp_str += col_i [i].get_colName ();
tmp_str += QUOTE_CNS;
if (i < (col_i.entries () - 1))
{
tmp_str += ", ";
}
}
tmp_str += ")";
// -----------------------------------------
tmp_str += " VALUES";
// -----------------------------------------
tmp_str += " (";
for (i = 0; i < col_i.entries (); i++)
{
tmp_str += "'";
tmp_str += col_i [i].get_colStringedValue ();
tmp_str += "'";
if (i < (col_i.entries () - 1))
{
tmp_str += ", ";
}
}
tmp_str += ")";
// -----------------------------------------
// -----------------------------------------
EXEC SQL BEGIN DECLARE SECTION;
const char* host_command_line = ((const char*)tmp_str);
EXEC SQL END DECLARE SECTION;
// -----------------------------------------
// =========================================
EXEC SQL WHENEVER SQLERROR GOTO case_insert_error;
// -----------------------------------------
// -----------------------------------------
INFO_BEFORE_ORACLE_ACTION (host_command_line);
EXEC SQL EXECUTE IMMEDIATE : host_command_line;
INFO_AFTER_ORACLE_ACTION (host_command_line);
// -----------------------------------------
// ---------
return TRUE;
// ---------
// =====================================
case_insert_error:
EXEC SQL WHENEVER SQLERROR DO sql_bug();
sql_ERROR_PRINT (host_command_line, "Cannot Do It");
// ======================================
tmp_repeating_key_values = RWCString ();
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
case NO_DATA_FOUND__1403 :
ASSERTION (0);
break;
case UNIQUE_CONSTRAINT_VIOLATED__1 :
// -----------------------------------------
tmp_repeating_key_values += " (";
for (i = 0; i < col_i.entries (); i++)
{
tmp_repeating_key_values += col_i [i].get_colName ();
if (i < (col_i.entries () - 1))
{
tmp_repeating_key_values += ", ";
}
}
tmp_repeating_key_values += ")";
// -----------------------------------------
tmp_repeating_key_values += " VALUES";
// -----------------------------------------
tmp_repeating_key_values += " (";
for (i = 0; i < col_i.entries (); i++)
{
tmp_repeating_key_values += "'";
tmp_repeating_key_values += col_i [i].get_colStringedValue ();
tmp_repeating_key_values += "'";
if (i < (col_i.entries () - 1))
{
tmp_repeating_key_values += ", ";
}
}
tmp_repeating_key_values += ")";
break;
default :
// Empty
break;
} // switch (sqlca.sqlcode)
// =======================================
if (!tmp_repeating_key_values.isNull ())
{
tmp_repeating_key_values = " ---> Most likely, row with such kyes < "
+ tmp_repeating_key_values
+ " > already exists in Database";
}
FATAL_AFTER_ORACLE_ACTION ("Unable to insert Row in Table <"
<< tableName_i
<< "> "
<< tmp_repeating_key_values
);
return FALSE;
// =====================================
} // RWBoolean OraDatabase::insertRow (
// ###################################
RWBoolean OraDatabase::updateRow (
const RWCString& tableName_i,
const RWTValOrderedVector<OraTableColumn>& colUpdate_i,
const RWCString& whereString_i
)
{
const RWCString funcName = "OraDatabase::updateRow";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// ====================================
ASSERTION (!(tableName_i.isNull ()));
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
ASSERTION (!(colUpdate_i.isEmpty ()));
// ====================================
RWCString tmp_str;
RWCString tmp_missing_columns_str;
int i;
EXEC SQL BEGIN DECLARE SECTION;
short ind_all;
EXEC SQL END DECLARE SECTION;
// -----------------------------------------
tmp_str = "UPDATE ";
tmp_str += QUOTE_CNS;
tmp_str += tableName_i;
tmp_str += QUOTE_CNS;
// ============================================
tmp_str += " SET ";
// -----------------------------------------
for (i = 0; i < colUpdate_i.entries (); i++)
{
tmp_str += QUOTE_CNS;
tmp_str += colUpdate_i [i].get_colName ();
tmp_str += QUOTE_CNS;
tmp_str += " = ";
tmp_str += "'";
tmp_str += colUpdate_i [i].get_colStringedValue ();
tmp_str += "'";
if (i < (colUpdate_i.entries () - 1))
{
tmp_str += ", ";
}
}
// -----------------------------------------
// ============================================
if (!whereString_i.isNull ())
{
// -----------------------------------------
tmp_str += " WHERE ";
tmp_str += "(";
tmp_str += whereString_i;
tmp_str += ")";
// -----------------------------------------
} // if (!whereString_i.isEmpty ())
// -----------------------------------------
// -----------------------------------------
EXEC SQL BEGIN DECLARE SECTION;
const char* host_command_line = ((const char*)tmp_str);
EXEC SQL END DECLARE SECTION;
// -----------------------------------------
// =========================================
EXEC SQL WHENEVER SQLERROR GOTO case_update_error;
// -----------------------------------------
// -----------------------------------------
INFO_BEFORE_ORACLE_ACTION (host_command_line);
EXEC SQL EXECUTE IMMEDIATE :host_command_line;
// -----------------------------------------
// ---------
return TRUE;
// ---------
// =====================================
case_update_error:
EXEC SQL WHENEVER SQLERROR DO sql_bug();
sql_ERROR_PRINT (host_command_line, "Cannot Do It");
// ======================================
tmp_missing_columns_str = RWCString ();
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
case NO_DATA_FOUND__1403 :
ASSERTION (0);
break;
case INVALID_COLUMN_NAME__904 :
tmp_missing_columns_str = gstr_InvalidColumnsNames (
tableName_i,
colUpdate_i
);
break;
default :
// Empty
break;
} // switch (sqlca.sqlcode)
// =======================================
if (!tmp_missing_columns_str.isNull ())
{
tmp_missing_columns_str = " ---> Here are updated columns names missing
in this table : "
+ tmp_missing_columns_str;
}
tmp_missing_columns_str += "; ####> Here are valid columns names of the
table <"
+ tableName_i
+ "> : "
+ gstr_TableColunmsNames (tableName_i);
FATAL_AFTER_ORACLE_ACTION ("Unable to update Row in Table <"
<< tableName_i
<< "> "
<< tmp_missing_columns_str
);
return FALSE;
// =====================================
} // RWBoolean OraDatabase::updateRow (
// ###################################
RWBoolean OraDatabase::updateRow (
const RWCString& tableName_i,
const RWTValOrderedVector<OraTableColumn>& colUpdate_i,
const RWTValOrderedVector<OraTableColumn>& colWhereAnd_i,
const RWTValOrderedVector<OraTableColumn>& colWhereOr_i
)
{
const RWCString funcName = "OraDatabase::updateRow";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// ====================================
ASSERTION (!(tableName_i.isNull ()));
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
ASSERTION (!(colUpdate_i.isEmpty ()));
// ====================================
int i;
RWCString where_str;
// -----------------------------------------
// ============================================
if (!colWhereAnd_i.isEmpty ())
{
// -----------------------------------------
where_str += "(";
for (i = 0; i < colWhereAnd_i.entries (); i++)
{
where_str += QUOTE_CNS;
where_str += colWhereAnd_i [i].get_colName ();
where_str += QUOTE_CNS;
where_str += " = ";
where_str += "'";
where_str += colWhereAnd_i [i].get_colStringedValue ();
where_str += "'";
if (i < (colWhereAnd_i.entries () - 1))
{
where_str += " AND ";
}
}
where_str += ")";
} // if (!colWhereAnd_i.isEmpty ())
// =====================================
if ((!colWhereOr_i.isEmpty ()) && (!colWhereOr_i.isEmpty ()))
{
where_str += " AND ";
}
// =====================================
if (!colWhereOr_i.isEmpty ())
{
// -----------------------------------------
where_str += "(";
for (i = 0; i < colWhereOr_i.entries (); i++)
{
where_str += QUOTE_CNS;
where_str += colWhereOr_i [i].get_colName ();
where_str += QUOTE_CNS;
where_str += " = ";
where_str += "'";
where_str += colWhereOr_i [i].get_colStringedValue ();
where_str += "'";
if (i < (colWhereOr_i.entries () - 1))
{
where_str += " OR ";
}
}
where_str += ")";
} // if (!colWhereOr_i.isEmpty ())
// =====================================
// =======================
// ======================================
RWCString tmp_missing_columns_str;
tmp_missing_columns_str += gstr_InvalidColumnsNames (
tableName_i,
colWhereAnd_i
);
tmp_missing_columns_str += gstr_InvalidColumnsNames (
tableName_i,
colWhereOr_i
);
// =======================================
if (!tmp_missing_columns_str.isNull ())
{
tmp_missing_columns_str = " ---> Here are where-columns names missing in
this table : "
+ tmp_missing_columns_str;
}
tmp_missing_columns_str += "; ####> Here are valid columns names of the
table <"
+ tableName_i
+ "> : "
+ gstr_TableColunmsNames (tableName_i);
// =======================
RWBoolean ret_boolValue = updateRow (
tableName_i,
colUpdate_i,
where_str
);
if (!ret_boolValue)
{
if (!tmp_missing_columns_str.isNull ())
{
FATAL_MSG_DBA ("Table <"
<< tableName_i
<< "> "
<< tmp_missing_columns_str
);
}
}
return ret_boolValue;
// =======================
} // RWBoolean OraDatabase::updateRow (
// ###################################
RWBoolean OraDatabase::updateRow (
const RWCString& tableName_i,
const RWTValOrderedVector<OraTableColumn>& colUpdate_i,
const OraTableColumn& colWhereEq_i
)
{
const RWCString funcName = "OraDatabase::updateRow";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// =======================
ASSERTION (!(tableName_i.isNull ()));
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
// =======================
RWTValOrderedVector<OraTableColumn> colWhereEq;
colWhereEq.append (colWhereEq_i);
// =======================
// ======================================
RWCString tmp_missing_columns_str;
tmp_missing_columns_str += gstr_InvalidColumnsNames (
tableName_i,
colWhereEq
);
// =======================================
if (!tmp_missing_columns_str.isNull ())
{
tmp_missing_columns_str = " ---> Here are where-columns names missing in
this table : "
+ tmp_missing_columns_str;
}
tmp_missing_columns_str += "; ####> Here are valid columns names of the
table <"
+ tableName_i
+ "> : "
+ gstr_TableColunmsNames (tableName_i);
// =======================
RWBoolean ret_boolValue = updateRow (
tableName_i,
colUpdate_i,
colWhereEq
);
if (!ret_boolValue)
{
if (!tmp_missing_columns_str.isNull ())
{
FATAL_MSG_DBA ("Table <"
<< tableName_i
<< "> "
<< tmp_missing_columns_str
);
}
}
return ret_boolValue;
// =======================
} // RWBoolean OraDatabase::updateRow (
// ###################################
RWBoolean OraDatabase::deleteRow (
const RWCString& tableName_i,
const RWCString& whereString_i
)
{
const RWCString funcName = "OraDatabase::deleteRow";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWBoolean ret_boolValue = TRUE;
// ====================================
ASSERTION (!(tableName_i.isNull ()));
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
ASSERTION (!(whereString_i.isNull ()));
// ====================================
RWCString tmp_str;
int i;
EXEC SQL BEGIN DECLARE SECTION;
short ind_all;
EXEC SQL END DECLARE SECTION;
// -----------------------------------------
tmp_str = "DELETE FROM ";
tmp_str += QUOTE_CNS;
tmp_str += tableName_i;
tmp_str += QUOTE_CNS;
tmp_str += " WHERE ";
tmp_str += "(";
tmp_str += whereString_i;
tmp_str += ")";
// -----------------------------------------
EXEC SQL BEGIN DECLARE SECTION;
const char* host_command_line = ((const char*)tmp_str);
EXEC SQL END DECLARE SECTION;
// -----------------------------------------
// =========================================
EXEC SQL WHENEVER SQLERROR GOTO case_delete_error;
// -----------------------------------------
// -----------------------------------------
INFO_BEFORE_ORACLE_ACTION (host_command_line);
EXEC SQL EXECUTE IMMEDIATE :host_command_line;
INFO_AFTER_ORACLE_ACTION (host_command_line);
// -----------------------------------------
// ======================================
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
// Empty; ret_boolValue == TRUE;
break;
case NO_DATA_FOUND__1403 :
FATAL_AFTER_ORACLE_ACTION ("Not found Row to be deleted in Table <"
<< tableName_i
<< ">"
);
ret_boolValue = FALSE;
break;
default :
sql_ERROR_PRINT ("in" + funcName, "ILLEGAL sqlcode ERROR VALUE");
ASSERTION (0);
} // switch (sqlca.sqlcode)
// =======================================
// ---------
return ret_boolValue;
// ---------
// =====================================
case_delete_error:
EXEC SQL WHENEVER SQLERROR DO sql_bug();
sql_ERROR_PRINT (host_command_line, "Cannot Do It");
FATAL_AFTER_ORACLE_ACTION ("Unable to delete Row in Table <"
<< tableName_i
<< ">"
);
return FALSE;
// =====================================
} // RWBoolean OraDatabase::deleteRow (
// ###################################
RWBoolean OraDatabase::deleteRow (
const RWCString& tableName_i,
const RWTValOrderedVector<OraTableColumn>& colWhereAnd_i,
const RWTValOrderedVector<OraTableColumn>& colWhereOr_i
)
{
const RWCString funcName = "OraDatabase::deleteRow";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// ====================================
ASSERTION (!(tableName_i.isNull ()));
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
ASSERTION ((!(colWhereAnd_i.isEmpty ())) | (!(colWhereOr_i.isEmpty ())));
// ====================================
int i;
RWCString tmp_str;
// -----------------------------------------
// ============================================
if (!colWhereAnd_i.isEmpty ())
{
// -----------------------------------------
tmp_str += "(";
for (i = 0; i < colWhereAnd_i.entries (); i++)
{
tmp_str += QUOTE_CNS;
tmp_str += colWhereAnd_i [i].get_colName ();
tmp_str += QUOTE_CNS;
tmp_str += " = ";
tmp_str += "'";
tmp_str += colWhereAnd_i [i].get_colStringedValue ();
tmp_str += "'";
if (i < (colWhereAnd_i.entries () - 1))
{
tmp_str += " AND ";
}
}
tmp_str += ")";
} // if (!colWhereAnd_i.isEmpty ())
// =====================================
if ((!colWhereOr_i.isEmpty ()) && (!colWhereOr_i.isEmpty ()))
{
tmp_str += " AND ";
}
// =====================================
if (!colWhereOr_i.isEmpty ())
{
// -----------------------------------------
tmp_str += "(";
for (i = 0; i < colWhereOr_i.entries (); i++)
{
tmp_str += QUOTE_CNS;
tmp_str += colWhereOr_i [i].get_colName ();
tmp_str += QUOTE_CNS;
tmp_str += " = ";
tmp_str += "'";
tmp_str += colWhereOr_i [i].get_colStringedValue ();
tmp_str += "'";
if (i < (colWhereOr_i.entries () - 1))
{
tmp_str += " OR ";
}
}
tmp_str += ")";
} // if (!colWhereOr_i.isEmpty ())
// =====================================
// =====================================
// =======================
// ======================================
RWCString tmp_missing_columns_str;
tmp_missing_columns_str += gstr_InvalidColumnsNames (
tableName_i,
colWhereAnd_i
);
tmp_missing_columns_str += gstr_InvalidColumnsNames (
tableName_i,
colWhereOr_i
);
// =======================================
if (!tmp_missing_columns_str.isNull ())
{
tmp_missing_columns_str = " ---> Here are where-columns names missing in
this table : "
+ tmp_missing_columns_str;
}
tmp_missing_columns_str += "; ####> Here are valid columns names of the
table <"
+ tableName_i
+ "> : "
+ gstr_TableColunmsNames (tableName_i);
// =======================
RWBoolean ret_boolValue = deleteRow (tableName_i, tmp_str);
if (!ret_boolValue)
{
if (!tmp_missing_columns_str.isNull ())
{
FATAL_MSG_DBA ("Table <"
<< tableName_i
<< "> "
<< tmp_missing_columns_str
);
}
}
return ret_boolValue;
// =======================
} // RWBoolean OraDatabase::deleteRow (
// ###################################
RWBoolean OraDatabase::selectRow (
const RWCString& tableName_i,
const RWTValOrderedVector<RWCString>& colSelectName_i,
RWTValOrderedVector<RWTValOrderedVector<OraTableColumn> >&
selectedRows_o,
const RWCString& whereString_i
) const
{
const RWCString funcName = "OraDatabase::selectRow";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// ------------------------------------
ASSERTION (!tableName_i.isNull ());
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
// ------------------------------------
int i;
RWCString tmp_missing_columns_str;
RWTValOrderedVector<RWCString> colSelectName (colSelectName_i);
// ====================================
selectedRows_o = RWTValOrderedVector<RWTValOrderedVector<OraTableColumn> >
();
// ====================================
ASSERTION (!(tableName_i.isNull ()));
if (colSelectName.isEmpty ())
{
colSelectName = getTableColunmsNames (tableName_i);
}
ASSERTION (!(colSelectName.isEmpty ()));
ASSERTION (selectedRows_o.isEmpty ());
// ====================================
RWTValOrderedVector<OraTableColumn> colSelect;
for (i = 0; i < colSelectName.entries (); i++)
{
ASSERTION (getTableColunmsDescription (tableName_i, colSelectName
[i]).entries () >= 1);
ASSERTION (getTableColunmsDescription (tableName_i, colSelectName
[i]).entries () == 1);
colSelect.append (getTableColunmsDescription (tableName_i, colSelectName
[i]).first ());
}
RWBoolean ret_boolValue = TRUE;
RWCString tmp_str;
RWCString select_str;
RWCString tmp_additional_str;
RWCString tmp_extract_str;
int prev_size;
int total_row_in_box;
int item_index;
int fetch_index;
int row_count;
int sli; // select-list item
int row; // row in array
// ####################################
// ########## SQLDA init ##############
// ####################################
// ============================
SQLDA* ptr_sqlda_descriptors = NULL;
char c_data [MAX_SELECT_ITEMS] [FETCH_SIZE]
[MAX_ITEM_VALUE_SIZE];
short i_data [MAX_SELECT_ITEMS] [FETCH_SIZE];
for (item_index = 0; item_index < MAX_SELECT_ITEMS; item_index++)
{
for (fetch_index = 0; fetch_index < FETCH_SIZE; fetch_index++)
{
strcpy (c_data [item_index] [fetch_index], "");
i_data [item_index] [fetch_index] = -2;
}
} // for (item_index = 0; item_index < MAX_SELECT_ITEMS; item_index++)
// ============================
const int max_selected_columns = colSelect.entries ();
int max_column_name_size = 0;
int max_column_value_size = 0;
for (i = 0; i < max_selected_columns; i++)
{
max_column_name_size = MAX_VALUE (
max_column_name_size,
colSelect [i].get_colName ().length ()
);
max_column_value_size = MAX_VALUE (
max_column_value_size,
colSelect [i].get_colSize ()
);
}
if (!init_sqlda (
ptr_sqlda_descriptors,
max_selected_columns,
FETCH_SIZE,
max_column_name_size,
max_column_value_size
))
{
ret_boolValue = FALSE;
ASSERTION (0);
}
ASSERTION (!(ptr_sqlda_descriptors == NULL));
// ####################################
select_str = RWCString ();
for (i = 0; i < colSelect.entries (); i++)
{
select_str += QUOTE_CNS;
select_str += colSelect [i].get_colName ();
select_str += QUOTE_CNS;
if (i < (colSelect.entries () - 1))
{
select_str += ", ";
}
}
// ####################################
// -----------------------------------------
tmp_str = "SELECT ";
tmp_str += select_str;
tmp_str += " FROM ";
tmp_str += QUOTE_CNS;
tmp_str += tableName_i;
tmp_str += QUOTE_CNS;
// -----------------------------------------
// ============================================
if (!whereString_i.isNull ())
{
// -----------------------------------------
tmp_str += " WHERE ";
tmp_str += "(";
tmp_str += whereString_i;
tmp_str += ")";
// -----------------------------------------
} // if (!whereString_i.isEmpty ())
// =========================================
EXEC SQL BEGIN DECLARE SECTION;
int array_size = FETCH_SIZE;
const char* host_command_line = ((const char*)tmp_str);
EXEC SQL END DECLARE SECTION;
// ---------------------------
ASSERTION (sqlca.sqlcode == 0);
// ---------------------------
// =========================================
EXEC SQL WHENEVER SQLERROR GOTO case_select_error;
// -----------------------------------------
EXEC SQL PREPARE S1 FROM :host_command_line;
ASSERTION (sqlca.sqlcode == 0);
EXEC SQL DECLARE C1 CURSOR FOR S1;
ASSERTION (sqlca.sqlcode == 0);
EXEC SQL OPEN C1;
ASSERTION (sqlca.sqlcode == 0);
EXEC SQL DESCRIBE SELECT LIST FOR S1 INTO ptr_sqlda_descriptors;
ASSERTION (sqlca.sqlcode == 0);
if (ptr_sqlda_descriptors->F < 0)
{
ASSERTION (0);
}
ASSERTION (ptr_sqlda_descriptors->F > 0); // ???
ptr_sqlda_descriptors->N = ptr_sqlda_descriptors->F; // Assumed not
negative.
// -----------------
for (sli = 0; sli < ptr_sqlda_descriptors->N; sli++)
{
// Set addresses of heads of the arrays in the V element.
ptr_sqlda_descriptors->V[sli] = c_data [sli] [0];
ptr_sqlda_descriptors->I[sli] = &i_data [sli] [0];
// Convert everything to varchar on output.
ptr_sqlda_descriptors->T[sli] = 1;
// Set the maximum lengths.
ptr_sqlda_descriptors->L[sli] = MAX_ITEM_VALUE_SIZE;
}
// -----------------
for (row_count = 0; ;)
{
// Do the fetch. The loop breaks on NOT FOUND.
EXEC SQL FOR :array_size FETCH C1 USING DESCRIPTOR ptr_sqlda_descriptors;
// ########################################
// ######## EXTRACT DATA : BEGIN ##########
// ########################################
total_row_in_box = sqlca.sqlerrd[2] - row_count;
for (row = 0; row < total_row_in_box; row++)
{
// --------------------------------
ASSERTION (!colSelect.isEmpty ());
selectedRows_o.append (colSelect);
ASSERTION (!selectedRows_o.isEmpty ());
// --------------------------------
// --------------------------------
for (sli = 0; sli < ptr_sqlda_descriptors->N; sli++)
{
// --------------------------
tmp_extract_str = c_data [sli] [row];
tmp_extract_str = tmp_extract_str (0, MAX_ITEM_VALUE_SIZE);
do
{
prev_size = tmp_extract_str.length ();
// ----------------
tmp_extract_str = tmp_extract_str.strip (RWCString::both);
tmp_extract_str = tmp_extract_str.strip (RWCString::both, '\t');
// ----------------
} while (prev_size != tmp_extract_str.length ());
// --------------------------
// --------------------------
// --------------------------
selectedRows_o.last() [sli].colValueIndicator_ = i_data [sli] [row];
switch (i_data [sli] [row])
{
case 0 :
selectedRows_o.last() [sli].colStringedValue_ = tmp_extract_str;
break;
case -1 :
selectedRows_o.last() [sli].colStringedValue_ = NO_VALUE_ORA_CNS;
break;
dafault :
selectedRows_o.last() [sli].colStringedValue_ =
TRUNCATED_VALUE_ORA_CNS;
FATAL_AFTER_ORACLE_ACTION ("Selected value truncated");
ASSERTION (0);
} // switch (ptr_items_ind_ [sli][row])
} // for (sli = 0; sli < ptr_sqlda_descriptors->N; sli++)
} // for (row = 0; row < total_row_in_box; row++)
// ########################################
// ######## EXTRACT DATA : END ############
// ########################################
row_count = sqlca.sqlerrd[2];
if (sqlca.sqlcode == NO_DATA_FOUND__1403)
{
break;
}
} // for (row_count = 0; ;)
tmp_additional_str = RWCString ("SELECTION : ")
+ to_rwstring (sqlca.sqlerrd[2])
+ " rows selected\n";
INFO_AFTER_ORACLE_ACTION (tmp_additional_str);
// ####################################
// ########## SQLDA free ##############
// ####################################
EXEC SQL CLOSE C1;
ASSERTION (sqlca.sqlcode == 0);
if (!free_sqlda (ptr_sqlda_descriptors))
{
ret_boolValue = FALSE;
ASSERTION (0);
}
ASSERTION (ptr_sqlda_descriptors == NULL);
// ====================================
for (item_index = 0; item_index < MAX_SELECT_ITEMS; item_index++)
{
for (fetch_index = 0; fetch_index < FETCH_SIZE; fetch_index++)
{
strcpy (c_data [item_index] [fetch_index], "");
i_data [item_index] [fetch_index] = -3;
}
} // for (item_index = 0; item_index < MAX_SELECT_ITEMS; item_index++)
// ####################################
// -----------------------------------------
INFO_BEFORE_ORACLE_ACTION (host_command_line);
EXEC SQL EXECUTE IMMEDIATE :host_command_line;
// INFO_AFTER_ORACLE_ACTION (host_command_line);
// -----------------------------------------
// ---------
return ret_boolValue;
// ---------
// =====================================
case_select_error:
EXEC SQL WHENEVER SQLERROR DO sql_bug();
sql_ERROR_PRINT (host_command_line, "Cannot Do It");
// ======================================
tmp_missing_columns_str = RWCString ();
switch (sqlca.sqlcode)
{
case NO_ERRORS__0 :
ASSERTION (0);
break;
case NO_DATA_FOUND__1403 :
ASSERTION (0);
break;
case INVALID_COLUMN_NAME__904 :
tmp_missing_columns_str = gstr_InvalidColumnsNames (
tableName_i,
colSelect
);
break;
default :
// Empty
break;
} // switch (sqlca.sqlcode)
// =======================================
if (!tmp_missing_columns_str.isNull ())
{
tmp_missing_columns_str = " ---> Here are selected columns names missing
in this table : "
+ tmp_missing_columns_str;
}
tmp_missing_columns_str += "; ####> Here are valid columns names of the
table <"
+ tableName_i
+ "> : "
+ gstr_TableColunmsNames (tableName_i);
FATAL_AFTER_ORACLE_ACTION ("Unable to select Row in Table <"
<< tableName_i
<< "> "
<< tmp_missing_columns_str
);
return FALSE;
// =====================================
} // RWBoolean OraDatabase::selectRow (
// ###################################
RWBoolean OraDatabase::selectRow (
const RWCString& tableName_i,
const RWTValOrderedVector<RWCString>& colSelectName_i,
RWTValOrderedVector<RWTValOrderedVector<OraTableColumn> >&
selectedRows_o,
const RWTValOrderedVector<OraTableColumn>& colWhereAnd_i,
const RWTValOrderedVector<OraTableColumn>& colWhereOr_i
) const
{
const RWCString funcName = "OraDatabase::selectRow";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// ====================================
selectedRows_o = RWTValOrderedVector<RWTValOrderedVector<OraTableColumn> >
();
// ====================================
ASSERTION (!(tableName_i.isNull ()));
ASSERTION (tableExists (tableName_i));
ASSERTION (tableThomasExists (tableName_i));
ASSERTION (!(colSelectName_i.isEmpty ()));
ASSERTION (selectedRows_o.isEmpty ());
// ====================================
int i;
RWCString tmp_str;
// -----------------------------------------
// ============================================
if (!colWhereAnd_i.isEmpty ())
{
// -----------------------------------------
tmp_str += "(";
for (i = 0; i < colWhereAnd_i.entries (); i++)
{
tmp_str += QUOTE_CNS;
tmp_str += colWhereAnd_i [i].get_colName ();
tmp_str += QUOTE_CNS;
tmp_str += " = ";
tmp_str += "'";
tmp_str += colWhereAnd_i [i].get_colStringedValue ();
tmp_str += "'";
if (i < (colWhereAnd_i.entries () - 1))
{
tmp_str += " AND ";
}
}
tmp_str += ")";
} // if (!colWhereAnd_i.isEmpty ())
// =====================================
// =====================================
if (!colWhereAnd_i.isEmpty ())
{
// -----------------------------------------
tmp_str += " AND ";
tmp_str += "(";
for (i = 0; i < colWhereAnd_i.entries (); i++)
{
tmp_str += QUOTE_CNS;
tmp_str += colWhereAnd_i [i].get_colName ();
tmp_str += QUOTE_CNS;
tmp_str += " = ";
tmp_str += "'";
tmp_str += colWhereAnd_i [i].get_colStringedValue ();
tmp_str += "'";
if (i < (colWhereAnd_i.entries () - 1))
{
tmp_str += " OR ";
}
}
tmp_str += ")";
} // if (!colWhereAnd_i.isEmpty ())
// =====================================
// =======================
// ======================================
RWCString tmp_missing_columns_str;
tmp_missing_columns_str += gstr_InvalidColumnsNames (
tableName_i,
colWhereAnd_i
);
tmp_missing_columns_str += gstr_InvalidColumnsNames (
tableName_i,
colWhereOr_i
);
// =======================================
if (!tmp_missing_columns_str.isNull ())
{
tmp_missing_columns_str = " ---> Here are where-columns names missing in
this table : "
+ tmp_missing_columns_str;
}
tmp_missing_columns_str += "; ####> Here are valid columns names of the
table <"
+ tableName_i
+ "> : "
+ gstr_TableColunmsNames (tableName_i);
// =======================
RWBoolean ret_boolValue = selectRow (
tableName_i,
colSelectName_i,
selectedRows_o,
tmp_str
);
if (!ret_boolValue)
{
if (!tmp_missing_columns_str.isNull ())
{
FATAL_MSG_DBA ("Table <"
<< tableName_i
<< "> "
<< tmp_missing_columns_str
);
}
}
return ret_boolValue;
// =======================
} // RWBoolean OraDatabase::selectRow (
// ###################################
RWBoolean OraDatabase::init_sqlda (
SQLDA*& ptr_sqlda_descriptors_io,
int max_items_i,
int fetch_size_i,
int max_name_size_i,
int max_value_size_i
) const
{
const RWCString funcName = "OraDatabase::init_sqlda";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWBoolean ret_boolValue = TRUE;
RWCString tmp_str;
int item_index;
int fetch_index;
EXEC SQL WHENEVER SQLERROR DO sql_ERROR_ACTION ("init_sqlda");
// ====================================
sqlda_count_s++;
ASSERTION (sqlda_count_s == 1);
// ====================================
// #####################################
ASSERTION (max_items_i > 0);
ASSERTION (fetch_size_i > 0);
ASSERTION (max_name_size_i > 0);
ASSERTION (max_value_size_i > 0);
// #####################################
// ######### IMPORTANT ##################
if (max_items_i > MAX_SELECT_ITEMS)
{
FATAL_ASSERT ("max_items_i = " << max_items_i << ", MAX_SELECT_ITEMS = "
<< MAX_SELECT_ITEMS);
ASSERTION (0);
}
if (fetch_size_i > FETCH_SIZE)
{
FATAL_ASSERT ( "fetch_size_i = " << fetch_size_i << ", FETCH_SIZE = " <<
FETCH_SIZE);
ASSERTION (0);
}
if (max_name_size_i > MAX_ITEM_NAME_SIZE)
{
FATAL_ASSERT ( "max_name_size_i = " << max_name_size_i << ",
MAX_ITEM_NAME_SIZE = " << MAX_ITEM_NAME_SIZE);
ASSERTION (0);
}
if (max_value_size_i > (MAX_ITEM_VALUE_SIZE - 1))
{
FATAL_ASSERT ( "max_value_size_i = " << max_value_size_i << ",
MAX_ITEM_VALUE_SIZE = " << MAX_ITEM_VALUE_SIZE);
ASSERTION (0);
}
ASSERTION (max_items_i <= MAX_SELECT_ITEMS);
ASSERTION (fetch_size_i <= FETCH_SIZE);
ASSERTION (max_name_size_i <= MAX_ITEM_NAME_SIZE);
ASSERTION (max_value_size_i <= (MAX_ITEM_VALUE_SIZE - 1));
// #####################################
// ====================================
ptr_sqlda_descriptors_io = sqlald (MAX_SELECT_ITEMS, MAX_ITEM_NAME_SIZE,
0);
// ptr_sqlda_descriptors_io = sqlald (max_items_i, max_name_size_i + 1, 0);
// ptr_sqlda_descriptors_io = SQLSQLDAAlloc (SQL_SINGLE_RCTX, max_items_i,
max_name_size_i + 1, 0);
// ptr_sqlda_descriptors_io = SQLSQLDAAlloc ((void*) NULL, max_items_i,
max_name_size_i + 1, 0);
if (ptr_sqlda_descriptors_io == NULL)
{
ret_boolValue = FALSE;
}
// ====================================
// ===================
ASSERTION (!(ptr_sqlda_descriptors_io == NULL));
return ret_boolValue;
} // RWBoolean OraDatabase::init_sqlda (
// ###################################
RWBoolean OraDatabase::free_sqlda (SQLDA*& ptr_sqlda_descriptors_io) const
{
const RWCString funcName = "OraDatabase::free_sqlda";
EXEC SQL WHENEVER SQLERROR CONTINUE;
RWBoolean ret_boolValue = TRUE;
EXEC SQL WHENEVER SQLERROR DO sql_ERROR_ACTION ("free_sqlda");
// ===================
sqlda_count_s--;
ASSERTION (sqlda_count_s == 0);
// ===================
// ===============================
// ---------------------------------------------
// SQLSQLDAFree(SQL_SINGLE_RCTX, ptr_sqlda_descriptors_io);
// SQLSQLDAFree((void*)NULL, ptr_sqlda_descriptors_io);
sqlclu(ptr_sqlda_descriptors_io);
ptr_sqlda_descriptors_io = NULL;
// ---------------------------------------------
// ====================================
// ===================
return ret_boolValue;
} // RWBoolean OraDatabase::free_sqlda (
// ###################################################################
// ############ static test_... methods ##############################
// ###################################################################
// ###################################
void OraDatabase::test_001_existing_table (
const RWCString& username_i,
const RWCString& password_i,
int argc,
char** argv
)
{
const RWCString funcName = "test_001_existing_table";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// =============================
OraDatabase oracleDb;
if (!oracleDb.connectToDatabase (username_i, password_i))
{
FATAL_MSG_DBA ("Cannot connect to Oracle as user <"
<< username_i
<< ">, password <"
<< password_i
<< ">"
);
ASSERTION (0);
}
ASSERTION (oracleDb.isConnected ());
// =============================
int the_index;
RWCString tmp_str;
char tmp_chars [MAX_TABLE_NAME_SIZE];
cout << "#####################################################" << endl;
cout << "##### BEGIN : " << funcName << endl;
cout << "#####################################################" << endl;
cout << endl;
// ================================================
for (the_index = 1; the_index < argc; the_index++)
{
// ======================
if (oracleDb.tableExists (argv [the_index]))
{
cout << "===> Table <" << argv [the_index] << ">";
cout << " exists";
}
else
{
cout << "===> Table <" << argv [the_index] << ">";
cout << " doesn't exist";
}
cout << " in Database" << endl;
// ======================
}
// ================================================
for (; ; )
{
cout << endl;
cout << "\tEnter checked table name (or Return): ";
cin.getline (tmp_chars, MAX_TABLE_NAME_SIZE);
cout << endl;
tmp_str = tmp_chars;
ASSERTION (tmp_str.length () < MAX_TABLE_NAME_SIZE);
if (tmp_str.isNull ())
{
break;
}
// ======================
if (oracleDb.tableExists (tmp_str))
{
cout << "===> Table <" << tmp_str << ">";
cout << " exists";
}
else
{
cout << "===> Table <" << tmp_str << ">";
cout << " doesn't exist";
}
cout << " in Database" << endl;
// ======================
} // for (; ; )
cout << "Thank you ... " << endl;
cout << endl;
cout << "#####################################################" << endl;
cout << "##### END : " << funcName << endl;
cout << "#####################################################" << endl;
cout << endl;
// =============================
if (!oracleDb.disconnectFromDatabase ())
{
FATAL_MSG_DBA ("Cannot disconnect from Oracle");
ASSERTION (0);
}
ASSERTION (!oracleDb.isConnected ());
// =============================
} // void test_001_existing_table (
// ###################################
void OraDatabase::test_002_all_tables (
const RWCString& username_i,
const RWCString& password_i,
int argc,
char** argv
)
{
const RWCString funcName = "test_002_all_tables";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// =============================
OraDatabase oracleDb;
if (!oracleDb.connectToDatabase (username_i, password_i))
{
FATAL_MSG_DBA ("Cannot connect to Oracle as user <"
<< username_i
<< ">, password <"
<< password_i
<< ">"
);
ASSERTION (0);
}
ASSERTION (oracleDb.isConnected ());
// =============================
int the_index;
RWCString tmp_str;
cout << endl;
cout << "#####################################################" << endl;
cout << "##### BEGIN : " << funcName << endl;
cout << "#####################################################" << endl;
cout << endl;
// ================================================
RWTValSortedVector<RWCString> vect_tables = oracleDb.getAllTablesNames ();
for (the_index = 0; the_index < vect_tables.entries (); the_index++)
{
cout << oracleDb.gstr_TableContent (vect_tables [the_index]) << endl;
} // for (int the_index = 0; ...
// ================================================
cout << "Thank you ... " << endl;
cout << endl;
cout << "#####################################################" << endl;
cout << "#####################################################" << endl;
cout << "##### END : " << funcName << endl;
cout << "#####################################################" << endl;
cout << endl;
// =============================
if (!oracleDb.disconnectFromDatabase ())
{
FATAL_MSG_DBA ("Cannot disconnect from Oracle");
ASSERTION (0);
}
ASSERTION (!oracleDb.isConnected ());
// =============================
} // void test_002_all_tables (
// ###################################
void OraDatabase::test_003_create_table (
const RWCString& username_i,
const RWCString& password_i,
int argc,
char** argv
)
{
const RWCString funcName = "test_003_create_table";
EXEC SQL WHENEVER SQLERROR CONTINUE;
// =============================
OraDatabase oracleDb;
if (!oracleDb.connectToDatabase (username_i, password_i))
{
FATAL_MSG_DBA ("Cannot connect to Oracle as user <"
<< username_i
<< ">, password <"
<< password_i
<< ">"
);
ASSERTION (0);
}
ASSERTION (oracleDb.isConnected ());
// =============================
int the_index;
RWCString tmp_str;
cout << endl;
cout << "#####################################################" << endl;
cout << "##### BEGIN : " << funcName << endl;
cout << "#####################################################" << endl;
cout << endl;
// ================================================
cout << "TBD" << endl;
// ================================================
cout << "Thank you ... " << endl;
cout << endl;
cout << "#####################################################" << endl;
cout << "##### END : " << funcName << endl;
cout << "#####################################################" << endl;
cout << endl;
// =============================
if (!oracleDb.disconnectFromDatabase ())
{
FATAL_MSG_DBA ("Cannot disconnect from Oracle");
ASSERTION (0);
}
ASSERTION (!oracleDb.isConnected ());
// =============================
} // void test_003_create_table (
// ###################################################################
// ###################################################################
// # END OF FILE
// ###################################################################
------------------- Pro*C/C++C++ code : END -------------
=== File #2 of 2 : oraw.pc ==============================