Program techniques : change indexorder or use aliases

Program techniques : change indexorder or use aliases

Postby Marc Venken » Mon Nov 02, 2020 3:15 pm

I wonder what the best technique would be and the advantages of 1 of the 2

Often, I need to use the same database in more than one lookup action or update action.

1. I can change the index order, but than I also have to keep track of resetting it back and at the correct position
2. I can open de database in more aliases and use different browses and lookups with these aliases ?? Can I get issues with the CDX file ?

And we can use Oop (James), smaller parts are converted somethimes in this way.
But just out of interest... witch is used more often here ( 1 or 2) ?

In 1 : The first time, sometimes is with a relation set to ... , and when the database order is changed, the relation is broken. (I believe this is standard in FW)
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1429
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Program techniques : change indexorder or use aliases

Postby Enrico Maria Giordano » Mon Nov 02, 2020 5:43 pm

Marc Venken wrote:But just out of interest... witch is used more often here ( 1 or 2) ?


Personally, I'm using both, depending on the specific situation.

Marc Venken wrote:In 1 : The first time, sometimes is with a relation set to ... , and when the database order is changed, the relation is broken. (I believe this is standard in FW)


No, it is standard in xBase languages.

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

Re: Program techniques : change indexorder or use aliases

Postby James Bott » Mon Nov 02, 2020 7:31 pm

Marc,

You gave me a laugh when I saw your message directed at me-you knew I would say OOP. Good, at least you remember.

Note that back in Clipper era with 16bit computers without much memory we were limited as to how many files we could have open at one time. This rarely an issue now. so you can open as many files as you need usually. You will, however, run into speed issues when the PC has limited RAM.

OOP databases open a new copy of a database each time they are initiated. So you may have several copies of the same database open at once.

oCustomer1:= TCustomer():new()
oCustomer2:= TCustomer():new()

Without using OOP, if you try to open one database and use it in several routines by passing it around, then you are going to have to save and restore it's state in each routine that changes the state. That means index , index order, current recno, filter, relation, etc. I tried this once but it was way too complicated.

With OOP, it just takes one line of code to open a new copy of a database--and no save and restore needed. Actually, it could be more than one database, for instance with a sales order object. You have a customer, invoice header and invoice line items databases, and two of them are related. Still one line of code to open it:

oSalesOrder:= TSalesOrder():new()

James

Simplicity is the ultimate sophistication. ~Leonardo DaVinci
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Program techniques : change indexorder or use aliases

Postby nageswaragunupudi » Tue Nov 03, 2020 12:44 pm

This is easy
2. I can open de database in more aliases and use different browses and lookups with these aliases ?? Can I get issues with the CDX file ?

No problems.
Regards

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

Re: Program techniques : change indexorder or use aliases

Postby Marc Venken » Wed Nov 04, 2020 11:30 am

* New: function FW_DBFLOOKUP( uVal, [cOrder], bcRetExprn ) --> uResult
uVal : Value / Expression to be lookedup ( seek or locate )
cOrder : OrderName for seek. Or field name for locate. Omit if uVal
is an expression
bcRetExpr: codeblock/string: Expression to evaluate
Examples:
CUSTOMER->( FW_DBFLOOKUP( 108, "ID", "AGE" ) ) --> nAge of ID 108
CUSTOMER->( FW_DBFLOOKUP( 99, "ID", "FIELD->SALARY += 100" ) ) -->
Salary field is incremented and written to table and returns the value
ITEMS->( FW_DBLOOKUP( 101, "ITEMCODE", { || FIELD->QTY -= nOldQty } )
ITEMS->( FW_DBLOOKUP( 103, "ITEMCODE", { || FIELD->QRY += nNewQty } )
STATES->( FW_DBLOOKUP( 10, 0, "FIELD->NAME" ) ) // at recno 10
Original recno() and order are restored and any previous locks are
left intact before returning.
Reurn value NIL indicates failure
source: \fwh\function\dbffuns2.prg


ITEMS->( FW_DBLOOKUP( 101, "ITEMCODE", { || FIELD->QTY -= nOldQty } )
ITEMS->( FW_DBLOOKUP( 103, "ITEMCODE", { || FIELD->QRY += nNewQty } )

This function handles also everything not ?? (no need to extra open the dbf in a new alias)

This sample in use with a bchange function call from Xbrowse should work not ? (will test it later)

ITEMS->( FW_DBLOOKUP( obrw:code:value, "ITEMCODE", { || FIELD->GROEP = oBrw:groep:value } ) )

I suppose that we can also change more than one item with this code ? { || FIELD->GROEP = oBrw:groep:value, FIELD->DATE = date() } or maybe better call a function and change the data insite the function ?

This function supposes that the file is already open... Can we also let it open the dbf when it is not yet open before calling the function ?
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1429
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 86 guests