summaryrefslogtreecommitdiff
path: root/src/utils/xb_execsql.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/utils/xb_execsql.cpp
parentdaf17154bf13139d9375f48525d19d6aaba08155 (diff)
New upstream version 4.0.2upstream/4.0.2
Diffstat (limited to 'src/utils/xb_execsql.cpp')
-rwxr-xr-xsrc/utils/xb_execsql.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/utils/xb_execsql.cpp b/src/utils/xb_execsql.cpp
new file mode 100755
index 0000000..d474593
--- /dev/null
+++ b/src/utils/xb_execsql.cpp
@@ -0,0 +1,95 @@
+/* xb_execsql.cpp
+
+XBase64 Software Library
+
+Copyright (c) 1997,2003,2014 Gary A Kunkel
+
+The xb64 software library is covered under
+the terms of the GPL Version 3, 2007 license.
+
+Email Contact:
+
+ xb64-devel@lists.sourceforge.net
+ xb64-users@lists.sourceforge.net
+
+*/
+
+#include <xbase.h>
+
+using namespace xb;
+
+xbInt16 GetNextSqlCmd( xbFile &f, xbString &sCmd );
+xbInt16 GetNextSqlCmd( xbFile &f, xbString &sCmd )
+{
+ sCmd = "";
+ xbString sLine;
+ xbInt16 iRc = XB_NO_ERROR;
+ xbUInt32 lPos = 0;
+ xbBool bDone = xbFalse;
+ while( !bDone ){
+ if(( iRc = f.xbFgets( 256, sLine )) != XB_NO_ERROR ){
+ bDone = xbTrue;
+ } else {
+
+ // don't need CR/LF chars
+ sLine.ZapChar( 0x0a );
+ sLine.ZapChar( 0x0d );
+
+ // if comment, zap out everything to the right of the hash
+ lPos = sLine.Pos( '#' );
+ if( lPos > 0 )
+ sLine.Left( lPos - 1);
+
+ if( sLine.Pos( ';' ) > 0 ){
+ bDone = xbTrue;
+ sLine.ZapChar( ';' );
+ }
+ }
+ sCmd += sLine;
+ }
+ return iRc;
+}
+
+int main(int ac,char** av)
+{
+
+ if (ac <= 1) {
+ std::cout << "Usage: xb_execsql filename..." << std::endl;
+ return 1;
+ }
+
+ xbXBase x;
+ x.EnableMsgLogging();
+ xbSql sql( &x );
+ xbFile f( sql.GetXbasePtr() );
+ xbInt16 iRc = XB_NO_ERROR;
+ xbString sFileName;
+ xbString sSqlLine;
+
+ sFileName = av[1];
+
+ if(( iRc = f.xbFopen( "r", sFileName, XB_SINGLE_USER )) != XB_NO_ERROR ){
+ xbString sMsg;
+ sMsg.Sprintf( "Error opening [%s]\n", sFileName.Str() );
+ std::cout << sMsg.Str();
+ sql.GetXbasePtr()->DisplayError( iRc );
+ return 1;
+ }
+
+ while( iRc == XB_NO_ERROR ){
+ iRc = GetNextSqlCmd( f, sSqlLine );
+
+ if( iRc == XB_NO_ERROR ){
+
+ sSqlLine.Trim();
+ std::cout << "Processing line [" << sSqlLine.Str() << "]\n";
+ iRc = sql.ExecuteNonQuery( sSqlLine );
+ if( iRc != XB_NO_ERROR )
+ x.DisplayError( iRc );
+ }
+ }
+
+ f.xbFclose();
+ return 0;
+}
+