dbseek

dbseek

Postby Silvio.Falconi » Thu Jan 29, 2015 10:56 am

I not understood a command on old clipper source I must converte I found

OR->(dbSeek(Str(DO->(RecNo()), 3)))

the Od dbf id index on a field numeric 3 N (prof)

Question : the recno() is allways a number or on old clipper could be also a string ?

and then I have

while (or->prof == DO->(RecNo()))

but == is wrong ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6796
Joined: Thu Oct 18, 2012 7:17 pm

Re: dbseek

Postby Enrico Maria Giordano » Thu Jan 29, 2015 11:06 am

Silvio.Falconi wrote:Question : the recno() is allways a number or on old clipper could be also a string ?


No, it's always been a number.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8332
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: dbseek

Postby Silvio.Falconi » Thu Jan 29, 2015 11:42 am

but on dos run ok how it is possible ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6796
Joined: Thu Oct 18, 2012 7:17 pm

Re: dbseek

Postby Silvio.Falconi » Thu Jan 29, 2015 11:49 am

perhaps I resolve ... on dos I saw the index is another
INDEX ON str(PROF,3)+upper(CLASSE)+upper(GG_ORA)+ORESEQ)

in this case the expression OR->(dbSeek(Str(DO->(RecNo()), 3))) is right ?
also this while (or->prof == DO->(RecNo()))
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6796
Joined: Thu Oct 18, 2012 7:17 pm

Re: dbseek

Postby James Bott » Thu Jan 29, 2015 3:12 pm

Silvio,

in this case the expression OR->(dbSeek(Str(DO->(RecNo()), 3))) is right ?


Don't confuse the valtype of recno() with the use of str(recno()) to do a seek on an index.

I admit this is some very strange programming--I have never seen anything like it. Either the original programmer is brilliant, or very confused--I'm not sure which.

Only on very rare occasions do I use recno() for anything, and I can't ever remember using it in an index.
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: dbseek

Postby Silvio.Falconi » Sat Jan 31, 2015 10:58 am

the app use the search on numberof recno in two database
it open teacher .dbf and make a loop
it take the number od REcno on teacher.dbf first and then try to search this code number on another dbf Orario.dbf where is a field numeric with the number of recno od teacher
on 1992 on clipper on dos it runned good . now I can modify it but I must undestood how I made it first
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6796
Joined: Thu Oct 18, 2012 7:17 pm

Re: dbseek

Postby James Bott » Sat Jan 31, 2015 6:13 pm

The problem with recno() is that these values change when records are deleted and the file packed. I would never use recno. Create an ID field instead. I almost always create an sequential ID field as the number one field. This is the primary key. The only exception is files used for one-to-many relationships.

It is a good system that has never failed me.

A system using recno() as the primary key is going to fail miserably on you eventually.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: dbseek

Postby nageswaragunupudi » Sun Feb 01, 2015 12:58 am

The problem with recno() is that these values change when records are deleted and the file packed. I would never use recno. Create an ID field instead. I almost always create an sequential ID field as the number one field. This is the primary key.

This is a universally accepted good practice.
Now DBFCDX provides *safe* autoinc field by specifying field type as '+' instead of 'N'

The only exception is files used for one-to-many relationships.

Even here we can continue to follow the same rule of unique primary key. Another field will contain non-unique values of parent-id. This is generally known as foreign-key.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10254
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: dbseek

Postby James Bott » Sun Feb 01, 2015 5:47 pm

Nages,

Now DBFCDX provides *safe* autoinc field by specifying field type as '+' instead of 'N'


Wow, that's news to me. This is a great feature. Is the value inserted numeric or string? I always use a string for easy formatting.

Why did you star "safe?"

I wrote a database sub-class to add auto-incrementing. Maybe now I won't need it.

Why would you need a unique primary key for a one-to-many table?

One-to-many tables are usually contain non-unique values in both fields. For instance let's say you have a customer file and you want to have six phone numbers available. You could add six phone number fields, but most of them would remain empty. And as soon as you run into a situation where a customer has 7 phones then you have to restructure the customer file.

If you use a one-to-many relationship, you create a file with two fields, custno, and phone. You can have an unlimited number of phones for each customer.

CUSTNO, PHONE
01111, 124-9999
01111, 124-9995
01112, 678-0000

In this example the phone number field contains unique numbers, but only because the phone system requires it. If the field contained, say, computers owned by make and model, then they could be non-unique.

Certainly you could add a primary key field, but I have never needed one. Or, maybe I'm not understanding what you are saying?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: dbseek

Postby Enrico Maria Giordano » Sun Feb 01, 2015 6:01 pm

James,

James Bott wrote:Why would you need a unique primary key for a one-to-many table?


Essentially, a table needs a unique primary key for record identity purpose.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8332
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: dbseek

Postby Silvio.Falconi » Mon Feb 02, 2015 10:52 am

Now I have another problem with Dbseek

I have Orario.dbf and some index ( i use cdx) with 992 records


USE ORARIO ALIAS OR
INDEX ON OR->PROF TAG ORARIO1 TO ORARIO
INDEX ON (str(PROF,3)+upper(CLASSE)+upper(GG_ORA)+ORESEQ) TAG ORARIO2 TO ORARIO
INDEX ON (upper(OR->CLASSE)+upper(OR->GG_ORA)) TAG ORARIO3 TO ORARIO


tha function I need I used to control if a classrom is free or not

the search is on the same file
the function search the classroom sample "1A" + the day and Hour sample "11"

for a sample :

id found "1A11" then return .T. ( classroom is occupated)


I think it can be only one record with the same "1A11" it is possible have two or many records with the same code

Code: Select all  Expand view
# include "Fivewin.ch"


Function test()
Local ngiorno
local nOra
Local nGiornoOra

USE ORARIO ALIAS OR
INDEX ON OR->PROF TAG ORARIO1  TO ORARIO
INDEX ON (str(PROF,3)+upper(CLASSE)+upper(GG_ORA)+ORESEQ) TAG ORARIO2  TO ORARIO
INDEX ON   (upper(OR->CLASSE)+upper(OR->GG_ORA)) TAG ORARIO3  TO ORARIO

 or->(dbSetOrder(1))

 OR->(dbGoTop())

 Do While .not. or->(eof())
           for ngiorno= 1 to 6
              for nOra:=1 to 6
                  nGiornoOra := str(ngiorno,1)+str(nOra,1)

                 If CLASSELIB(1, ngiorno, nOra)
                       or->gg_ora:=  nGiornoOra
                       or->blocco:= "*"
                     exit
                  exit
                Endif
               next
            next

             OR->(dbskip())
         Enddo

            return nil




 function CLASSELIB(num, ngiorno, nOra)

     nclasse:= or->classe
     nRecord:= or->(RecNo())
     Local3:= 1

      or->(dbSetOrder(3))
      OR->(dbGoTop())

   for n= 0 to num - 1
      if (or->(dbSeek(nclasse + Str(ngiorno, 1) + iif(nOra + n ;
            == 10, "0", Str(nOra + n, 1)))))
         or->(dbSetOrder(1))
         or->(dbGoto(nRecord))
         return .F.
      endif

   next

   or->(dbSetOrder(1))
   or->(dbGoto(nRecord))
   return .T.
 




it is possible it found many records because there are teachers have some hour on a classroom with different materia


Image


How I can resolve ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6796
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 20 guests