summaryrefslogtreecommitdiff
path: root/docs/html/xbc12.html
diff options
context:
space:
mode:
Diffstat (limited to 'docs/html/xbc12.html')
-rwxr-xr-xdocs/html/xbc12.html319
1 files changed, 256 insertions, 63 deletions
diff --git a/docs/html/xbc12.html b/docs/html/xbc12.html
index a40c7e0..29d6dc1 100755
--- a/docs/html/xbc12.html
+++ b/docs/html/xbc12.html
@@ -2,85 +2,278 @@
<HTML>
<TITLE>Xbase DBMS Chapter 12</TITLE>
<BODY BGCOLOR=#FFFFFF>
-<H1><p align="center">Record and File Locking</p></H1>
-<p align="center">Chapter Updated 12/13/22</p><hr>
+<H2><p align="center">Dates</p></H2>
+<p align="center">Chapter Updated 04/28/23</p><hr>
-<h3>Locking Overview</h3>
+<br><br>
-Xbase64 supports multi-user processing through file and record locks.
-Record locking restricts multiple cooperating programs from simultaneously
-accessing the same data and corrupting it. Without record and file locking
-in a multi-user environment, simultaneous access to the data and index files
-can cause the files to become inaccurate and unusable.<br><br>
+<h3>Class xbDate methods</h3>
+<table border=1>
+<tr><th>Method</th><th>Description</th></tr>
-Automatic record locking is on by default in the Xbase64 library. To disable it,
-use method xbXBase::DisableDefaultAutoLock() and to enable it, use method xbXBase::EnableDefaultAutoLock().
-<br><br>
-Locking can also be enabled / disabled at the table level with with xbDbf::SetAutoLock().<br><br>
-If autolocking is disabled and the code base is being used in a multi user environment, it is
-up to the application program to verify the needed locks are set as there is no checking or
-setting any locks if autolocking is turned off. It is only safe to turn off the autolocking functionality
-if the library is being used in a single user environment.
-<br><br>
-The current Xbase64 record locking logic is modeled after DBase (tm) V7 locking.
-<br><br>
+<tr><td>xbDate()<br>xbDate( const char * Date8 )<br>xbDate( const xbString &Date8 )<br>xbDate( xbInt32 lJulDate )</td><td>xbDate constructor.</td></tr>
+<tr><td>xbDate( xbUInt16 iInit )</td><td>Special xbDate constructor, called to initialize static variables and/or set to Sysdate</td></tr>
-The locking methods return either XB_LOCK_FAILED or XB_NO_ERROR. If they return
-XB_LOCK_FAILED the actual reason can be found in the global variable
-<em>errno</em> or function <em>perror()</em> can be executed to view the
-results.
-<br><br>
+<tr><td>void operator=( const xbDate &d )</td><td>Set a date equal to another date.</td></tr>
+<tr><td>void operator+=( xbInt32 i )</td><td>Increment a date.</td><tr>
+<tr><td>void operator-=( xbInt32 i )</td><td>Decrement a date.</td><tr>
+<tr><td>void operator++( xbInt32 i )</td><td>Increment a date.</td><tr>
+<tr><td>void operator--( xbInt32 i )</td><td>Decrement a date.</td><tr>
-The errno field may contain one of the following values if the lock was not
-successful.<br><br>
-<TABLE BORDER>
-<TR VALIGN="BASELINE">
-<TR><TH ALIGN="LEFT">Error Code<TD>Description
-<TR><TH ALIGN="LEFT">EBADF<TD>Invalid file descriptor
-<TR><TH ALIGN="LEFT">EINVAL<TD>Invalid lock information or file does not support locks
-<TR><TH ALIGN="LEFT">EACCESS<BR>EAGAIN<TD>Lock can not be set because it is blocked by an existing lock on the file.
-<TR><TH ALIGN="LEFT">ENOLCK<TD>The system is out of lock resources, too many file locks in place.
-<TR><TH ALIGN="LEFT">EDEADLK<TD>Deadlock condition
-<TR><TH ALIGN="LEFT">EINTR<TD>Process was interrupted by a signal while it was waiting
-</TABLE>
-<br><br>
+<tr><td>xbInt32 operator-( const xbDate & ) const</td><td>Determine the number of days between two dates.</td><tr>
+<tr><td>const char * operator-( xbInt32 i )</td><td>Subtract <em>i</em> days from a date.</td><tr>
+<tr><td>const char * operator+( xbInt32 i )</td><td>Add <em>i</em> days to a date.</td><tr>
-<h3>Linux/Windows File Locking Compatibility Issue</h3>
+<tr><td>xbBool operator==( const xbDate & ) const</td><td>Compare for equal dates.</td><tr>
+<tr><td>xbBool operator!=( const xbDate & ) const</td><td>Compare for not equal dates.</td><tr>
+<tr><td>xbBool operator< ( const xbDate & ) const</td><td>Compare for less than date.</td><tr>
+<tr><td>xbBool operator> ( const xbDate & ) const</td><td>Compare for greater than date.</td><tr>
+<tr><td>xbBool operator<=( const xbDate & ) const</td><td>Compare for less than or euql to date.</td><tr>
+<tr><td>xbBool operator>=( const xbDate & ) const</td><td>Compare for greater than or equal to date.</td><tr>
-There is a compatibility locking issue to be aware of. Windows environments allow for the exclusive
-opening of file handles and Linux/Unix platforms do not. If you are writing an application that will be
-using a tool like Dbase on a Windows machine, accessing a file on a Linux/Samba configure machine,
-be aware that the file could be opened in exclusive mode by DBase on the Windows system, and the same file could
-be simultaneously opened with a program on the Unix box. That could cause some issues.
-<br><br>
-In Unix, a program can not lock a file so another process can not access it.<br>
-In Windows, a program can lock a file so another process can not access it.<br>
-DBase(tm) supports routines to open files exclusively, preventing other users from opening a file.<br>
-Locking on the Mac/Apple platform only works on NFS shares. It does not work with SMB shares.
+<tr><td>xbInt16 CalcRollingCenturyForYear( xbInt16 year ) const</td><td>Calculate century for a give 2 digit year. Uses 80/20 method.</td><tr>
+<tr><td>xbInt16 CenturyOf() const</td><td>Return century of the date.</td><tr>
+<tr><td>xbInt16 CharDayOf( xbString &sOutCharDay )</td><td>Retrieve the character day.</td><tr>
+<tr><td>xbInt16 CharMonthOf( xbString &sOutCharMonth )</td><td>Retrive the character month.</td><tr>
+<tr><td>xbBool DateIsValid ( const xbString &sDate8 ) const;</td><td>Check if a given date is valid.</td><tr>
+<tr><td>xbInt16 DayOf( xbInt16 iFormat ) const</td><td>Return Day of week, month or year depending on the option.</td><tr>
+<tr><td>xbInt16 CTOD( const xbString &sCtodInDate )</td><td>Sets the date from input date in format MM/DD/YY</td><tr>
+<tr><td>xbInt16 FormatDate( const xbString &sFmtIn, xbString &sFmtOut )</td><td>Create a formatted date string based on input format.</td><tr>
+<tr><td>const char *Str() const</td><td>Return a pointer the date value.</td><tr>
+<tr><td>xbBool IsLeapYear( xbInt16 iYear ) const<br>IsLeapYear() const</td><td>Returns true if leap year, otherwise returns false.</td><tr>
+<tr><td>xbBool IsNull() const</td><td>Returns xbTrue is the date is null, else returns false.</td><tr>
+<tr><td>xbInt32 JulianDays() const</td><td>Return the Julian days value.</td><tr>
+<tr><td>xbInt16 JulToDate8( xbInt32 lJulDate )</td><td>Convert a Julian date to xbDate value.</td><tr>
+<tr><td>xbInt16 LastDayOfMonth()</td><td>Calculate the last day of a month for the given teat and month.</td><tr>
+<tr><td>xbInt16 MonthOf() const</td><td>Return the numeric month of the date.</td><tr>
+<tr><td>xbInt16 Set( const xbString &Date8 )</td><td>Set the date to valid input date.</td><tr>
+<tr><td>xbInt16 Sysdate()</td><td>Set the date to the system date.</td><tr>
+<tr><td>xbInt16 YearOf() const</td><td>Return the numeric year of the date.</td><tr>
+
+</table>
+
+<br><br><hr><br><br>
+<h2>Example program using xbDate class</h2>
+
+<xmp>
+/* xb_ex_date.cpp
+
+
+XBase64 Software Library
+
+Copyright (c) 1997,2003,2014,2021,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
+
+This program demonstrates using the xbDate class
+
+*/
+
+
+#include "xbase.h"
+
+using namespace xb;
+
+int main()
+{
+
+ xbXBase x; /* initial date static variables */
+
+ xbString StringDate( "19601007" ); /* oct 7 1960 */
+ char CharDate[9] = "19611109"; /* nov 9 1961 */
+
+ xbDate d1; /* today is default */
+ xbDate d2( StringDate ); /* from string data */
+ xbDate d3( CharDate ); /* from char data */
+ xbDate d4; /* another date class */
+ xbString s;
+
+ std::cout << "This program demonstrates usage of the xbDate class" << std::endl;
+ std::cout << "Date 1 (Sysdate) is " << d1.Str() << std::endl;
+ std::cout << "Date 2 (StringDate) is " << d2.Str() << std::endl;
+ std::cout << "Date 3 (CharDate) is " << d3.Str() << std::endl;
+
+ std::cout << "This year is " << d1.YearOf() << std::endl;
+ std::cout << "Year of xbString Date is " << d2.YearOf()
+ << std::endl;
+ std::cout << "Year of char Date is " << d3.YearOf()
+ << std::endl;
+
+ std::cout << "This Month is " << d1.MonthOf() << std::endl;
+ std::cout << "Month of xbString Date is " << d2.MonthOf()
+ << std::endl;
+ std::cout << "Month of char Date is " << d3.MonthOf()
+ << std::endl;
+
+ std::cout << "Today is day " << d1.DayOf( XB_FMT_WEEK ) << " of the week" << std::endl;
+ std::cout << "StringDate is day " << d2.DayOf( XB_FMT_MONTH ) << " of the month" << std::endl;
+ std::cout << "CharDate is day " << d3.DayOf( XB_FMT_YEAR ) << " of the year" << std::endl;
-<br><h3>Samba settings</h3>
+ if( d1.IsLeapYear())
+ std::cout << "This is a leap year" << std::endl;
+ else
+ std::cout << "This is not a leap year." << std::endl;
-If you will be using Samba on Linux/Unix and sharing files between Linux and Windows machines,
-you will need to disable oplocks. In the smb.conf file, set:<br>
-<br>
-[sharename]<br>
-oplocks = False<br>
-level2 oplocks = False
+ if( d2.IsLeapYear())
+ std::cout << "StringDate is a leap year" << std::endl;
+ else
+ std::cout << "StringDate is not a leap year." << std::endl;
+ if( d3.IsLeapYear())
+ std::cout << "CharDate is a leap year" << std::endl;
+ else
+ std::cout << "CharDate is not a leap year." << std::endl;
-<br><h3>iLockFlavor</h3>
+ std::cout << "Today is " << d1.Sysdate() << std::endl;
-The library was constructed in a manner so that it could be updated to support alternate lock "flavors".
-The 4.x.x library is built to mirror the DBase locking, but the structure is in place to expand to other locking
-types if needed.
+ if( d1.DateIsValid( "19951301" ))
+ std::cout << "19951301 is a valid date" << std::endl;
+ else
+ std::cout << "19951301 is not a valid date" << std::endl;
+ if( d1.DateIsValid( "19920229" ))
+ std::cout << "19920229 is a valid date" << std::endl;
+ else
+ std::cout << "19920229 is not a valid date" << std::endl;
+ if( d2.DateIsValid( StringDate ))
+ std::cout << StringDate.Str() << " is a valid date" << std::endl;
+ else
+ std::cout << StringDate.Str() << " is not a valid date" << std::endl;
+ std::cout << "Today's Julian date " << d1.JulianDays() << std::endl;
+ std::cout << "Julian date of Jan 01, 1970 " << d2.JulianDays() << std::endl;
+ std::cout << "StringDate Julian date " << d2.JulianDays() << std::endl;
-<br><br><br>
-<hr><br>
+ std::cout << "There are " << (d1.JulianDays() - d2.JulianDays()) << " days between " << d1.Str() << " and " << d2.Str() << std::endl;
+
+ std::cout << "Todays Julian date (Number of days since Jan 1 0100):" << d1.JulianDays() << std::endl;
+
+ d4 = d1; // set d4 class = to sysdate
+ std::cout << "Object d4 initialized to " << d4.Str() << std::endl;
+ std::cout << "This should be todays date: "
+ << d4.JulToDate8(d4.JulianDays()) << std::endl;
+ std::cout << "In 7 days it will be "
+ << d4.JulToDate8(d4.JulianDays() + 7L ) << std::endl;
+
+ d1.CharDayOf( s );
+ std::cout << "Today is " << s.Str() << std::endl;
+
+ d2.CharDayOf( s );
+ std::cout << "StringDate day is " << s.Str() << std::endl;
+ d1.CharMonthOf( s );
+ std::cout << "This month is " << s.Str() << std::endl;
+ d2.CharMonthOf( s );
+ std::cout << "StringDate month is " << s.Str() << std::endl;
+
+
+ /* various format routines using different formats, strings and chars */
+ xbString sOutDate;
+
+ d1.FormatDate( "YYDDD", sOutDate );
+ std::cout << "Format (YYDDD) = " << sOutDate.Str() << std::endl;
+
+ d1.FormatDate( "MM/DD/YY", sOutDate );
+ std::cout << "Format (MM/DD/YY) = " << sOutDate.Str() << std::endl;
+
+ d1.FormatDate( "YY-MM-DD", sOutDate );
+ std::cout << "Format (YY-MM-DD) = " << sOutDate.Str() << std::endl;
+
+ d1.FormatDate( "DDDDDDDDD, MMMMMMMMMM DD YYYY", sOutDate );
+ std::cout << "Format (DDDDDDDDD, MMMMMMMMMM DD YYYY) = " << sOutDate.Str() << std::endl;
+
+ std::cout << "Last day this month " << d1.LastDayOfMonth() << std::endl;
+ std::cout << "Last day of month for StringDate is " << d2.LastDayOfMonth() << std::endl;
+
+ std::cout << "Overloaded operators test..." << std::endl;
+
+ if( d1 == d2 )
+ std::cout << d1.Str() << " is equal to " << d2.Str()
+ << std::endl;
+ else
+ std::cout << d1.Str() << " is not equal to " << d2.Str()
+ << std::endl;
+
+ if( d1 != d3 )
+ std::cout << d1.Str() << " is not equal to " << d3.Str()
+ << std::endl;
+ else
+ std::cout << d1.Str() << " is equal to " << d3.Str()
+ << std::endl;
+
+ if( d1 < d2 )
+ std::cout << d1.Str() << " is less than " << d2.Str()
+ << std::endl;
+ else
+ std::cout << d1.Str() << " is not less than " << d2.Str()
+ << std::endl;
+
+ if( d1 > d2 )
+ std::cout << d1.Str() << " is greater than " << d2.Str()
+ << std::endl;
+ else
+ std::cout << d1.Str() << " is not greater than " << d2.Str()
+ << std::endl;
+
+ if( d1 <= d2 )
+ std::cout << d1.Str() << " is less than or equal to " << d2.Str()
+ << std::endl;
+ else
+ std::cout << d1.Str() << " is not less than or equal to "
+ << d2.Str() << std::endl;
+
+ if( d1 >= d2 )
+ std::cout << d1.Str() << " is greater than or equal to "
+ << d2.Str() << std::endl;
+ else
+ std::cout << d1.Str() << " is not greater than or equal to "
+ << d2.Str() << std::endl;
+
+ d1.Sysdate();
+ d1++;
+ std::cout << "Tomorrow is " << d1.Str() << std::endl;
+ d1-=2;
+ std::cout << "Yesterday was " << d1.Str() << std::endl;
+ std::cout << "There are " << d1 - d2 << " days between " << d1.Str()
+ << " and " << d2.Str() << std::endl;
+
+ d1="20140701";
+ std::cout << "Operator = example " << d1.Str() << std::endl;
+
+ d1+=5;
+ std::cout << "Operator += 5 example " << d1.Str() << std::endl;
+
+ d1--;
+ std::cout << "Operator -- example " << d1.Str() << std::endl;
+
+ d1-4;
+ std::cout << "Operator -4 example " << d1.Str() << std::endl;
+
+ d1+10;
+ std::cout << "Operator +10 example " << d1.Str() << std::endl;
+ std::cout << "CenturyOf() " << d1.CenturyOf() << std::endl;
+
+ xbString sWorkDate;
+ d1.CTOD( "10/07/60" );
+ std::cout << "CTOD( '10/07/60' ) " << d1.Str() << std::endl;
+
+ d1.Set( "19590118" );
+ std::cout << "Set( '19590118' ) " << d1.Str() << std::endl;
+
+ std::cout << "CalcRollingCenturyForYear( 95 ) = " << d1.CalcRollingCenturyForYear( 95 ) << std::endl;
+ return 0;
+}
+</xmp>
+
+<br><br>
+<hr>
<p><img src="xbase.jpg"><br><hr>
-</BODY>
-</HTML>
+</body>
+</html>