summaryrefslogtreecommitdiff
path: root/src/sql/xbcrix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sql/xbcrix.cpp')
-rwxr-xr-xsrc/sql/xbcrix.cpp54
1 files changed, 33 insertions, 21 deletions
diff --git a/src/sql/xbcrix.cpp b/src/sql/xbcrix.cpp
index 6a391f7..8efdc39 100755
--- a/src/sql/xbcrix.cpp
+++ b/src/sql/xbcrix.cpp
@@ -66,6 +66,7 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){
xbString sNode;
xbBool bUnique = xbFalse;
xbDbf * dbf = NULL;
+ xbBool bTableLocked = xbFalse;
try{
@@ -113,6 +114,7 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){
xbFile f( xbase );
f.SetFileName( sIxName );
if( f.FileExists()){
+
iErrorStop = 110;
iRc = XB_FILE_EXISTS;
throw iRc;
@@ -140,12 +142,14 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){
// if not open, attempt to open it
dbf = xbase->GetDbfPtr( fDbf.GetFqFileName());
+
if( !dbf ){
if(( iRc = xbase->OpenHighestVersion( sTableName, "", &dbf )) != XB_NO_ERROR ){
iErrorStop = 120;
throw iRc;
}
}
+
if( dbf == NULL ){
iErrorStop = 130;
iRc = XB_FILE_NOT_FOUND;
@@ -153,8 +157,6 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){
}
sCmd.Ltrunc( ulPos );
- // std::cout << "cp1 ulPos = " << ulPos << " sCmd = [" << sCmd << "]\n";
-
//ulPos = sCmd.GetLastPos( ')' );
xbString sKeyExpression;
xbBool bDone = xbFalse;
@@ -181,7 +183,6 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){
}
// std::cout << "Key Expression =[" << sKeyExpression << "]\n";
-
sCmd.Ltrunc( lPos );
sCmd.Trim();
@@ -199,7 +200,6 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){
}
}
-
// std::cout << "sCmd - looking for FILTER stuff [" << sCmd << "]\n";
xbString sFilter;
if( sCmd.Len() > 6 ){
@@ -218,11 +218,11 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){
if(( iRc = dbf->LockTable( XB_LOCK )) != XB_NO_ERROR ){
iErrorStop = 140;
throw iRc;
+ } else {
+ bTableLocked = xbTrue;
}
#endif // XB_LOCKING_SUPPORT
- // std::cout << "SqlCreateIndex() - ixtype = " << sIxType << "\n";
-
xbIx *pIx;
void *vpTag;
@@ -230,14 +230,16 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){
iErrorStop = 150;
throw iRc;
}
- // std::cout << "SqlCreateIndex() - back from tag create\n";
+
#ifdef XB_NDX_SUPPORT
+ xbBool bAssociate = xbFalse;
if( sIxType == "NDX"){
sCmd.Ltrunc( ulPos );
sCmd.Trim();
if( sCmd.Len() > 0 ){
sCmd.ToUpperCase();
if( sCmd.Pos( "ASSOCIATE" )){
+ bAssociate = xbTrue;
if(( iRc = dbf->AssociateIndex( "NDX", sIxName, 0 )) != XB_NO_ERROR ){
iErrorStop = 160;
throw iRc;
@@ -245,25 +247,36 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){
}
}
}
-// if( sIxType == "NDX"){
-// if(( iRc = pIx->Reindex( &vpTag )) != XB_NO_ERROR ){
-// iErrorStop = 160;
-// throw iRc;
-// }
-// }
#endif // XB_NDX_SUPPORT
+ iRc = dbf->Reindex( 2, 1, &pIx, &vpTag );
- if(( iRc = pIx->Reindex( &vpTag )) != XB_NO_ERROR ){
- iErrorStop = 170;
+ #ifdef XB_NDX_SUPPORT
+ if( iRc != XB_NO_ERROR && sIxType == "NDX" && bAssociate ){
+ xbInt16 iRc2;
+ if(( iRc2 = dbf->AssociateIndex( "NDX", sIxName, 1 )) != XB_NO_ERROR ){
+ iErrorStop = 180;
+ throw iRc2;
+ }
+ iErrorStop = 190;
+ throw iRc;
+ }
+ #endif // XB_NDX_SUPPORT
+
+ if( iRc != XB_NO_ERROR ){
+ iErrorStop = 200;
throw iRc;
}
#ifdef XB_LOCKING_SUPPORT
- if(( iRc = dbf->LockTable( XB_UNLOCK )) != XB_NO_ERROR ){
- iErrorStop = 180;
- throw iRc;
+ if( bTableLocked ){
+ if(( iRc = dbf->LockTable( XB_UNLOCK )) != XB_NO_ERROR ){
+ iErrorStop = 210;
+ throw iRc;
+ } else {
+ bTableLocked = xbFalse;
+ }
}
#endif // XB_LOCKING_SUPPORT
@@ -273,11 +286,10 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){
sMsg.Sprintf( "xbSql::SqlCreateIndex() Exception Caught. Error Stop = [%d] rc = [%d] table = [%s]", iErrorStop, iRc, sTableName.Str() );
xbase->WriteLogMessage( sMsg.Str() );
xbase->WriteLogMessage( GetErrorMessage( iRc ));
-
}
-
#ifdef XB_LOCKING_SUPPORT
- dbf->LockTable( XB_UNLOCK );
+ if( bTableLocked && dbf )
+ dbf->LockTable( XB_UNLOCK );
#endif // XB_LOCKING_SUPPORT
return iRc;