summaryrefslogtreecommitdiff
path: root/src/tests/xb_test_sql.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/xb_test_sql.cpp')
-rwxr-xr-xsrc/tests/xb_test_sql.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/tests/xb_test_sql.cpp b/src/tests/xb_test_sql.cpp
new file mode 100755
index 0000000..630cc89
--- /dev/null
+++ b/src/tests/xb_test_sql.cpp
@@ -0,0 +1,107 @@
+/* xb_test_sql.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:
+
+ xb64-devel@lists.sourceforge.net
+ xb64-users@lists.sourceforge.net
+
+*/
+
+// This program tests the SQL functions
+
+// usage: xb_test_sql QUITE|NORMAL|VERBOSE
+
+
+
+#include "xbase.h"
+
+using namespace xb;
+
+#include "tstfuncs.cpp"
+
+
+int main( int argCnt, char **av )
+{
+ int iRc = 0;
+ int iRc2 = 0;
+ int po = 1; /* print option */
+ /* 0 - QUIET */
+ /* 1 - NORMAL */
+ /* 2 - VERBOSE */
+
+ if( argCnt > 1 ) {
+ if( av[1][0] == 'Q' )
+ po = 0;
+ else if( av[1][0] == 'V' )
+ po = 2;
+ }
+
+
+ xbSchema MySqlRecord[] =
+ {
+ { "CITY", XB_CHAR_FLD, 30, 0 },
+ { "STATE", XB_CHAR_FLD, 2, 0 },
+ { "ZIPCODE", XB_NUMERIC_FLD, 9, 0 },
+ { "NOTES", XB_MEMO_FLD, 10, 0 },
+ { "LASTUPDATE", XB_DATE_FLD, 8, 1 },
+ { "ACTIVE", XB_LOGICAL_FLD, 1, 0 },
+ { "",0,0,0 }
+ };
+
+
+ xbXBase x;
+#ifdef XB_LOGGING_SUPPORT
+ x.EnableMsgLogging();
+ if( po ){
+ std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl;
+ }
+ xbString sMsg;
+ sMsg.Sprintf( "Program [%s] initializing...", av[0] );
+ x.WriteLogMessage( sMsg );
+#endif
+
+
+
+ x.SetDataDirectory( PROJECT_DATA_DIR );
+ x.EnableMsgLogging();
+ InitTime();
+
+ xbSql sql( &x );
+
+ if( po > 0 )
+ std::cout << "Default Data Directory is [" << x.GetDataDirectory().Str() << "]" << std::endl;
+
+ xbDbf4 SqlDbf( &x ); // version 4 dbf file
+ iRc2 = SqlDbf.CreateTable( "TestSQL.DBF", "TestSQL", MySqlRecord, XB_OVERLAY, XB_MULTI_USER );
+ iRc += TestMethod( po, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR );
+ if( iRc2 )
+ x.DisplayError( iRc2 );
+
+
+ xbString sSql = "INSERT INTO TestSQL (CITY, STATE, ZIPCODE, NOTES, LASTUPDATE, ACTIVE ) VALUES ( 'San Diego', 'CA', 92007, 'San Diego is a cool place', '1989-02-09', 'Y')";
+
+ iRc2 = sql.ExecuteNonQuery( sSql );
+ iRc += TestMethod( po, "Insert()", (xbInt32) iRc2, XB_NO_ERROR );
+ if( iRc2 )
+ x.DisplayError( iRc2 );
+
+ iRc += TestMethod( po, "Close()", SqlDbf.Close(), XB_NO_ERROR );
+
+ if( po > 0 || iRc < 0 )
+ fprintf( stdout, "Total Errors = %d\n", iRc * -1 );
+
+
+#ifdef XB_LOGGING_SUPPORT
+ sMsg.Sprintf( "Program [%s] terminating with [%d] errors...", av[0], iRc * -1 );
+ x.WriteLogMessage( sMsg );
+#endif
+
+ return iRc;
+}
+