From 517ad9d4b6eae320b708d03a9340a22893b0cab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 29 Jan 2023 15:45:51 +0100 Subject: New upstream version 4.0.3 --- src/sql/xbalttbl.cpp | 125 +++++++++++++++++++++++++++++++++++++++++++ src/sql/xbcrix.cpp | 60 ++++++++++++--------- src/sql/xbcrtbl.cpp | 2 +- src/sql/xbdelete.cpp | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/sql/xbdrpix.cpp | 38 ++++++++----- src/sql/xbinsert.cpp | 32 +++++------ src/sql/xbselect.cpp | 92 ++++++++++++++++++++++++++++++++ src/sql/xbsql.cpp | 62 ++++++++++++++++----- 8 files changed, 491 insertions(+), 68 deletions(-) create mode 100755 src/sql/xbalttbl.cpp create mode 100755 src/sql/xbdelete.cpp create mode 100755 src/sql/xbselect.cpp (limited to 'src/sql') diff --git a/src/sql/xbalttbl.cpp b/src/sql/xbalttbl.cpp new file mode 100755 index 0000000..576eab7 --- /dev/null +++ b/src/sql/xbalttbl.cpp @@ -0,0 +1,125 @@ +/* xbslttbl.cpp + +XBase64 Software Library + +Copyright (c) 1997,2003,2014,2022 Gary A Kunkel + +The xb64 software library is covered under the terms of the GPL Version 3, 2007 license. + +Email Contact: + + XDB-devel@lists.sourceforge.net + XDB-users@lists.sourceforge.net + +*/ + +#include "xbase.h" + +#ifdef XB_SQL_SUPPORT + +namespace xb{ + + +/***********************************************************************/ +xbInt16 xbSql::SqlAlterTable( const xbString &sCmdLine ){ + + // expected format: + // ALTER TABLE tablename.DBF RENAME TO newtablename.DBF + + + xbInt16 iRc = 0; + xbInt16 iErrorStop = 0; + xbString sTableName = ""; + xbUInt32 ulPos = 0; + xbString sCmd = sCmdLine; + xbString sNode = ""; + + xbString sSrcTbl; + xbString sTrgTbl; + xbDbf * dbf = NULL; + + try{ + +// std::cout << "xbSql::SqlAlterTable( " << sCmdLine.Str() << " )\n"; + + // drop off the first node "DROP" + ulPos = sCmd.Pos( ' ' ); + sCmd.Ltrunc( ulPos ); + sCmd.Ltrim(); + + // drop off the second node "TABLE" + ulPos = sCmd.Pos( ' ' ); + sCmd.Ltrunc( ulPos ); + sCmd.Ltrim(); + + // pull off the source table + sSrcTbl.ExtractElement( sCmd, ' ', 1, 0 ); + sSrcTbl.Trim(); + + // pull off the action + sNode.ExtractElement( sCmd, ' ', 2, 0 ); + sNode.Trim(); + sNode.ToUpperCase(); + if( sNode != "RENAME" ){ + iErrorStop = 100; + iRc = XB_SYNTAX_ERROR; + throw iRc; + } + + // pull off "TO" + sNode.ExtractElement( sCmd, ' ', 3, 0 ); + sNode.Trim(); + sNode.ToUpperCase(); + if( sNode != "TO" ){ + iErrorStop = 110; + iRc = XB_SYNTAX_ERROR; + throw iRc; + } + + sTrgTbl.ExtractElement( sCmd, ' ', 4, 0 ); + sTrgTbl.Trim(); + + std::cout << "source table name = " << sSrcTbl.Str() << "\n"; +// std::cout << "target table name = " << sTrgTbl.Str() << "\n"; + + // if not open, attempt to open it + dbf = xbase->GetDbfPtr( sSrcTbl ); + + if( dbf ) + std::cout << "dbf valued\n"; + else + std::cout << "dbf not valued\n"; + + if( !dbf ){ + if(( iRc = xbase->OpenHighestVersion( sSrcTbl, "", &dbf )) != XB_NO_ERROR ){ + iErrorStop = 120; + throw iRc; + } + } + if( !dbf ){ + iErrorStop = 130; + iRc = XB_DBF_FILE_NOT_OPEN; + throw iRc; + } + + if(( iRc = dbf->Rename( sTrgTbl )) != XB_NO_ERROR ){ + iErrorStop = 140; + throw iRc; + } + + } + + catch (xbInt16 iRc ){ + xbString sMsg; + sMsg.Sprintf( "xbSql::SqlAlterTable() Exception Caught. Error Stop = [%d] rc = [%d] table = [%s]", iErrorStop, iRc, sTableName.Str() ); + xbase->WriteLogMessage( sMsg.Str() ); + xbase->WriteLogMessage( GetErrorMessage( iRc )); + } + + return iRc; +} + +/***********************************************************************/ +} /* namespace */ +#endif /* XB_SQL_SUPPORT */ + diff --git a/src/sql/xbcrix.cpp b/src/sql/xbcrix.cpp index b24782e..8dc6f62 100755 --- a/src/sql/xbcrix.cpp +++ b/src/sql/xbcrix.cpp @@ -21,6 +21,7 @@ namespace xb{ /***********************************************************************/ +#ifdef XB_INDEX_SUPPORT xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ // std::cout << "CREATE INDEX " << sCmdLine << std::endl; @@ -68,8 +69,6 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ try{ - // std::cout << "xbSql::CreateIx()\n" ; - // drop off the first node ulPos = sCmd.Pos( ' ' ); sCmd.Ltrunc( ulPos ); @@ -104,7 +103,7 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ if( sIxType == "" ){ if(( iRc = uda.GetTokenForKey( "IXTYPE", sIxType )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 100; throw iRc; } } @@ -114,7 +113,7 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ xbFile f( xbase ); f.SetFileName( sIxName ); if( f.FileExists()){ - iErrorStop = 30; + iErrorStop = 110; iRc = XB_FILE_EXISTS; throw iRc; } @@ -143,7 +142,7 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ dbf = xbase->GetDbfPtr( fDbf.GetFqFileName()); if( !dbf ){ if(( iRc = xbase->OpenHighestVersion( sTableName, "", &dbf )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 120; throw iRc; } } @@ -154,13 +153,14 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ } sCmd.Ltrunc( ulPos ); - // std::cout << "cp1 ulPos = " << ulPos << " scmd = " << sCmd << "\n"; + std::cout << "cp1 ulPos = " << ulPos << " sCmd = [" << sCmd << "]\n"; //ulPos = sCmd.GetLastPos( ')' ); xbString sKeyExpression; xbBool bDone = xbFalse; xbUInt32 lPos = 1; xbInt16 iParenCtr = 0; + while( !bDone && lPos < sCmd.Len()){ if( sCmd[lPos] == '(' ){ iParenCtr++; @@ -172,19 +172,21 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ } else { bDone = xbTrue; } - } else if( sCmd[lPos] == ',' ){ + } else if( sCmd[lPos] == ',' && iParenCtr == 0 ){ sKeyExpression.Append( '+' ); } else if( sCmd[lPos] != ' ' ){ sKeyExpression.Append( sCmd[lPos] ); } lPos++; } -// std::cout << "Key Expression =[" << sKeyExpression << "]\n"; + + std::cout << "Key Expression =[" << sKeyExpression << "]\n"; + sCmd.Ltrunc( lPos ); sCmd.Trim(); xbBool bDesc = xbFalse; -// std::cout << "sCmd - looking for DESC [" << sCmd << "]\n"; + // std::cout << "sCmd - looking for DESC [" << sCmd << "]\n"; if( sCmd.Len() > 4 ){ sNode = sCmd; sNode.ToUpperCase(); @@ -193,11 +195,12 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ bDesc = xbTrue; sCmd.Ltrunc( 4 ); sCmd.Trim(); - // std::cout << "Descending\n"; + std::cout << "Descending\n"; } } -// std::cout << "sCmd - looking for FILTER stuff [" << sCmd << "]\n"; + + // std::cout << "sCmd - looking for FILTER stuff [" << sCmd << "]\n"; xbString sFilter; if( sCmd.Len() > 6 ){ sNode = sCmd; @@ -205,29 +208,29 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ ulPos = sNode.Pos( "FILTER" ); if( ulPos > 0 ){ sFilter = sCmd; - sFilter.Ltrunc( ulPos + 7 ); + sFilter.Ltrunc( ulPos + 6 ); sFilter.Trim(); } } -// std::cout << "sCmd - FILTER = [" << sFilter << "]\n"; + // std::cout << "sCmd - FILTER = [" << sFilter << "]\n"; #ifdef XB_LOCKING_SUPPORT if(( iRc = dbf->LockTable( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 60; + iErrorStop = 130; throw iRc; } #endif // XB_LOCKING_SUPPORT -// std::cout << "SqlCreateIndex() - ixtype = " << sIxType << "\n"; + // std::cout << "SqlCreateIndex() - ixtype = " << sIxType << "\n"; xbIx *pIx; void *vpTag; if(( iRc = dbf->CreateTag( sIxType, sIxName, sKeyExpression, sFilter, bDesc, bUnique, xbFalse, &pIx, &vpTag )) != XB_NO_ERROR ){ - iErrorStop = 70; + iErrorStop = 140; throw iRc; } -// std::cout << "SqlCreateIndex() - back from tag create\n"; + // std::cout << "SqlCreateIndex() - back from tag create\n"; #ifdef XB_NDX_SUPPORT if( sIxType == "NDX"){ sCmd.Ltrunc( ulPos ); @@ -236,20 +239,27 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ sCmd.ToUpperCase(); if( sCmd.Pos( "ASSOCIATE" )){ if(( iRc = dbf->AssociateIndex( "NDX", sIxName, 0 )) != XB_NO_ERROR ){ - iErrorStop = 80; + iErrorStop = 150; throw iRc; } } } } - if( sIxType == "NDX"){ - if(( iRc = pIx->Reindex( &vpTag )) != XB_NO_ERROR ){ - iErrorStop = 100; - throw iRc; - } - } +// if( sIxType == "NDX"){ +// if(( iRc = pIx->Reindex( &vpTag )) != XB_NO_ERROR ){ +// iErrorStop = 160; +// throw iRc; +// } +// } #endif // XB_NDX_SUPPORT + + if(( iRc = pIx->Reindex( &vpTag )) != XB_NO_ERROR ){ + iErrorStop = 160; + throw iRc; + } + + #ifdef XB_LOCKING_SUPPORT if(( iRc = dbf->LockTable( XB_UNLOCK )) != XB_NO_ERROR ){ iErrorStop = 140; @@ -272,7 +282,7 @@ xbInt16 xbSql::SqlCreateIndex( const xbString &sCmdLine ){ return iRc; } - +#endif // XB_INDEX_SUPPORT /***********************************************************************/ } /* namespace */ #endif /* XB_SQL_SUPPORT */ diff --git a/src/sql/xbcrtbl.cpp b/src/sql/xbcrtbl.cpp index 4193d01..7f6b8fa 100755 --- a/src/sql/xbcrtbl.cpp +++ b/src/sql/xbcrtbl.cpp @@ -225,7 +225,7 @@ xbInt16 xbSql::SqlCreateTable( const xbString &sCmdLine ){ xbDbf * dbf = NULL; #ifdef XB_DBF4_SUPPORT dbf = new xbDbf4( xbase ); - #elif XB_DBF3_SUPPORT + #elif defined (XB_DBF3_SUPPORT) dbf = new xbDbf3( xbase ); #endif if(( iRc = dbf->CreateTable( sTableName, "", schema, 0, XB_MULTI_USER )) != XB_NO_ERROR ){ diff --git a/src/sql/xbdelete.cpp b/src/sql/xbdelete.cpp new file mode 100755 index 0000000..157b281 --- /dev/null +++ b/src/sql/xbdelete.cpp @@ -0,0 +1,148 @@ +/* xbdelete.cpp + +XBase64 Software Library + +Copyright (c) 1997,2003,2014,2022 Gary A Kunkel + +The xb64 software library is covered under the terms of the GPL Version 3, 2007 license. + +Email Contact: + + XDB-devel@lists.sourceforge.net + XDB-users@lists.sourceforge.net + +*/ + +#include "xbase.h" + +#ifdef XB_SQL_SUPPORT + +namespace xb{ + + +/***********************************************************************/ +xbInt16 xbSql::SqlDelete( const xbString &sCmdLine ){ + + // expected format: + // DELETE FROM tablename.DBF [WHERE expression] + + + xbInt16 iRc = 0; + xbInt16 iRc2 = 0; + xbInt16 iErrorStop = 0; + xbString sTableName = ""; + xbUInt32 ulPos = 0; + xbString sCmd = sCmdLine; + xbString sNode = ""; + xbString sFilter; + xbInt16 iDelOpt = 0; + + xbString sTable; + xbDbf * dbf = NULL; + + try{ + +// std::cout << "xbSql::SqlDelete( " << sCmdLine.Str() << " )\n"; + + sNode.ExtractElement( sCmd, ' ', 1, 0 ); + sNode.Trim(); + sNode.ToUpperCase(); + if( sNode == "UNDELETE" ) + iDelOpt = 1; + + // pull off the action + sNode.ExtractElement( sCmd, ' ', 2, 0 ); + sNode.Trim(); + sNode.ToUpperCase(); + if( sNode != "FROM" ){ + iErrorStop = 100; + iRc = XB_SYNTAX_ERROR; + throw iRc; + } + + // pull off the table name + sTable.ExtractElement( sCmd, ' ', 3, 0 ); + sTable.Trim(); + + // pull off the "WHERE" statement if it exists + sNode.ExtractElement( sCmd, ' ', 4, 0 ); + sNode.Trim(); + sNode.ToUpperCase(); + if( sNode == "WHERE" ){ + ulPos = sCmd.Pos( "WHERE" ); + sFilter = sCmd; + sFilter.Ltrunc( ulPos + 5 ); + } + + // if not open, attempt to open it + dbf = xbase->GetDbfPtr( sTable ); + if( !dbf ){ + if(( iRc = xbase->OpenHighestVersion( sTable, "", &dbf )) != XB_NO_ERROR ){ + iErrorStop = 110; + throw iRc; + } + } + if( !dbf ){ + iErrorStop = 120; + iRc = XB_DBF_FILE_NOT_OPEN; + throw iRc; + } + + if( sFilter == "" ){ + if(( iRc = dbf->DeleteAll( iDelOpt )) != XB_NO_ERROR ){ + iErrorStop = 130; + throw iRc; + } + } else { + + xbFilter f( dbf->GetXbasePtr(), dbf ); + if(( iRc = f.Set( sFilter )) != XB_NO_ERROR ){ + iErrorStop = 150; + throw iRc; + } + + iRc2 = f.GetFirstRecord( XB_ALL_RECS ); + while( iRc2 == XB_NO_ERROR ){ + if( iDelOpt == 0 ){ + if( !dbf->RecordDeleted()){ + if(( iRc = dbf->DeleteRecord()) != XB_NO_ERROR ){ + iErrorStop = 160; + throw iRc; + } + if(( iRc = dbf->Commit()) != XB_NO_ERROR ){ + iErrorStop = 170; + throw iRc; + } + } + + } else { // undelete + if( dbf->RecordDeleted()){ + if(( iRc = dbf->UndeleteRecord()) != XB_NO_ERROR ){ + iErrorStop = 180; + throw iRc; + } + if(( iRc = dbf->Commit()) != XB_NO_ERROR ){ + iErrorStop = 190; + throw iRc; + } + } + } + iRc2 = f.GetNextRecord(); + } + } + } + + catch (xbInt16 iRc ){ + xbString sMsg; + sMsg.Sprintf( "xbSql::SqlDropTable() Exception Caught. Error Stop = [%d] rc = [%d] table = [%s]", iErrorStop, iRc, sTableName.Str() ); + xbase->WriteLogMessage( sMsg.Str() ); + xbase->WriteLogMessage( GetErrorMessage( iRc )); + } + + return iRc; +} + +/***********************************************************************/ +} /* namespace */ +#endif /* XB_SQL_SUPPORT */ + diff --git a/src/sql/xbdrpix.cpp b/src/sql/xbdrpix.cpp index 9e3bc3b..2815264 100755 --- a/src/sql/xbdrpix.cpp +++ b/src/sql/xbdrpix.cpp @@ -19,7 +19,7 @@ Email Contact: namespace xb{ - +#ifdef XB_INDEX_SUPPORT /***********************************************************************/ xbInt16 xbSql::SqlDropIndex( const xbString &sCmdLine ){ @@ -63,7 +63,7 @@ xbInt16 xbSql::SqlDropIndex( const xbString &sCmdLine ){ sNode.Trim(); sNode.ToUpperCase(); if( sNode != "EXISTS" ){ - iErrorStop = 10; + iErrorStop = 100; iRc = XB_SYNTAX_ERROR; throw iRc; } else { @@ -97,30 +97,42 @@ xbInt16 xbSql::SqlDropIndex( const xbString &sCmdLine ){ dbf = xbase->GetDbfPtr( fDbf.GetFqFileName()); if( !dbf ){ if(( iRc = xbase->OpenHighestVersion( sTableName, "", &dbf )) != XB_NO_ERROR ){ - iErrorStop = 20; + iErrorStop = 110; throw iRc; } } if( dbf == NULL ){ - iErrorStop = 40; + iErrorStop = 120; iRc = XB_FILE_NOT_FOUND; throw iRc; } #ifdef XB_LOCKING_SUPPORT if(( iRc = dbf->LockTable( XB_LOCK )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 130; throw iRc; } #endif // XB_LOCKING_SUPPORT - iRc = dbf->DeleteTag( "NDX", sIxName ); - if( iRc == XB_FILE_NOT_FOUND && !bIfExists ){ - iErrorStop = 60; - throw( iRc ); - } else if( iRc != XB_NO_ERROR ){ - iErrorStop = 70; - throw iRc; + ulPos = sIxName.Pos( ".NDX" ); + if( ulPos > 0 ){ + iRc = dbf->DeleteTag( "NDX", sIxName ); + if( iRc == XB_FILE_NOT_FOUND && !bIfExists ){ + iErrorStop = 140; + throw( iRc ); + } else if( iRc != XB_NO_ERROR ){ + iErrorStop = 150; + throw iRc; + } + } else { // assuming MDX tag + iRc = dbf->DeleteTag( "MDX", sIxName ); + if( iRc == XB_FILE_NOT_FOUND && !bIfExists ){ + iErrorStop = 160; + throw( iRc ); + } else if( iRc != XB_NO_ERROR ){ + iErrorStop = 170; + throw iRc; + } } } catch (xbInt16 iRc ){ @@ -136,7 +148,7 @@ xbInt16 xbSql::SqlDropIndex( const xbString &sCmdLine ){ return iRc; } - +#endif // XB_INDEX_SUPPORT /***********************************************************************/ } /* namespace */ #endif /* XB_SQL_SUPPORT */ diff --git a/src/sql/xbinsert.cpp b/src/sql/xbinsert.cpp index 1095202..835f9e6 100755 --- a/src/sql/xbinsert.cpp +++ b/src/sql/xbinsert.cpp @@ -52,13 +52,13 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ if( !dbf ){ if(( iRc = xbase->OpenHighestVersion( sTableName, "", &dbf )) != XB_NO_ERROR ){ - iErrorStop = 10; + iErrorStop = 100; throw iRc; } } - + if( !dbf ){ - iErrorStop = 20; + iErrorStop = 110; iRc = XB_FILE_NOT_FOUND; throw iRc; } @@ -78,7 +78,7 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ // verify there are the same count in the field list and values list if( iFldCnt != iDataCnt ){ - iErrorStop = 30; + iErrorStop = 120; iRc = XB_SYNTAX_ERROR; throw iRc; } @@ -90,11 +90,11 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ sFieldName.ExtractElement( sFieldList, ',', i, 0 ); sFieldName.Trim(); if(( iRc = dbf->GetFieldNo( sFieldName, iFldNo )) != XB_NO_ERROR ){ - iErrorStop = 40; + iErrorStop = 130; throw iRc; } if(( iRc = dbf->GetFieldType( iFldNo, cFldType )) != XB_NO_ERROR ){ - iErrorStop = 50; + iErrorStop = 140; throw iRc; } @@ -113,7 +113,7 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ case 'N': case 'L': if(( iRc = dbf->PutField( iFldNo, sFieldData )) != XB_NO_ERROR ){ - iErrorStop = 100; + iErrorStop = 150; throw iRc; } break; @@ -121,7 +121,7 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ case 'D': // assumes input date format of yyyy-mm-dd if( sFieldData.Len() != 10 || sFieldData[5] != '-' || sFieldData[8] != '-' ){ - iErrorStop = 110; + iErrorStop = 160; iRc = XB_INVALID_DATA; throw iRc; } @@ -129,7 +129,7 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ sWork1.Remove( 8, 1 ); sWork1.Remove( 5, 1 ); if(( iRc = dbf->PutField( iFldNo, sWork1 )) != XB_NO_ERROR ){ - iErrorStop = 120; + iErrorStop = 170; throw iRc; } break; @@ -140,14 +140,14 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ break; default: - iErrorStop= 150; + iErrorStop= 180; iRc = XB_INVALID_FIELD_TYPE; throw iRc; } } if(( iRc = dbf->AppendRecord()) != XB_NO_ERROR ){ - iErrorStop = 300; + iErrorStop = 190; throw iRc; } @@ -159,17 +159,17 @@ xbInt16 xbSql::SqlInsert( const xbString &sCmdLine ){ iFldNo = llN->GetKey(); sFieldData = llD->GetKey(); if(( iRc = dbf->UpdateMemoField( iFldNo, sFieldData )) != XB_NO_ERROR ){ - iErrorStop = 400; + iErrorStop = 200; throw iRc; } llN = llN->GetNextNode(); llD = llD->GetNextNode(); } - if(( iRc == dbf->Commit()) != XB_NO_ERROR ){ - iErrorStop = 500; - throw iRc; - } + if(( iRc = dbf->Commit()) != XB_NO_ERROR ){ + iErrorStop = 210; + throw iRc; + } } catch (xbInt16 iRc ){ xbString sMsg; diff --git a/src/sql/xbselect.cpp b/src/sql/xbselect.cpp new file mode 100755 index 0000000..91c0485 --- /dev/null +++ b/src/sql/xbselect.cpp @@ -0,0 +1,92 @@ +/* xbset.cpp + +XBase64 Software Library + +Copyright (c) 1997,2003,2014,2022 Gary A Kunkel + +The xb64 software library is covered under the terms of the GPL Version 3, 2007 license. + +Email Contact: + + XDB-devel@lists.sourceforge.net + XDB-users@lists.sourceforge.net + +*/ + +#include "xbase.h" + +#ifdef XB_SQL_SUPPORT + +namespace xb{ + + +/***********************************************************************/ +xbInt16 xbSql::SqlSelect( const xbString &sCmdLine ){ + + std::cout << "SELECT [" << sCmdLine << "]\n"; + // expected format: + // SELECT + + xbInt16 iRc = 0; + xbInt16 iErrorStop = 0; + xbUInt32 ulPos; + + try{ + +/* + xbString sCmd = sCmdLine; + sCmd.Trim(); + sCmd.ZapTrailingChar( ';' ); + sCmd.Trim(); + + // drop off the first node "SET" + ulPos = sCmd.Pos( ' ' ); + sCmd.Ltrunc( ulPos ); + sCmd.Ltrim(); + + xbString sNode1 = sCmd; + sNode1.ToUpperCase(); + + if( sNode1 == "SET" ) { + uda.DumpUda(); + + } else { + + xbString sKey; + sKey.ExtractElement( sCmd, '=', 1, 0 ); + sKey.Trim(); + + xbString sToken; + sToken.ExtractElement( sCmd, '=', 2, 0 ); + sToken.Trim(); + + + if( sToken == '^' ){ + if(( iRc = uda.DelTokenForKey( sKey )) != XB_NO_ERROR ){ + iErrorStop = 10; + throw iRc; + } + } else { + if(( iRc = uda.UpdTokenForKey( sKey, sToken )) != XB_NO_ERROR ){ + iErrorStop = 10; + throw iRc; + } + } + } +*/ + + } + catch (xbInt16 iRc ){ + xbString sMsg; + sMsg.Sprintf( "xbSql::SqlSelect() Exception Caught. Error Stop = [%d] rc = [%d]", iErrorStop, iRc ); + xbase->WriteLogMessage( sMsg.Str() ); + xbase->WriteLogMessage( GetErrorMessage( iRc )); + } + + return iRc; +} + +/***********************************************************************/ +} /* namespace */ +#endif /* XB_SQL_SUPPORT */ + diff --git a/src/sql/xbsql.cpp b/src/sql/xbsql.cpp index 25cd2c8..5261b1a 100755 --- a/src/sql/xbsql.cpp +++ b/src/sql/xbsql.cpp @@ -57,7 +57,20 @@ xbInt16 xbSql::ExecuteNonQuery( const xbString &sCmdLine ) { // std::cout << "node 1 = " << sNode1.Str() << std::endl; - if( sNode1 == "CREATE" ){ + if( sNode1 == "ALTER" ){ + xbString sNode2; + sNode2.ExtractElement( sCmd.Str(), ' ', 2, 0 ); + sNode2.ToUpperCase(); + sNode2.Trim(); + + if( sNode2 == "TABLE" ) + iRc = SqlAlterTable( sCmd ); + else + iRc = XB_INVALID_FUNCTION; + + + + } else if( sNode1 == "CREATE" ){ xbString sNode2; sNode2.ExtractElement( sCmd.Str(), ' ', 2, 0 ); @@ -65,8 +78,11 @@ xbInt16 xbSql::ExecuteNonQuery( const xbString &sCmdLine ) { sNode2.Trim(); if( sNode2 == "TABLE" ) iRc = SqlCreateTable( sCmd ); + + #ifdef XB_INDEX_SUPPORT else if( sNode2 == "INDEX" || sNode2 == "UNIQUE" ) iRc = SqlCreateIndex( sCmd ); + #endif // XB_INDEX_SUPPORT else iRc = XB_INVALID_FUNCTION; @@ -81,22 +97,35 @@ xbInt16 xbSql::ExecuteNonQuery( const xbString &sCmdLine ) { if( sNode2 == "TABLE" ) iRc = SqlDropTable( sCmd ); + #ifdef XB_INDEX_SUPPORT else if( sNode2 == "INDEX" ) iRc = SqlDropIndex( sCmd ); + #endif // XB_INDEX_SUPPORT + + else + iRc = XB_INVALID_FUNCTION; + + } else if( sNode1 == "DELETE" || sNode1 == "UNDELETE" ){ + + iRc = SqlDelete( sCmd ); + } else if( sNode1 == "HELP" ) SqlHelp(); else if( sNode1 == "INSERT" ){ - iRc = SqlInsert( sCmd ); // else if( sNode1 == "UPDATE" ) // iRc = SqlUpdate( sCmd ); } + else if( sNode1 == "USE" ) iRc = SqlUse( sCmd ); + else if( sNode1 == "SELECT" ) + iRc = SqlSelect( sCmd ); + else if( sNode1 == "SET" ) iRc = SqlSet( sCmd ); @@ -114,11 +143,23 @@ xbXBase *xbSql::GetXbasePtr() const { /***********************************************************************/ void xbSql::SqlHelp() const { - std::cout << "************************" << std::endl; - std::cout << "Valid XBase SQL commands" << std::endl << std::endl; - std::cout << "HELP" << std::endl; - std::cout << "USE /dir/to/dbf/tables" << std::endl; - std::cout << "CREATE TABLE" << std::endl << std::endl << std::endl; + std::cout << "************************" << std::endl; + std::cout << "Valid XBase SQL commands" << std::endl << std::endl; + std::cout << "HELP" << std::endl; + + std::cout << "ALTER TABLE tablename.DBF RENAME TO newtablename.DBF" << std::endl; + std::cout << "CREATE INDEX ixname.NDX ON tablename.dbf ( EXPRESSION ) [ASSOCIATE]" << std::endl; + std::cout << "CREATE [UNIQUE] INDEX tagname ON tablename.dbf ( EXPRESSION ) [DESC] [FILTER .NOT. DELETED()]" << std::endl; + std::cout << "CREATE TABLE tablename.DBF (Field1 CHAR(10), INTFLD1 INTEGER, ... )" << std::endl; + std::cout << "DELETE FROM tablename.DBF [WHERE expression]" << std::endl; + std::cout << "DROP INDEX [IF EXISTS] ixname.NDX ON tablename.DBF" << std::endl; + std::cout << "DROP TABLE [IF EXISTS] tablename.DBF" << std::endl; + std::cout << "INSERT INTO tablename (field1, field2, field3,...) VALUES ( 'charval', numval, {MM/DD/YY})" << std::endl; + std::cout << "SELECT FIELD1,FIELD2... FROM TABLE.DBF [WHERE expression] [ORDER BY TAG TAGNAME" << std::endl; + std::cout << "SET ATTRIBUTE = DATAVALUE" << std::endl; + std::cout << "SET ATTRIBUTE = ^ (to delete an entry)" << std::endl; + std::cout << "USE /dir/to/dbf/tables" << std::endl; + std::cout << "CREATE TABLE" << std::endl << std::endl << std::endl; } /***********************************************************************/ @@ -132,12 +173,7 @@ xbInt16 xbSql::SqlUse( const xbString &sCmdLine ){ return XB_NO_ERROR; } -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ - /***********************************************************************/ } /* namespace */ #endif /* XB_SQL_SUPPORT */ + -- cgit v1.2.3