summaryrefslogtreecommitdiff
path: root/src/utils/xb_execsql.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/xb_execsql.cpp')
-rwxr-xr-xsrc/utils/xb_execsql.cpp69
1 files changed, 52 insertions, 17 deletions
diff --git a/src/utils/xb_execsql.cpp b/src/utils/xb_execsql.cpp
index daa6b6e..3441e91 100755
--- a/src/utils/xb_execsql.cpp
+++ b/src/utils/xb_execsql.cpp
@@ -15,12 +15,21 @@ Email Contact:
*/
#include <xbase.h>
-
using namespace xb;
-xbInt16 GetNextSqlCmd( xbFile &f, xbString &sCmd );
-xbInt16 GetNextSqlCmd( xbFile &f, xbString &sCmd )
-{
+void PrintHelp();
+void PrintHelp(){
+ std::cout << "Usage: xb_execsql [-h] [-?] [--help] [-v] [--version] -i filename.SQL -q --quiet" << std::endl << std::endl;
+ std::cout << "This program processes sql commands from input file 'filename.SQL'" << std::endl << std::endl;
+}
+void PrintVersion();
+void PrintVersion(){
+ std::cout << "Xbase64 Version: " << xbase_VERSION_MAJOR << "." << xbase_VERSION_MINOR << "." << xbase_VERSION_PATCH << std::endl;
+}
+
+
+xbInt16 GetNextSqlCmd( xbFile &f, xbString &sCmd, xbBool bQuiet );
+xbInt16 GetNextSqlCmd( xbFile &f, xbString &sCmd, xbBool bQuiet ){
sCmd = "";
xbString sLine;
xbInt16 iRc = XB_NO_ERROR;
@@ -31,6 +40,12 @@ xbInt16 GetNextSqlCmd( xbFile &f, xbString &sCmd )
bDone = xbTrue;
} else {
+ if( !bQuiet ){
+ std::cout << sLine;
+ if( sLine.Pos( 0x0a ) == 0 )
+ std::cout << std::endl;
+ }
+
// don't need CR/LF chars
sLine.ZapChar( 0x0a );
sLine.ZapChar( 0x0d );
@@ -50,23 +65,43 @@ xbInt16 GetNextSqlCmd( xbFile &f, xbString &sCmd )
return iRc;
}
-int main(int ac,char** av)
+
+int main(int argc, char* argv[])
{
+ xbXBase x;
+ xbSql sql( &x );
+ xbFile f( sql.GetXbasePtr() );
+ xbInt16 iRc = XB_NO_ERROR;
+ xbString sFileName = "";
+ xbString sSqlLine = "";
+ xbString sParm = "";
+ xbBool bQuiet = xbFalse;
+
+ x.EnableMsgLogging();
- if (ac <= 1) {
- std::cout << "Usage: xb_execsql filename..." << std::endl;
+ if (argc < 2 || x.GetCmdLineOpt( argc, argv, "-h", sParm ) ||
+ x.GetCmdLineOpt( argc, argv, "-?", sParm ) ||
+ x.GetCmdLineOpt( argc, argv, "--help", sParm )){
+ PrintHelp();
return 1;
}
- xbXBase x;
- x.EnableMsgLogging();
- xbSql sql( &x );
- xbFile f( sql.GetXbasePtr() );
- xbInt16 iRc = XB_NO_ERROR;
- xbString sFileName;
- xbString sSqlLine;
+ if ( x.GetCmdLineOpt( argc, argv, "-v", sParm ) ||
+ x.GetCmdLineOpt( argc, argv, "--version", sParm )){
+ PrintVersion();
+ return 1;
+ }
+
+ if ( x.GetCmdLineOpt( argc, argv, "-q", sParm ) ||
+ x.GetCmdLineOpt( argc, argv, "--quiet", sParm )){
+ bQuiet = xbTrue;
+ }
+
+ if( !x.GetCmdLineOpt( argc, argv, "-i", sFileName ) || sFileName == "" ){
+ PrintHelp();
+ return 1;
+ }
- sFileName = av[1];
if(( iRc = f.xbFopen( "r", sFileName, XB_SINGLE_USER )) != XB_NO_ERROR ){
xbString sMsg;
@@ -77,12 +112,12 @@ int main(int ac,char** av)
}
while( iRc == XB_NO_ERROR ){
- iRc = GetNextSqlCmd( f, sSqlLine );
+ iRc = GetNextSqlCmd( f, sSqlLine, bQuiet );
if( iRc == XB_NO_ERROR ){
sSqlLine.Trim();
- std::cout << "Processing line [" << sSqlLine.Str() << "]\n";
+ // std::cout << "Processing line [" << sSqlLine.Str() << "]\n";
iRc = sql.ExecuteNonQuery( sSqlLine );
if( iRc != XB_NO_ERROR )
x.DisplayError( iRc );