summaryrefslogtreecommitdiff
path: root/src/core/xbtblmgr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/xbtblmgr.cpp')
-rwxr-xr-xsrc/core/xbtblmgr.cpp85
1 files changed, 63 insertions, 22 deletions
diff --git a/src/core/xbtblmgr.cpp b/src/core/xbtblmgr.cpp
index f154dc6..2fe6a8c 100755
--- a/src/core/xbtblmgr.cpp
+++ b/src/core/xbtblmgr.cpp
@@ -22,20 +22,19 @@ Email Contact:
namespace xb{
/*************************************************************************/
-
xbTblMgr::xbTblMgr(){
TblList = NULL;
iOpenTableCount = 0;
}
/*************************************************************************/
-
xbTblMgr::~xbTblMgr(){
xbTblList *l;
if( TblList ){
while( TblList ){
l = TblList;
TblList = TblList->pNext;
+ delete l->psFqTblName;
delete l->psTblName;
delete l->psTblAlias;
free( l );
@@ -44,47 +43,74 @@ xbTblMgr::~xbTblMgr(){
}
/*************************************************************************/
-
-xbInt16 xbTblMgr::AddTblToTblList( xbDbf *d, const xbString & sTblName ){
- return AddTblToTblList( d, sTblName, "" );
+xbInt16 xbTblMgr::AddTblToTblList( xbDbf *d, const xbString & sFqTblName ){
+ return AddTblToTblList( d, sFqTblName, "" );
}
/*************************************************************************/
+xbInt16 xbTblMgr::AddTblToTblList( xbDbf *d, const xbString & sFqTblName, const xbString & sTblAlias ) {
+
+ // Set the Fq (fully qualified name)
+ // Pull the table name from the FQ name
+ // Set the Alias to the table name if the alias name is not provided
-xbInt16 xbTblMgr::AddTblToTblList( xbDbf *d, const xbString & sTblName, const xbString & sTblAlias ) {
xbTblList *i, *s, *t;
xbInt16 iRc = 0;
xbInt16 iErrorStop = 0;
+ xbString sTblName;
xbString sAlias;
+ xbString sTemp;
+ xbString sFqTemp;
+ xbUInt32 iSlashPos;
+
+ // std::cout << "AddTblToTblList fq in = [" << sFqTblName.Str() << "] alias in =[" << sTblAlias.Str() << "]\n";
try{
- if( sTblName.Len() == 0 ){
+ if( sFqTblName.Len() == 0 ){
iErrorStop = 100;
iRc = XB_INVALID_TABLE_NAME;
throw iRc;
}
- if( sTblAlias.Len() == 0 ){
+ sTblName = sFqTblName;
+ sTblName.SwapChars( '\\', '/' );
+ iSlashPos = sTblName.GetLastPos( '/' );
+
+ // std::cout << "slashpos = " << iSlashPos << "\n";
+
+
+ if( iSlashPos > 0 ){
+ sTblName.Ltrunc( iSlashPos ); // remove the directory part from the table name
+ sFqTemp = sFqTblName;
+ } else{
+ sFqTemp.Sprintf( "%s%s", GetDataDirectory().Str(), sFqTblName.Str()); // add the dir part to the FQ name
+ }
+
+ xbUInt32 iDbfPos = sFqTemp.Pos( ".DBF" );
+ if( iDbfPos == 0 )
+ sFqTemp += ".DBF";
+ else
+ sTblName.Resize( sTblName.Len() - 3 );
+
+ if( sTblAlias.Len() == 0 )
sAlias = sTblName;
- sAlias.SwapChars( '\\', '/' );
- xbUInt32 iPos = sAlias.GetLastPos( '/' );
- if( iPos > 0 ) /* get rid of the directory part of the name */
- sAlias.Ltrunc( iPos );
- } else {
+ else
sAlias = sTblAlias;
- }
+
+ //std::cout << "fq=[" << sFqTemp.Str() << "] tblname = [" << sTblName.Str() << "] alias = [" << sAlias.Str() << "]\n";
if((i = (xbTblList *) calloc(1, sizeof(xbTblList))) == NULL){
iErrorStop = 110;
iRc = XB_NO_MEMORY;
throw iRc;
}
- i->psTblName = new xbString( sTblName );
- i->psTblAlias = new xbString( sAlias );
- i->pDbf = d;
- i->pNext = NULL;
+ i->psFqTblName = new xbString( sFqTemp );
+ i->psTblName = new xbString( sTblName );
+ i->psTblAlias = new xbString( sAlias );
+ i->pDbf = d;
+ i->pNext = NULL;
// insert new table into the list of open tables, sorted by table name
s = NULL;
@@ -97,7 +123,7 @@ xbInt16 xbTblMgr::AddTblToTblList( xbDbf *d, const xbString & sTblName, const xb
if( t && (strcmp( t->psTblAlias->Str(), sAlias.Str()) == 0 )){
iErrorStop = 120;
- delete i->psTblName;
+ delete i->psFqTblName;
delete i->psTblAlias;
free( i );
iRc = XB_DUP_TABLE_OR_ALIAS;
@@ -131,7 +157,7 @@ xbInt16 xbTblMgr::DisplayTableList() const {
else{
while( l ){
iTblCnt++;
- std::cout << iTblCnt << " Table=[" << l->psTblName->Str() << "] Alias=[" << l->psTblAlias->Str() << "]" << std::endl;
+ std::cout << iTblCnt << " FqFileName=[" << l->psFqTblName->Str() << "] TableName=[" << l->psTblName->Str() << "] Alias=[" << l->psTblAlias->Str() << "]" << std::endl;
l = l->pNext;
}
}
@@ -149,6 +175,7 @@ xbInt16 xbTblMgr::DisplayTableList() const {
xbDbf *xbTblMgr::GetDbfPtr(const xbString& sTblAlias) const {
+
xbTblList *t;
t = TblList;
xbString s;
@@ -159,14 +186,26 @@ xbDbf *xbTblMgr::GetDbfPtr(const xbString& sTblAlias) const {
s.Set( sTblAlias );
while( t ){
- if( s == t->psTblAlias->Str())
+ if( s == t->psTblAlias->Str()){
+ return t->pDbf;
+ }
+ t = t->pNext;
+ }
+
+ t = TblList;
+ while( t ){
+ std::cout << "s = [" << s.Str() << "] tbl name = [" << t->psTblName->Str() << "]\n";
+ if( s == t->psTblName->Str()){
+ std::cout << "found\n";
return t->pDbf;
+ }
t = t->pNext;
}
+
t = TblList;
while( t ){
- if( sTblAlias == t->psTblName->Str())
+ if( sTblAlias == t->psFqTblName->Str())
return t->pDbf;
t = t->pNext;
}
@@ -227,6 +266,7 @@ xbInt16 xbTblMgr::RemoveTblFromTblList( const xbString & sTblAlias ) {
else
TblList = i->pNext;
+ delete i->psFqTblName;
delete i->psTblName;
delete i->psTblAlias;
free( i );
@@ -254,6 +294,7 @@ xbInt16 xbTblMgr::RemoveTblFromTblList( xbDbf *pTbl ) {
else
TblList = i->pNext;
+ delete i->psFqTblName;
delete i->psTblName;
delete i->psTblAlias;
free( i );