diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-12-07 13:17:14 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-12-07 13:17:14 +0100 |
commit | 4875a3dd9b183dcd2256e2abfc4ccf7484c233b4 (patch) | |
tree | 0abbea881ded030851014ffdd60fbf71fead8f65 /src/sql/xbsql.cpp | |
parent | daf17154bf13139d9375f48525d19d6aaba08155 (diff) |
New upstream version 4.0.2upstream/4.0.2
Diffstat (limited to 'src/sql/xbsql.cpp')
-rwxr-xr-x | src/sql/xbsql.cpp | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/src/sql/xbsql.cpp b/src/sql/xbsql.cpp new file mode 100755 index 0000000..25cd2c8 --- /dev/null +++ b/src/sql/xbsql.cpp @@ -0,0 +1,143 @@ +/* xbsql.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{ + +/***********************************************************************/ +xbSql::xbSql( xbXBase *x ){ + xbase = x; + xbString sIxType; + + #ifdef XB_MDX_SUPPORT + sIxType = "MDX"; + #endif + + #ifdef XB_NDX_SUPPORT + if( sIxType == "" ) + sIxType = "NDX"; + #endif + + if( sIxType != "" ) + uda.AddTokenForKey( "IXTYPE", sIxType ); + +} +/***********************************************************************/ +xbSql::~xbSql(){ +} + +/***********************************************************************/ +xbInt16 xbSql::ExecuteNonQuery( const xbString &sCmdLine ) { + +// std::cout << "\n\n\nExecute() " << sCmdLine.Str() << "\n"; + + xbInt16 iRc = XB_NO_ERROR; + xbString sCmd = sCmdLine; + + sCmd.Trim(); + xbString sNode1; + sNode1.ExtractElement( sCmd.Str(), ' ', 1, 0 ); + sNode1.ToUpperCase(); + sNode1.Trim(); + +// std::cout << "node 1 = " << sNode1.Str() << std::endl; + + if( sNode1 == "CREATE" ){ + + xbString sNode2; + sNode2.ExtractElement( sCmd.Str(), ' ', 2, 0 ); + sNode2.ToUpperCase(); + sNode2.Trim(); + if( sNode2 == "TABLE" ) + iRc = SqlCreateTable( sCmd ); + else if( sNode2 == "INDEX" || sNode2 == "UNIQUE" ) + iRc = SqlCreateIndex( sCmd ); + + else + iRc = XB_INVALID_FUNCTION; + + } else if( sNode1 == "DROP" ){ + + xbString sNode2; + sNode2.ExtractElement( sCmd.Str(), ' ', 2, 0 ); + sNode2.ToUpperCase(); + sNode2.Trim(); + + if( sNode2 == "TABLE" ) + iRc = SqlDropTable( sCmd ); + + else if( sNode2 == "INDEX" ) + iRc = SqlDropIndex( 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 == "SET" ) + iRc = SqlSet( sCmd ); + + else + return XB_INVALID_FUNCTION; + + return iRc; +} + +/***********************************************************************/ +xbXBase *xbSql::GetXbasePtr() const { + return xbase; +} + + +/***********************************************************************/ +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; +} + +/***********************************************************************/ +xbInt16 xbSql::SqlUse( const xbString &sCmdLine ){ + + xbString sNode2; + sNode2.ExtractElement( sCmdLine.Str(), ' ', 2, 0 ); + sNode2.Trim(); + xbase->SetDataDirectory( sNode2 ); +// std::cout << "USE " << sNode2 << std::endl; + return XB_NO_ERROR; +} + +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ +/***********************************************************************/ + +/***********************************************************************/ +} /* namespace */ +#endif /* XB_SQL_SUPPORT */ |