FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Is this Netopen function from 16 bit ok for FWH32 ?
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Is this Netopen function from 16 bit ok for FWH32 ?
Posted: Fri Sep 22, 2017 12:58 PM
Hello,

In my project of converting from 16 bit to FWH, i need to change all my Ntx and partial COMIX files to CDX FWH.

I have the folowing code for opening files in FW16 :

Is this code still a good code, (change the COMIX to CDX...) or should I find a better one that uses more of FWH Power.

Maybe someone can share his code to open in network situation ?

At this point, I want to convert strait from 16 to 32. Later I could change to Objects, or other options.

Thanks.


Code (fw): Select all Collapse
FUNCTION NETOPEN( cFile, lMode, cAlias, nSeconds, lNewArea,cDriver, lReadOnly )
local nWaitTime, lContinue := .t., lSuccess  := .f., TSEL      := 0

DEFAULT lMode     :=  .T.                     // shared mode
DEFAULT nSeconds  :=  3
DEFAULT cAlias    := cFile
DEFAULT lNewArea  :=  .t.
DEFAULT cDriver   := "COMIX"
//DEFAULT cDriver   := "DBFNTX"
DEFAULT lReadOnly :=  .f.
nWaitTime := nSeconds

// bestand het bestand
IF ! FILE( cFile + ".DBF" )
   Exit("Bestand " + CFILE + ".DBF is afwezig")
ENDIF
// verify driver is valid
if ascan( RddList(), cDriver ) == 0
   MSGSTOP("Driver " + Cdriver + "  afwezig")
   Exit()
endif
//
// Indien reeds geopend, alles ok, select waar
//
IF SELECT(cAlias) # 0
   MsgInfo("File was reeds geopend")
   TSEL := SELECT(cAlias)
   SELECT(TSEL)
   lContinue := .t.
   lNewArea  := .f.
ENDIF
// while continuing to attempt open
Do while lContinue // while .not. timed-out
   while nSeconds > 0 .and. lContinue
     //dbUseArea( lNewArea, cDriver, cFile, cAlias, ( .not. lMode ), lReadOnly )
     dbUseArea( lNewArea, cDriver, cFile, cAlias, lMode, lReadOnly )
     // check for success/failure
     IF neterr()
       nSeconds--
       lSuccess  := .F.
      else
       // open successful
       nSeconds  := 0
       lSuccess  := .t.
       lContinue := .f.
     ENDIF
  ENDDO
  IF ! lSuccess
      nSeconds  := nWaitTime
      MSGSTOP("Bestand " + CFILE+" Alias : "+cAlias + " is geopend door een andere gebruiker" + CRLF + CRLF + "Gelieve even te wachten")
      lSuccess   := .F.
      lContinue  := .T.
      lNewArea   := .T.
  ENDIF
ENDDO

return lSuccess
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Is this Netopen function from 16 bit ok for FWH32 ?
Posted: Fri Sep 22, 2017 01:49 PM
Marc

This User Defined Function has served me well .. the rdd is set for DbfCdx

Rick Lipkin

Code (fw): Select all Collapse
/* LOGICAL NETUSE( CDATABASE, LOPENMODE, NSECONDS )

  CHARACTER CDATABASE      - NAME OF DATABASE
  LOGICAL LOPENMODE        - OPEN MODE .T. exclusive  .F. shared
  NUMERIC NSECONDS         - NUMBER OF SECONDS TO WAIT  0 forever

  RETURN  .T. if successful,  .F. if not

  SAMPLE CALL  IF NETUSE( "CALLS.DBF", .F., 5 )  // you may need to use the full path and location to open the .dbf
*/
//------------------------------
Func NETUSE( CDATABASE, LOPENMODE, NSECONDS )

LOCAL FOREVER, RESTART, WAIT_TIME, YESNO

RESTART := .T.
FOREVER := ( NSECONDS = 0 )
YESNO   := {"Yes" , "No"}

DO WHILE RESTART

   WAIT_TIME := NSECONDS

   DO WHILE ( FOREVER .OR. WAIT_TIME > 0 )

      IF LOPENMODE
         USE ( CDATABASE ) via "DBFCDX" EXCLUSIVE
      ELSE
         USE ( CDATABASE ) via "DBFCDX" SHARED
      ENDIF

      IF .NOT. NETERR()
         RETURN(.T.)
      ENDIF
      INKEY(1)
      WAIT_TIME--

   ENDDO

   * lock failed, ask to continue

   IF MsgYesNo( "Cannot lock " + CDATABASE + ", retry ?" )
   ELSE
      EXIT
   ENDIF

ENDDO

RETURN(.F.)
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Is this Netopen function from 16 bit ok for FWH32 ?
Posted: Fri Sep 22, 2017 04:29 PM

I use CDX, and tData ( Database objects ). I haven't worried about network locking in YEARS ... it should all be automatic. It's also a lot simpler. ALL of my installs are networked.

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Is this Netopen function from 16 bit ok for FWH32 ?
Posted: Fri Sep 22, 2017 06:48 PM
TimStone wrote:I use CDX, and tData ( Database objects ). I haven't worried about network locking in YEARS ... it should all be automatic. It's also a lot simpler. ALL of my installs are networked.


I totaly agree.. I have more than once talked with James, and got a lot of info, and I'm convinced about Objects. I even use them i smaller apps, but for my bigger program, I first need to get it going in FWH.
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Is this Netopen function from 16 bit ok for FWH32 ?
Posted: Sun Sep 24, 2017 02:04 PM

Marc

Along the subject Tim brings up ... you might want to consider moving to the Ado Class and Methods.

https://docs.microsoft.com/en-us/sql/ad ... object-ado

Benefits:

1) Ado oRs code is the same whether you use Ms Sql Server, Ms Access or Oracle .. MySql and MariaDB are similar.
2) Ado leverages Opportunistic Locking where as .DbfCdx has documented Opportunistic Locking performance issues in a Mult-User network environment
3) Ado allows Ms Access and Ms Sql server to share ( virtually ) the same code .. just change the connection string.
4) Modern SQL code is very desirable with many CIO's

It sounds like you are on the verge of a major re-write anyway ... please have a look at the sample AdoRick.Prg .. a good example on how to start using Ado and MS Access .. also on how to implement increment filtering ..

Rick Lipkin

ps .. I thought you were using Ado already in some of your other projects ?

Continue the discussion