summaryrefslogtreecommitdiff
path: root/src/sql/xbdrptbl.cpp
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2022-12-07 13:17:14 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2022-12-07 13:17:14 +0100
commit4875a3dd9b183dcd2256e2abfc4ccf7484c233b4 (patch)
tree0abbea881ded030851014ffdd60fbf71fead8f65 /src/sql/xbdrptbl.cpp
parentdaf17154bf13139d9375f48525d19d6aaba08155 (diff)
New upstream version 4.0.2upstream/4.0.2
Diffstat (limited to 'src/sql/xbdrptbl.cpp')
-rwxr-xr-xsrc/sql/xbdrptbl.cpp125
1 files changed, 125 insertions, 0 deletions
diff --git a/src/sql/xbdrptbl.cpp b/src/sql/xbdrptbl.cpp
new file mode 100755
index 0000000..e2cfa9d
--- /dev/null
+++ b/src/sql/xbdrptbl.cpp
@@ -0,0 +1,125 @@
+/* xbdrptbl.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::SqlDropTable( const xbString &sCmdLine ){
+
+ // std::cout << "DROP TABLE [" << sCmdLine << "]\n";
+ // expected format:
+ // DROP TABLE [IF EXISTS] tablename.dbf
+
+
+ xbInt16 iRc = 0;
+ xbInt16 iErrorStop = 0;
+ xbString sTableName = "";
+ xbUInt32 ulPos = 0;
+ xbString sCmd = sCmdLine;
+ xbString sNode = "";
+ xbBool bIfExists = xbFalse;
+ xbDbf * dbf = NULL;
+
+ try{
+
+ // 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();
+
+ sNode.ExtractElement( sCmd, ' ', 1, 0 );
+ sNode.Trim();
+ sNode.ToUpperCase();
+
+ if( sNode == "IF" ){
+ ulPos = sCmd.Pos( ' ' );
+ sCmd.Ltrunc( ulPos );
+ sCmd.Ltrim();
+ sNode.ExtractElement( sCmd, ' ', 1, 0 );
+ sNode.Trim();
+ sNode.ToUpperCase();
+ if( sNode != "EXISTS" ){
+ iErrorStop = 10;
+ iRc = XB_SYNTAX_ERROR;
+ throw iRc;
+ } else {
+ ulPos = sCmd.Pos( ' ' );
+ sCmd.Ltrunc( ulPos );
+ sCmd.Ltrim();
+ bIfExists = xbTrue;
+ }
+ }
+
+ // get the table name
+ sTableName.ExtractElement( sCmd, ' ', 1, 0 );
+ sTableName.Trim();
+
+ xbFile fDbf( xbase );
+ fDbf.SetFileName( sTableName );
+
+ if( bIfExists && ! fDbf.FileExists())
+ return XB_NO_ERROR;
+
+ // if not open, attempt to open it
+ dbf = xbase->GetDbfPtr( fDbf.GetFqFileName());
+
+ if( !dbf ){
+ dbf = xbase->Open( sTableName, iRc );
+ if( iRc != XB_NO_ERROR ){
+ if( iRc == XB_FILE_NOT_FOUND && bIfExists ){
+ return XB_NO_ERROR;
+ } else {
+ iErrorStop = 20;
+ throw iRc;
+ }
+ }
+ }
+ if( dbf == NULL ){
+ iErrorStop = 40;
+ iRc = XB_OPEN_ERROR;
+ throw iRc;
+ }
+
+ if(( dbf->DeleteTable()) != XB_NO_ERROR ){
+ iErrorStop = 50;
+ throw iRc;
+ }
+
+ }
+
+ 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 */
+