Re: [Harbour] DBSEEK()

2009-12-30 Thread Przemysław Czerpak
On Tue, 29 Dec 2009, Mindaugas Kavaliauskas wrote:

Hi,

 It's defined indirectly by dynamic descend flag which causes
 that seek last should work like in Harbour native RDDs and
 CL53/COMIX. In such implementation seek last is fully revertible
 by switching to descending order ( ordDescend(,,!ordDescend()) )
 and forward seek. Otherwise we will have some anomalies.
 Ok, if understand the idea of seeklast now, then it means try doing
 seek backward (in reversed index order, like using DESCEND), but
 not return the last record (having maximal recno value) of the
 records having the same key value.

Too much complicated for me ;-)
I rather suggest you to think about functionality. This code:

   dbSeek( dtFirst, .T., .F. )
   while field-DATE = dtLast .and. !EOF()
  [...]
  dbSkip( 1 )
   enddo

should scan the same record set as this code:

   dbSeek( dtLast, .T., .T. )
   while field-DATE = dtFirst .and. !BOF()
  [...]
  dbSkip( -1 )
   enddo

and this also precisely defines which record should be chosen
when the exact key does not exists and for soft seek last.

 But ADS still have bug in the first test. If softseek positions at
 EOF seeklast does not help to stop on last record. Here is the test
 indicating both correct (in some cases) and wrong (in another cases)
 behavior of ADS:

Yes, and your patch is correct though probably we can remove
AdsAtEOF() checking and always call:
   u32RetVal = AdsSkip( pArea-hOrdCurrent, -1 );
I also suggest to store in u32RetVal AdsSeek() and AdsSeekLast() results
and move:
   if( u32RetVal != AE_SUCCESS )
   {
  commonError( pArea, EG_CORRUPTION, ( HB_ERRCODE ) u32RetVal, 0, NULL, 
EF_CANDEFAULT, NULL );
  return HB_FAILURE;
   }
to always generate RTE also when AdsSeek*() fails.
Please only check the AdsSeek*() results for empty ADT and DBF tables.

best regards,
Przemek
___
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour


[Harbour] DBSEEK()

2009-12-29 Thread Mindaugas Kavaliauskas

Hello,


I have a question/discussion about DBSEEK(). I've started from the 
different ADSCDX and DBFCDX behavior and later included Clipper tests.


#ifdef __HARBOUR__
REQUEST ADSCDX
#endif
REQUEST DBFCDX
FIELD F

FUNC main(cADS)
  IF EMPTY(cADS)
RDDSETDEFAULT(DBFCDX)
  ELSE
RDDSETDEFAULT(ADSCDX)
  ENDIF
  ? VERSION(), RDDSETDEFAULT()

  DBCREATE(test187, {{F, N, 5, 0}},, .T.)
  OrdCreate(test187, f, F)
  DBAPPEND();  F := 1

  DBSEEK(10, .T., .F.)
  ? RECNO()
  DBSEEK(10, .T., .T.)
  ? RECNO()
  DBCLOSEALL()
RETURN 0

The code above prints:
C:\cawi32\sample\testtest187.exe

Harbour 2.0.0 (Rev. 13372) DBFCDX
 2
 1
C:\cawi32\sample\testtest187.exe xxx

Harbour 2.0.0 (Rev. 13372) ADSCDX
 2
 2
C:\cawi32\sample\testtest187.exe

Clipper (R) 5.2e Intl. (x216)  (1995.02.07) DBFCDX
  2
  2

So, I looks like Harbour's DBFCDX is wrong and ADSCDX is OK, but my 
co-worker said, that Clipper has bugs in softseek. I've tried another test:


REQUEST DBFCDX
#ifdef __HARBOUR__
REQUEST ADSCDX
#endif
FIELD F

PROC main(cADS)
  IF EMPTY(cADS)
RDDSETDEFAULT(DBFCDX)
  ELSE
RDDSETDEFAULT(ADSCDX)
  ENDIF
  ? VERSION(), RDDSETDEFAULT()
  DBCREATE(test188, {{F, N, 5, 0}},, .T.)
  OrdCreate(test188, f, F)
  DBAPPEND();  F := 1
  DBAPPEND();  F := 1
  DBAPPEND();  F := 3
  DBAPPEND();  F := 3
  DBSEEK(2, .T., .F.)
  ? RECNO()
  DBSEEK(2, .T., .T.)
  ? RECNO()
  DBCLOSEALL()
RETURN

It prints:
C:\cawi32\sample\testtest188.exe

Harbour 2.0.0 (Rev. 13372) DBFCDX
 3
 2
C:\cawi32\sample\testtest188.exe xxx

Harbour 2.0.0 (Rev. 13372) ADSCDX
 2
 2
C:\cawi32\sample\testtest188.exe

Clipper (R) 5.2e Intl. (x216)  (1995.02.07) DBFCDX
  5
  5

So, we have a different behavior for all of RDD's, and I seems Clipper 
ignores softseek at all.



From a printed (CL53) reference guide vol.1 page 2-315 I can read: 
lLast is specified as true (.T.) to seek the last occurence of the 
specified key value. , but it is not clear how it works if specified 
key does not exists. I can also read on the same page: ... for a soft 
seek, the work area is positioned to the first record whose key value is 
greater than the specified key value. If no such record exists, the work 
area is positioned to LASTREC() + 1 and EOF() returns true (.T.).


So, in the latter sample (test188) I would expect:
3
4
but not any of the above results from various tests.

*** So, how soft seek and last seek should work? ***

The question becomes even more complicated if think about DESCENT index.



Regards,
Mindaugas
___
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour


Re: [Harbour] DBSEEK()

2009-12-29 Thread Mindaugas Kavaliauskas

Hi, Przemek,


I've made fixed in my SVN copy, but I see you comment in ADSRDD code 
related to the subject, so, please verify, that fix is OK.



Index: C:/harbour/contrib/rddads/ads1.c
===
--- C:/harbour/contrib/rddads/ads1.c(revision 13378)
+++ C:/harbour/contrib/rddads/ads1.c(working copy)
@@ -1072,13 +1072,14 @@

  AdsAtEOF( pArea-hTable, u16Eof );
  if( !u16Eof )
+u32RetVal = AdsSkip( pArea-hOrdCurrent, -1 );
+ else
+u32RetVal = AdsGotoBottom( pArea-hOrdCurrent );
+
+ if( u32RetVal != AE_SUCCESS )
  {
-u32RetVal = AdsSkip( pArea-hOrdCurrent, -1 );
-if( u32RetVal != AE_SUCCESS )
-{
-   commonError( pArea, EG_CORRUPTION, ( HB_ERRCODE ) 
u32RetVal, 0, NULL, EF_CANDEFAULT, NULL );

-   return HB_FAILURE;
-}
+commonError( pArea, EG_CORRUPTION, ( HB_ERRCODE ) 
u32RetVal, 0, NULL, EF_CANDEFAULT, NULL );

+return HB_FAILURE;
  }
   }
}


I also attach extended test code. It includes also test for the 
seeksoft/seeklast in the beginning of index.



Regards,
Mindaugas


REQUEST DBFCDX
#ifdef __HARBOUR__
REQUEST ADSCDX
#endif
FIELD F

PROC main(cADS, cLocal)
  IF EMPTY(cADS)
RDDSETDEFAULT(DBFCDX)
  ELSE
#ifdef __HARBOUR__
RDDSETDEFAULT(ADSCDX)
AdsSetServerType(IIF(EMPTY(cLocal), 2, 1))
#endif
  ENDIF
  ? VERSION(), RDDSETDEFAULT()
  DBCREATE(test188, {{F, N, 5, 0}},, .T.)
  OrdCreate(test188, f, F, {|| F})
  DBAPPEND();  F := 1
  DBAPPEND();  F := 1
  DBAPPEND();  F := 3
  DBAPPEND();  F := 3
  DBSEEK(2, .T., .F.);  ? RECNO()
  DBSEEK(2, .T., .T.);  ? RECNO()
  DBSEEK(9, .T., .F.);  ? RECNO()
  DBSEEK(9, .T., .T.);  ? RECNO()
  DBSEEK(0, .T., .F.);  ? RECNO()
  DBSEEK(0, .T., .T.);  ? RECNO()
  DBCLOSEALL()
RETURN
___
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour


[Harbour] DbSeek() Problem with latest SVN

2009-11-08 Thread Mario H. Sabado

Hi Przemek,

I had encountered problem with the latest SVN with DbSeek(). It always 
return .F. in my case after reindexing and re-creating index.   I'm 
using DBFNTX and BCC62 under WinXP SP3. 


Thanks for any advise.

Best regards,
Mario
___
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour