summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples')
-rwxr-xr-xsrc/examples/xb_ex_date.cpp2
-rwxr-xr-xsrc/examples/xb_ex_expression.cpp5
-rwxr-xr-xsrc/examples/xb_ex_log.cpp77
-rwxr-xr-xsrc/examples/xb_ex_ssv.cpp4
-rwxr-xr-xsrc/examples/xb_ex_string.cpp5
-rwxr-xr-xsrc/examples/xb_ex_v3_create_dbf.cpp28
-rwxr-xr-xsrc/examples/xb_ex_v3_upd_dbf.cpp144
-rwxr-xr-xsrc/examples/xb_ex_v4_create_dbf.cpp9
-rwxr-xr-xsrc/examples/xb_ex_v4_upd_dbf.cpp16
9 files changed, 216 insertions, 74 deletions
diff --git a/src/examples/xb_ex_date.cpp b/src/examples/xb_ex_date.cpp
index fc038b5..7b92dbe 100755
--- a/src/examples/xb_ex_date.cpp
+++ b/src/examples/xb_ex_date.cpp
@@ -24,6 +24,8 @@ using namespace xb;
int main()
{
+ xbXBase x; /* initial date static variables */
+
xbString StringDate( "19601007" ); /* oct 7 1960 */
char CharDate[9] = "19611109"; /* nov 9 1961 */
diff --git a/src/examples/xb_ex_expression.cpp b/src/examples/xb_ex_expression.cpp
index 840e9c6..f16c79f 100755
--- a/src/examples/xb_ex_expression.cpp
+++ b/src/examples/xb_ex_expression.cpp
@@ -168,7 +168,6 @@ int main(){
}
PrintResult( &sExpression, &exp );
-
// String expression example
sExpression = "CFLD1+CFLD2+'{'+DTOS(DATE1)+'}'";
xbExp exp2( &x );
@@ -176,11 +175,13 @@ int main(){
iErrorStop = 210;
throw iRc;
}
+
// Process the parsed expression
if(( iRc = exp2.ProcessExpression()) != XB_NO_ERROR ){
iErrorStop = 220;
return -1;
}
+
PrintResult( &sExpression, &exp2 );
// Date example
@@ -211,8 +212,6 @@ int main(){
}
PrintResult( &sExpression, &exp4 );
-
-
// Cleanup
MyFile->DeleteTable();
delete MyFile;
diff --git a/src/examples/xb_ex_log.cpp b/src/examples/xb_ex_log.cpp
new file mode 100755
index 0000000..cf5320f
--- /dev/null
+++ b/src/examples/xb_ex_log.cpp
@@ -0,0 +1,77 @@
+/* xb_ex_log.cpp
+
+XBase64 Software Library
+
+Copyright (c) 1997,2003,2014,2022,2023 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
+
+*/
+
+// This program demostrates how to use logging
+
+
+#include "xbase.h"
+
+using namespace xb;
+
+int main( int argCnt, char **av )
+{
+
+ #ifdef XB_LOGGING_SUPPORT
+
+ xbXBase x;
+ xbString sMsg;
+
+
+ std::cout << "Default Logfile Name is: [" << x.GetLogFqFileName().Str()
+ << "] Rollover size = [" << x.GetLogSize()
+ << "]" << std::endl;
+
+ if( x.GetLogStatus() )
+ std::cout << "Logging is active" << std::endl;
+ else
+ std::cout << "Logging is inactive" << std::endl;
+
+ x.SetLogDirectory( PROJECT_LOG_DIR ); // use the library log directory
+ x.SetLogFileName ( "MySpecialLogFile.txt" ); // set to use a special name
+ x.SetLogSize ( x.GetLogSize() * 2 ); // double the log file size
+
+ // enable the logfile and write a message for the new settings to take effect
+ x.EnableMsgLogging();
+ sMsg.Sprintf( "Program [%s] initializing...", av[0] );
+ x.WriteLogMessage( sMsg );
+
+ std::cout << "New Logfile Name is: [" << x.GetLogFqFileName().Str()
+ << "] Rollover size = [" << x.GetLogSize()
+ << "]" << std::endl;
+
+ if( x.GetLogStatus() )
+ std::cout << "Logging is active" << std::endl;
+ else
+ std::cout << "Logging is inactive" << std::endl;
+
+ // write some messages to the logfile
+ for( int i = 0; i < 5; i++ ){
+ sMsg.Sprintf( "Test message [%d]", i );
+ x.WriteLogMessage( sMsg );
+ }
+
+ sMsg.Sprintf( "Program [%s] terminating..", av[0] );
+ x.WriteLogMessage( sMsg );
+
+ x.FlushLog(); // not really needed, but here for demonstration purposes
+
+ #endif // B_LOGGING_SUPPORT
+
+ return 0;
+}
+
+
+
+
diff --git a/src/examples/xb_ex_ssv.cpp b/src/examples/xb_ex_ssv.cpp
index a78345f..61d72a2 100755
--- a/src/examples/xb_ex_ssv.cpp
+++ b/src/examples/xb_ex_ssv.cpp
@@ -19,7 +19,9 @@ This program demonstrates using functionality of the xbSsv class (Shared system
using namespace xb;
-int main( int ac, char ** av ){
+//int main( int ac, char ** av ){
+
+int main( int, char ** av ){
xbXBase x; // set up xbase for business
xbString sMsg; // a message string
diff --git a/src/examples/xb_ex_string.cpp b/src/examples/xb_ex_string.cpp
index 30fd74e..0cd7671 100755
--- a/src/examples/xb_ex_string.cpp
+++ b/src/examples/xb_ex_string.cpp
@@ -116,8 +116,9 @@ int main()
std::cout << s3.Str() << std::endl;
- s3 = 'A' + s1;
-
+ // The following compiles and runs, but is not valid
+ // s3 = 'A' + s1;
+
std::cout << std::endl << "== operator tests" << std::endl;
if( s1 == s2 )
std::cout << s1.Str() << " == " << s2.Str() << std::endl;
diff --git a/src/examples/xb_ex_v3_create_dbf.cpp b/src/examples/xb_ex_v3_create_dbf.cpp
index ecfcd72..d6f7047 100755
--- a/src/examples/xb_ex_v3_create_dbf.cpp
+++ b/src/examples/xb_ex_v3_create_dbf.cpp
@@ -2,7 +2,7 @@
XBase64 Software Library
-Copyright (c) 1997,2003,2014,2022 Gary A Kunkel
+Copyright (c) 1997,2003,2014,2022,2023 Gary A Kunkel
The xb64 software library is covered under the terms of the GPL Version 3, 2007 license.
@@ -47,19 +47,19 @@ int main()
// Create Dbase3 NDX style indices if support compiled in
-#ifdef XB_NDX_SUPPORT
+ #ifdef XB_NDX_SUPPORT
xbIxNdx MyIndex1( MyDbfFile ); /* class for index 1 */
xbIxNdx MyIndex2( MyDbfFile ); /* class for index 2 */
xbIxNdx MyIndex3( MyDbfFile ); /* class for index 3 */
-#endif
+ #endif
-// fixme
-// Create Clipper NTX style indices if support compiled in - bring this back to life in a future release
-#ifdef XB_INDEX_NTX
+ // fixme
+ // Create Clipper NTX style indices if support compiled in - bring this back to life in a future release
+ #ifdef XB_INDEX_NTX
xbNtx MyIndex4( &MyDbfFile ); /* class for index 4 */
xbNtx MyIndex5( &MyDbfFile ); /* class for index 5 */
-#endif
+ #endif
xbInt16 rc;
@@ -68,7 +68,7 @@ int main()
else
{
-#ifdef XB_NDX_SUPPORT
+ #ifdef XB_NDX_SUPPORT
xbIx *pIx;
void *pTag;
@@ -83,6 +83,7 @@ int main()
if(( rc = MyDbfFile->CreateTag ( "NDX", "MYINDEX1.NDX", "LASTNAME", "", 0, 1, XB_OVERLAY, &pIx, &pTag )) != XB_NO_ERROR )
x.DisplayError( rc );
+
/* define a multi-field index "LASTNAME FIRSTNAME" */
if(( rc = MyDbfFile->CreateTag( "NDX", "MYINDEX2.NDX", "LASTNAME+FIRSTNAME", "", 0, 1, XB_OVERLAY, &pIx, &pTag )) != XB_NO_ERROR )
x.DisplayError( rc );
@@ -91,12 +92,19 @@ int main()
if(( rc = MyDbfFile->CreateTag( "NDX", "MYINDEX3.NDX", "ZIPCODE", "", 0, 0, XB_OVERLAY, &pIx, &pTag )) != XB_NO_ERROR )
x.DisplayError( rc );
-#endif
+ std::cout << "Tag Count in MYINDEX3.NDX = " << pIx->GetTagCount() << "\n";
+ xbString sTagName;
+ sTagName = pIx->GetTagName( &pTag );
+ std::cout << "Tag Name in MYINDEX3.NDX = " << sTagName.Str() << "\n";
+
+
+ #endif
}
MyDbfFile->Close(); /* Close database and associated indexes */
+ delete MyDbfFile;
-#endif // XB_DBF3_SUPPORT
+ #endif // XB_DBF3_SUPPORT
return 0;
}
diff --git a/src/examples/xb_ex_v3_upd_dbf.cpp b/src/examples/xb_ex_v3_upd_dbf.cpp
index aa6ec49..eecba16 100755
--- a/src/examples/xb_ex_v3_upd_dbf.cpp
+++ b/src/examples/xb_ex_v3_upd_dbf.cpp
@@ -2,7 +2,7 @@
XBase64 Software Library
-Copyright (c) 1997,2003,2014,2021,2022 Gary A Kunkel
+Copyright (c) 1997,2003,2014,2021,2022,2023 Gary A Kunkel
The xb64 software library is covered under the terms of the GPL Version 3, 2007 license.
@@ -45,7 +45,9 @@ int main()
x.WriteLogMessage( "Program [xb_ex_v3_upd_dbf] initializing..." );
- xbDbf * MyTable = new xbDbf3( &x ); /* class for V3 table */
+ xbDbf * MyTable = new xbDbf3( &x ); /* class for V3 table */
+
+ xbString sSearchKey; /* string for doing an index lookup */
xbInt16 iRc = 0;
xbInt16 iErrorStop = 0;
@@ -53,29 +55,36 @@ int main()
try{
if(( iRc = MyTable->Open( "MyV3Table1.DBF" )) != XB_NO_ERROR ){
- iErrorStop = 1;
+ iErrorStop = 100;
throw iRc;
}
+
#ifdef XB_NDX_SUPPORT
// V3 NDX style indices can be opened manually (vs production MDX index files opened automatically)
+
+
if(( iRc = MyTable->OpenIndex( "NDX", "MYINDEX1.NDX")) != XB_NO_ERROR ){
- iErrorStop = 2;
+ iErrorStop = 110;
throw iRc;
}
+
+
+/*
if(( iRc = MyTable->OpenIndex( "NDX", "MYINDEX2.NDX" )) != XB_NO_ERROR ){
- iErrorStop = 3;
+ iErrorStop = 120;
throw iRc;
}
+
if(( iRc = MyTable->OpenIndex( "NDX", "MYINDEX3.NDX" )) != XB_NO_ERROR ){
- iErrorStop = 4;
+ iErrorStop = 130;
throw iRc;
}
+*/
+
std::cout << "Current tag = [" << MyTable->GetCurTagName().Str() << "]\n";
#endif
-
-
// get the field numbers for all the fields in the table
fld_FIRSTNAME = MyTable->GetFieldNo( "FIRSTNAME" );
fld_LASTNAME = MyTable->GetFieldNo( "LASTNAME" );
@@ -84,189 +93,223 @@ int main()
fld_RETIRED = MyTable->GetFieldNo( "RETIRED?" );
fld_ZIPCODE = MyTable->GetFieldNo( "ZIPCODE" );
+
+
+ // do an index lookup for (key does not exist in this example)
+ sSearchKey = "abc123";
+ if(( iRc = MyTable->Find( sSearchKey )) != XB_NOT_FOUND ){
+ iErrorStop = 140;
+ throw iRc;
+ }
+ std::cout << "RC = " << iRc << "\n";
+
+
+
#ifdef XB_MEMO_SUPPORT
fld_MEMO1 = MyTable->GetFieldNo( "MEMO1" );
#endif
+
// Blank the record buffer
if(( iRc = MyTable->BlankRecord()) != XB_NO_ERROR ){
- iErrorStop = 7;
+ iErrorStop = 140;
throw iRc;
}
+
// put field examples - using field numbers
if(( iRc = MyTable->PutField( fld_LASTNAME, "JONES" )) != XB_NO_ERROR ){
- iErrorStop = 8;
+ iErrorStop = 150;
throw iRc;
}
+
if(( iRc = MyTable->PutField( fld_FIRSTNAME, "JERRY" )) != XB_NO_ERROR ){
- iErrorStop = 9;
+ iErrorStop = 160;
throw iRc;
}
+
if(( iRc = MyTable->PutField( fld_AMOUNT, "12.35" )) != XB_NO_ERROR ){
- iErrorStop = 10;
+ iErrorStop = 170;
throw iRc;
}
if(( iRc = MyTable->PutField( fld_BIRTHDATE, "19880208" )) != XB_NO_ERROR ){
- iErrorStop = 10;
+ iErrorStop = 180;
throw iRc;
}
if(( iRc = MyTable->PutLogicalField( fld_RETIRED, "Y" )) != XB_NO_ERROR ){
- iErrorStop = 11;
+ iErrorStop = 190;
throw iRc;
}
if(( iRc = MyTable->PutLongField( fld_ZIPCODE, 12345 )) != XB_NO_ERROR ){
- iErrorStop = 12;
+ iErrorStop = 200;
throw iRc;
}
#ifdef XB_MEMO_SUPPORT
sMemoData = "Memo data record 1";
if(( iRc = MyTable->UpdateMemoField( fld_MEMO1, sMemoData )) != XB_NO_ERROR ){
- iErrorStop = 13;
+ iErrorStop = 210;
throw iRc;
}
#endif
// Append the first record
if(( iRc = MyTable->AppendRecord()) != XB_NO_ERROR ){
- iErrorStop = 15;
- throw iRc;
+ // here is where you would address any errors.
+ // in this program, we simply abort and continue
+ MyTable->Abort();
}
// put field to the record buffer using field name (slightly less efficient than using field numbers)
-
// Blank the record buffer
if(( iRc = MyTable->BlankRecord()) != XB_NO_ERROR ){
- iErrorStop = 20;
+ iErrorStop = 220;
throw iRc;
}
if(( iRc = MyTable->PutField( "LASTNAME", "EINSTIEN" )) != XB_NO_ERROR ){
- iErrorStop = 21;
+ iErrorStop = 230;
throw iRc;
}
if(( iRc = MyTable->PutField( "FIRSTNAME", "ALBERT" )) != XB_NO_ERROR ){
- iErrorStop = 22;
+ iErrorStop = 240;
throw iRc;
}
if(( iRc = MyTable->PutField( "AMOUNT", "987.55" )) != XB_NO_ERROR ){
- iErrorStop = 23;
+ iErrorStop = 250;
throw iRc;
}
if(( iRc = MyTable->PutField( fld_BIRTHDATE, "19890209" )) != XB_NO_ERROR ){
- iErrorStop = 24;
+ iErrorStop = 260;
throw iRc;
}
if(( iRc = MyTable->PutLogicalField( "RETIRED?", "N" )) != XB_NO_ERROR ){
- iErrorStop = 25;
+ iErrorStop = 270;
throw iRc;
}
if(( iRc = MyTable->PutLongField( "ZIPCODE", 44256 )) != XB_NO_ERROR ){
- iErrorStop = 26;
+ iErrorStop = 280;
throw iRc;
}
#ifdef XB_MEMO_SUPPORT
sMemoData = "Memo data record 2";
if(( iRc = MyTable->UpdateMemoField( fld_MEMO1, sMemoData )) != XB_NO_ERROR ){
- iErrorStop = 27;
+ iErrorStop = 290;
throw iRc;
}
#endif
// Append the second record
if(( iRc = MyTable->AppendRecord()) != XB_NO_ERROR ){
- iErrorStop = 30;
- throw iRc;
+ // here is where you would address any errors.
+ // in this program, we simply abort and continue
+ MyTable->Abort();
}
+
+ if(( iRc = MyTable->GetRecord( 1 )) != XB_NO_ERROR ){
+ iErrorStop = 300;
+ throw iRc;
+ }
// get a field with a field number
- xbString FirstName;
- if(( iRc = MyTable->GetField( fld_FIRSTNAME, FirstName )) < 0 ){
- iErrorStop = 40;
+ xbString sFirstName;
+ if(( iRc = MyTable->GetField( fld_FIRSTNAME, sFirstName )) < 0 ){
+ iErrorStop = 310;
throw iRc;
}
- std::cout << "First Name is [" << FirstName.Str() << "]" << std::endl;
+ std::cout << "First Name is [" << sFirstName.Str() << "]" << std::endl;
- xbString LastName;
- if(( iRc = MyTable->GetField( "LASTNAME", LastName )) < 0 ){
- iErrorStop = 41;
+ xbString sLastName;
+ if(( iRc = MyTable->GetField( "LASTNAME", sLastName )) < 0 ){
+ iErrorStop = 320;
throw iRc;
}
- std::cout << "Last Name is [" << LastName.Str() << "]" << std::endl;
+ std::cout << "Last Name is [" << sLastName.Str() << "]" << std::endl;
xbInt16 iNoOfDecimals;
if(( iRc = MyTable->GetFieldDecimal( "AMOUNT", iNoOfDecimals )) != XB_NO_ERROR ){
- iErrorStop = 42;
+ iErrorStop = 330;
throw iRc;
}
std::cout << "There are " << iNoOfDecimals << " decimals in the AMOUNT field" << std::endl;
xbString FieldName;
if(( iRc = MyTable->GetFieldName( 4, FieldName )) != XB_NO_ERROR ){
- iErrorStop = 43;
+ iErrorStop = 340;
throw iRc;
}
std::cout << "Field #4 name is " << FieldName.Str() << std::endl;
xbString sRetired;
if(( iRc = MyTable->GetLogicalField( "RETIRED?", sRetired )) < 0 ){
- iErrorStop = 45;
+ iErrorStop = 350;
throw iRc;
}
std::cout << "Switch value = [" << sRetired.Str() << "]" << std::endl;
xbInt32 lZip;
if(( iRc = MyTable->GetLongField( "ZIPCODE", lZip )) < 0 ){
- iErrorStop = 46;
+ iErrorStop = 360;
throw iRc;
}
std::cout << "Long value = [" << lZip << "]" << std::endl;
// Initialize the record buffer in preparation for another record
if(( iRc = MyTable->BlankRecord()) != XB_NO_ERROR ){
- iErrorStop = 48;
+ iErrorStop = 370;
throw iRc;
}
// Append another record (it will be blank)
if(( iRc = MyTable->AppendRecord()) != XB_NO_ERROR ){
- iErrorStop = 49;
- throw iRc;
+ // here is where you would address any errors.
+ // in this program, we simply abort and continue
+ MyTable->Abort();
};
- // mark current record for deletion
+ // mark record 1 for deletion
+ if(( iRc = MyTable->GetRecord( 1 )) != XB_NO_ERROR ){
+ iErrorStop = 300;
+ throw iRc;
+ }
+
if(( iRc = MyTable->DeleteRecord()) != XB_NO_ERROR ){
- iErrorStop = 50;
+ iErrorStop = 380;
throw iRc;
};
// save current record
if(( iRc = MyTable->PutRecord()) != XB_NO_ERROR ){
- iErrorStop = 51;
+ iErrorStop = 390;
throw iRc;
}
// pack the table with no options
if(( iRc = MyTable->Pack()) != XB_NO_ERROR ){
- iErrorStop = 52;
+ iErrorStop = 400;
throw iRc;
}
+ if(( iRc = MyTable->Commit()) != XB_NO_ERROR ){
+ // here is where you would address any errors.
+ // in this program, we simply abort and continue
+ MyTable->Abort();
+ }
+
/* Close database and associated indexes */
if(( iRc = MyTable->Close()) != XB_NO_ERROR ){
- iErrorStop = 53;
+ iErrorStop = 410;
throw iRc;
}
@@ -276,7 +319,8 @@ int main()
std::cout << x.GetErrorMessage( rc ) << std::endl;
}
-#endif // XB_DBF3_SUPPORT
+ delete MyTable;
+ #endif // XB_DBF3_SUPPORT
return 0;
}
diff --git a/src/examples/xb_ex_v4_create_dbf.cpp b/src/examples/xb_ex_v4_create_dbf.cpp
index 6169213..d6bfb2f 100755
--- a/src/examples/xb_ex_v4_create_dbf.cpp
+++ b/src/examples/xb_ex_v4_create_dbf.cpp
@@ -2,7 +2,7 @@
XBase64 Software Library
-Copyright (c) 1997,2003,2014,2022 Gary A Kunkel
+Copyright (c) 1997,2003,2014,2022,2023 Gary A Kunkel
The xb64 software library is covered under the terms of the GPL Version 3, 2007 license.
@@ -60,12 +60,12 @@ int main()
xbInt16 iRc;
xbDbf * MyDbfFile;
-
+
#ifdef XB_MDX_SUPPORT
xbIx *pIx;
void *pTag;
#endif // XB_MDX_SUPPORT
-
+
MyDbfFile = new xbDbf4( &x );
if(( iRc = MyDbfFile->CreateTable( "Address.DBF", "Address", MyAddressBookRecord, XB_OVERLAY, XB_MULTI_USER )) != XB_NO_ERROR )
@@ -93,7 +93,8 @@ int main()
}
MyDbfFile->Close(); /* Close database and associated indexes */
+ delete MyDbfFile;
-#endif // XB_DBF4_SUPPORT
+ #endif // XB_DBF4_SUPPORT
return 0;
}
diff --git a/src/examples/xb_ex_v4_upd_dbf.cpp b/src/examples/xb_ex_v4_upd_dbf.cpp
index 75d0641..d128eba 100755
--- a/src/examples/xb_ex_v4_upd_dbf.cpp
+++ b/src/examples/xb_ex_v4_upd_dbf.cpp
@@ -209,7 +209,7 @@ int main()
}
std::cout << "Switch value = [" << sFriend.Str() << "]" << std::endl;
- xbInt32 lZip;
+ xbInt32 lZip = 0;
if(( iRc = MyTable->GetLongField( "ZIPCODE", lZip )) < 0 ){
iErrorStop = 350;
throw iRc;
@@ -259,9 +259,15 @@ int main()
}
// example code to loop through the table
- for( xbUInt32 ul = 1; ul <= MyTable->GetRecordCount(); ul++ ){
+ xbUInt32 ulRecCnt;
+ if(( iRc = MyTable->GetRecordCnt( ulRecCnt )) != XB_NO_ERROR ){
+ iErrorStop = 430;
+ throw iRc;
+ }
+
+ for( xbUInt32 ul = 1; ul <= ulRecCnt; ul++ ){
if(( iRc = MyTable->GetRecord( ul )) != XB_NO_ERROR ){
- iErrorStop = 430;
+ iErrorStop = 440;
throw iRc;
}
// do something with the record here
@@ -271,9 +277,11 @@ int main()
/* Close database and associated indexes */
if(( iRc = MyTable->Close()) != XB_NO_ERROR ){
- iErrorStop = 440;
+ iErrorStop = 450;
throw iRc;
}
+ delete MyTable;
+
}
catch( xbInt16 iRc ){