Improvement to DBFs management ...

Improvement to DBFs management ...

Postby Rimantas » Tue Oct 06, 2009 3:52 pm

Hi ,

That it's discussion ... :) . The main problem with DBFs is working in MDI enviroment . Lets say in sample :

- open "sales" windows with sales table . All is OK ;
- then open other window - "invoices" . Here is and orders from "sales" ;
I'm using research techique in browse - in column codeblock exist something like that -
{ || m_search( "SALES", ( cInvcAls )->sales_Id, "SALES_ORDER" ) ) } .
This is returning sales order and this works very fine and quick .
- Lets direct focus to the first opened - "sales" - mdi child window . Then you will see that
now you are on other record of sales orders , not that you leaved before opening "invoices" .

This isn't a big problem . But undoubt ... :) . I'm using one alias - "sales" in all program parts . I know , that I can open the same table with many alias names . Maybe that it's the most easy way - in the main of "sales" open in other alias , "sales_main" for sample , in other parts I can use as "sales" alias . But maybe exist other possibilities - to avoid such situations as I described . Any comments and advice are welcome ! :-)

What is influence for program ( or PC memory and etc. ) of opening the same table in some alias ? If I will open 25 tables in double amount of alias ? If influence isn't a big , maybe it will be the easest way to solve this small problem ... :)

With best regards !
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: Improvement to DBFs management ...

Postby Gale FORd » Tue Oct 06, 2009 4:38 pm

I tried to keep track of record #, filter, scope, index order, etc but finally gave up. The repainting windows really messes it up.
Now I use files with new alias names and it works pretty good.

Here is my routine.
Code: Select all  Expand view


function test
   Local cAlias
   if OpenMyFile("filename", @cAlias)
      ordsetfocus( "mytag" )
   else
      break
   endif
   ...
   ? ( cAlias )->field1
   dbselectarea( cAlias)
return( nil )

Function OpenMyFile( cFile, cAlias, lExclusive)

   local nPos := 0
   local cAlias := ""
   local nCount := 0
   local cTest
   local lReturn := .f.

   nPos := at(".", cFile)

   if nPos > 0
      cAlias := left(cFile, nPos - 1)
      cAlias := left(cFile, max(len(cAlias), 8))
   else
      cAlias := cFile
   endif

   cTest := cAlias+padl(ltrim(strzero(nCount, 3)), 3, "0")
   while select(cTest) > 0
      nCount++
      cTest := cAlias + padl(ltrim(strzero(nCount, 3)), 3, "0")
   enddo

   cAlias := cTest

   lReturn := netuse( cFile, lExclusive,,, cAlias )
   // use (cFile) shared new alias (cAlias)
   //return NetErr()

return( lReturn )
 
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Improvement to DBFs management ...

Postby alvaro533 » Tue Oct 06, 2009 4:41 pm

Hi Rimantas, I use this. This way each mdi windows opens a different area. You keep the name of the area in a variable (cAlias)
Alvaro

Code: Select all  Expand view

static function myfunction()
local cAlias
local nSele:= select()

use sales new  index sales alias (cAlias:=getnewalias("sales"))

(cAlias)->sales_id:= 34
etc.. browse, etc.


select(cAlias)  // not select("cAlias")

(cAlias)->( dbclosearea() )

select(nSele)
return nil

//----------------------------------------------------------------------------//

function GetNewAlias( cDbfName )

   static n := 0

   return subs(cDbfName,1,3) + StrZero( ++n, 5 )

 
alvaro533
 
Posts: 206
Joined: Sat Apr 19, 2008 10:28 pm
Location: Madrid, España

Re: Improvement to DBFs management ...

Postby Otto » Tue Oct 06, 2009 5:04 pm

Rimantas, have a look at TData from James.

This handles all for you.

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6329
Joined: Fri Oct 07, 2005 7:07 pm

Re: Improvement to DBFs management ...

Postby Rimantas » Tue Oct 06, 2009 5:20 pm

Thanks for all answers ! It seems that replication of alias it's the most easy way ... :) . I'll use yours suggestions and samples .

Regards !
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: Improvement to DBFs management ...

Postby hmpaquito » Tue Oct 06, 2009 8:10 pm

Code: Select all  Expand view
 
Rimantas wrote:Thanks for all answers ! It seems that replication of alias it's the most easy way ... :) . I'll use yours suggestions and samples .

Regards !



Rimantas,

Would you like to management dbfs than rdbms big databases?
Here you are:


Code: Select all  Expand view

***************************************************************
// WorkSpac.Ch
//
//
**************************************************************

#Translate DEFINE WORKSPACE <oWS> => ;
                  <oWS>:= TWorkSpace():New()


#Define NO_PATHBLOCK NIL


// Si no se pasa path ni empresa asume la empresa actual
#Translate USE WORKAREA IN WORKSPACE <oWS> ;
          [PATH          <cPath>    ]      ;    // Normalmente NO SERA NECESARIO pasar el path !!
           FILES          <xFiles>         ;   // Nombres fichero en disco con o sin extension (hacer tratamiento para cuendo lleva extension pq puede no ser .dbf)
          [ALIAS         <xAliasExterno> ] ;   // Por si varios con mismo nombre fichero; ademas deberia se obligatorio cuando FILE sea una variable (no una constrante entrecomillada)
          [EXCLUSIVE     <lExclusive> ]      ;
          [PRE_OPEN      <lPreOpen> ]      ;  
          [FILTER        <bFilter>  ]      ;   // Para luego poderse quitar y restaurar.
          [OPEN_INDICES  <lOpenInd> ]      ;   // Abrir indices si/no
          ;
          [TO <lOk>]                   ;        // Solo tiene sentido cuando sea PRE_OPEN
          ;
          ;
          ;
          ;
          ;
          ;
          => ;
             ;
          [<lOk>:=] <oWS>:AddWorkArea(<cPath>, NO_PATHBLOCK, <xFiles>, <xAliasExterno>, <lExclusive>, <lPreOpen>, <bFilter>, <lOpenInd>, NIL, NIL, <cCodEmp>, NIL, <lEmpresaAsociada>)


*
***********************************************************************
// WorkSpac.Prg
//
*************************************************************************
#Include "FiveWin.Ch"


STATIC nCountWorkSpaces:= 0





#Define PARAM_AWA cPath, bPath, xFiles, xAliasExterno, lExclusive, lPreOpen, bFilter, lOpenInd, lDeGestion, lDeConta, cCodEmp, lEmpresaActual, lEmpresaAsociada
#Define PARAMETROS_TODOS ;
                         PARAM_AWA, cAliasReal, lOpen, cFile, cAliasExterno, cCodEmpCambiado


// Aqui la declaracion de PARAMETROS_TODOS
#Define POS_cPath          01
#Define POS_bPath          02
#Define POS_xFiles         03
#Define POS_xAliasExterno  04
#Define POS_lExclusive     05
#Define POS_lPreOpen       06
#Define POS_bFilter        07
#Define POS_lOpenInd       08
#Define POS_lDeGestion     09
#Define POS_lDeConta       10
#Define POS_cCodEmp        11
#Define POS_lEmpresaActual 12
#Define POS_lEmpresaAsociada 13
#Define POS_cAliasReal     14
#Define POS_lOpen          15
#Define POS_cFile          16
#Define POS_cAliasExterno  17
#Define POS_cCodEmpCambiado   18



*********************************************************************
// Ejemplo de manejo.
FUNCTION WSSample()
Local oRdbms

   DEFINE WORKSPACE oRdbms


   USE WORKAREA IN WORKSPACE oRdbms ;
       PATH "Data" ;
       FILES {"File1", "File2", "File3"}

   

   oRdbms:Activate()


   oRdbms:End()





RETURN NIL




//--------------------------------------------------------------------------//
CLASS TWorkSpace



   METHOD New()
   METHOD Activate()
   METHOD End()
   METHOD AddWorkArea()

   METHOD OpenFile()    HIDDEN
   METHOD OpenNoOpen()  HIDDEN     // Abre los que queden sin abrir


   // Para trabajar con los alias
   DATA oAlias          READONLY

   // Contiene todas las areas. Se movera al unisono con oAlias.
   DATA aAreasInfo      HIDDEN

   DATA nCountWorkAreas HIDDEN INIT 0

   METHOD CloseAll()    HIDDEN

   METHOD SelectArea(nOrdenApertura) INLINE dbSelectArea(::aAreasInfo[nOrdenApertura, POS_cAliasReal])
   *
   *
   DATA aAreas       READONLY
   METHOD RetAreas() HIDDEN
ENDCLASS

//--------------------------------------------------------------------------//
METHOD New()
nCountWorkSpaces++
*
::oAlias:= TPublic():New()
::aAreasInfo:= {}
RETURN Self
*
//--------------------------------------------------------------------------//
METHOD End()
nCountWorkSpaces--
*
::CloseAll()
RETURN NIL
*
*
//--------------------------------------------------------------------------//
METHOD Activate()
Local lOk:= .t.
*
IF !::OpenNoOpen()
   ::CloseAll()
   lOk:= .f.
ELSE
   ::aAreas:= ::RetAreas()  
ENDIF
RETURN lOk
*
//--------------------------------------------------------------------------//
METHOD CloseAll()
Local nI
Local cAlias
*
FOR nI:= 1 TO Len(::aAreasInfo)

//MDEBUG_(::aAreasInfo[nI, POS_cAliasReal], nI, ::aAreasInfo[nI, POS_lOpen])

   IF ::aAreasInfo[nI, POS_lOpen]  ////.AND. ::aAreasInfo[nI, POS_lActivateSiYaAbierto]
      cAlias:= ::aAreasInfo[nI, POS_cAliasReal]
      (cAlias)-> (dbCommit())
      CLOSE (cAlias)
      *
      *
      ::aAreasInfo[nI, POS_lOpen]:= .f. // Marca como NO abierto !!
   ENDIF
NEXT
RETURN NIL
*
//--------------------------------------------------------------------------//
// Abre los que no se PRE-abrieron (preopen) que seran todos
// casi siempre pq ... utilizar poco lo de preopen !!
METHOD OpenNoOpen()
Local lOk:= .t.
Local cFile, cAliasReal
FOR nI:= 1 TO Len(::aAreasInfo)
   IF !::aAreasInfo[nI, POS_lOpen]
      cFile:=      ::aAreasInfo[nI, POS_cFile]
      cAliasReal:= ::aAreasInfo[nI, POS_cAliasReal]

    //.......


      IF !::OpenFile(cFile, ::aAreasInfo[nI, POS_cPath], @cAliasReal,;
                    ::aAreasInfo[nI, POS_lExclusive],;
                    ::aAreasInfo[nI, POS_lOpenInd])
         lOk:= .f.
         EXIT
      ENDIF

      ::aAreasInfo[nI, POS_cAliasReal]:= cAliasReal  // Esto para cuando en el futuro se coja un area ya abierta.
      ::aAreasInfo[nI, POS_lOpen]:= .t.

    //...........


   ENDIF
NEXT
RETURN lOk
*
*
//--------------------------------------------------------------------------//
METHOD AddWorkArea(PARAM_AWA)
Local oWorkAreaInfo
Local cAliasReal
Local lActivateSiYaAbierto   // Especifica si se abrio en nueva area (cuando se abra)
Local lOpen            // Especifica si esta abierto
Local lRetOpen:= NIL
Local nI, cFile, cAliasExterno
Local lAbierto, cAliRet
Local cCodEmpCambiado  // Empresa en la que finalmente abrio... en TCamino() se pudo cambiar la empresa
*
DEFAULT lExclusive:= .f.
DEFAULT lPreOpen:= .f.
*
*
IF ValType(xFiles) == "C"
   aFiles:= {xFiles}
   xAliasExterno:= {xAliasExterno}
ELSE
   IF xAliasExterno == NIL
      // Alias externo por defecto... ojo que ahora mismo
      // coge el valor de la variable, si se declaro con una
      // variable... Para casos de variable, lo mejor es hacer
      // obligatorio el pasar el xAliasExterno...
      xAliasExterno:= {}
      FOR nI:= 1 TO Len(xFiles)
         Aadd(xAliasExterno, xFiles[nI])
      NEXT
   ENDIF
ENDIF
*
*
FOR nI:= 1 TO Len(xFiles)
   cFile:= Upper(xFiles[nI])
   cAliasExterno:= xAliasExterno[nI]
   *
   ::nCountWorkAreas++
   *
   // Con el prefijo puedo distinguir aquellos que son o no de WorkSpace
   #Define INI_WORKSPACE_AREA "WSA"
   *
   *
   #Define GENERA_ALIAS (INI_WORKSPACE_AREA+ StrZero(nCountWorkSpaces, 3)+ StrZero(::nCountWorkAreas, 4) )
   cAliasReal:= GENERA_ALIAS
   *
   *
   IF lPreOpen
      IF ::OpenFile(cPath, cFile, @cAliasReal,;
                   lExclusive,;
                   lAbrirInd)
         lOpen:= .t.
      ELSE
         lOpen:= .f.
      ENDIF
      lRetOpen:= lOpen
   ELSE
      lOpen:= .f.
   ENDIF
   *
   IF !::oAlias:IsDef(cAliasExterno)
      ::oAlias:Add(cAliasExterno, cAliasReal)
   ELSE
      MERROR_("Alias externo ya usado !!", "Utiliza clausula ALIAS", cAliasExterno, cAliasReal)
   ENDIF

   Aadd(::aAreasInfo, Inutilizar(PARAMETROS_TODOS))
NEXT
RETURN lRetOpen
*
//--------------------------------------------------------------------------//
// La utilizo para inutilizar algunos valores que ya no tienen sentido cuando
// se abre el fichero por fichero...
// y los inutilizo pq los guardo todos para no complicarme la vida !!!
STATIC FUNCTION Inutilizar(PARAMETROS_TODOS)
bPath := NIL
xFiles:= NIL
xAliasExterno:= NIL
RETURN {PARAMETROS_TODOS}
*
*
*
//--------------------------------------------------------------------------//
// cAliasReal por si en el futuro se cambia y se permite reutilizar areas
// ya abiertas... mientras tanto cAliasReal ya viene dado !!
METHOD OpenFile(cFile, cPath, cAliasReal,; //cPath, cFile, lActivateSiYaAbierto, cAliasReal)
                lExclusive,;
                lAbrirInd)
Local oDbf
*
#Define SIEMPRE_ABRIR          .T.
#Define ACTIVATE_SI_YA_ABIERTO .F.
*
oDbf:= Your_open_file_function(cFile, cPath, cAliasReal,;
                    lExclusive,;
                    SIEMPRE_ABRIR,;
                    lAbrirInd,;
                    ACTIVATE_SI_YA_ABIERTO)
IF !oDbf:lOpen
   oDbf:MsgNoOpen()
   RETURN .f.
ENDIF
//IF cAliasReal == NIL
cAliasReal:= oDbf:cAlias
//ENDIF
*
RETURN .t.
*
*
*
//--------------------------------------------------------------------------//
// Devuelve objetos de las areas... es para hacer tratamientos
// externos...
METHOD RetAreas()
Local nI
Local aRet:= {}
Local oClass
*
FOR nI:= 1 TO Len(::aAreasInfo)
   oClass:= ClassVar({;
                      {"cAlias", ::aAreasInfo[nI, POS_cAliasReal]},;
                      {"cPath",  ::aAreasInfo[nI, POS_cPath]};
                     })
   Aadd(aRet, oClass)
NEXT
RETURN aRet
*
*
*
*
*

 
Last edited by hmpaquito on Fri Jun 19, 2015 7:40 am, edited 2 times in total.
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Improvement to DBFs management ...

Postby Rimantas » Wed Oct 07, 2009 5:08 am

hmpaquito wrote:
Rimantas wrote:Thanks for all answers ! It seems that replication of alias it's the most easy way ... :) . I'll use yours suggestions and samples .

Regards !


Rimantas,

Would you like to management dbfs than rdbms big databases?




Interesting thing ! Thanks for source ! :) I'll review and try .

With best regards !
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: Improvement to DBFs management ...

Postby James Bott » Wed Oct 07, 2009 7:16 am

Rimintas,

As Otto stated, the use of database objects will solve all your alias problems. Read more about it on my website here:

http://www.gointellitech.com/program.htm

It may seem more compilcated at first, but I can assure you it is much less complicated than the way you are doing it now. Others, such as Otto, can confirm this.

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

Re: Improvement to DBFs management ...

Postby Rimantas » Wed Oct 07, 2009 7:38 am

James Bott wrote:Rimintas,

As Otto stated, the use of database objects will solve all your alias problems. Read more about it on my website here:

http://www.gointellitech.com/program.htm

It may seem more compilcated at first, but I can assure you it is much less complicated than the way you are doing it now. Others, such as Otto, can confirm this.

Regards,
James


Hi James ,

I know this your class and believe that it's perfect . But this isn't for free ... :( . My budget is limited , so I'll try other solutions ...

Regards !
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: Improvement to DBFs management ...

Postby nageswaragunupudi » Sat Oct 10, 2009 7:33 pm

TDataBase class comes free with FWH
Regards

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

Re: Improvement to DBFs management ...

Postby Rimantas » Sun Oct 11, 2009 4:38 pm

nageswaragunupudi wrote:TDataBase class comes free with FWH



In earliest versions of FWH this was not fully completed . Can you confirm a good results with that class ?

Regards !
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: Improvement to DBFs management ...

Postby Antonio Linares » Sun Oct 11, 2009 6:46 pm

Rimantas,

FWH Class TDataBase works really fine. Try it for yourself :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Improvement to DBFs management ...

Postby Rimantas » Mon Oct 12, 2009 5:42 am

Antonio Linares wrote:Rimantas,

FWH Class TDataBase works really fine. Try it for yourself :-)


Thanks , Antonio ! I'll try this class .

Regards !
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: Improvement to DBFs management ...

Postby PeterHarmes » Mon Oct 12, 2009 11:36 am

James,

Interested in using a database class, but was wondering how i use the class in the following situation:

I give my clients the ability to modify what appears in a browse and in what order the columns appear in, so i have a database that holds the browse info, like this:

Browse Code, Column Number, Field, Size, Header

for example:

CUSTOMER,1,CUSTOMER->ACNT_NBR,100, "Account"
CUSTOMER,2,CUSTOMER->ACNT_NAME,300,"Name"
etc..

The way i currently do this, is to do a strtran on the info read from the database, so if the CUSTOMER alias was CUST01 I would transform the "Field" field to "CUST01->ACNT_NBR" & "CUST01->ACNT_NAME" etc..

How can i do this with either tData or tDataBase class?

Best Regards,

Pete
PeterHarmes
 
Posts: 363
Joined: Wed Feb 15, 2006 2:06 pm
Location: Oxford, England

Re: Improvement to DBFs management ...

Postby James Bott » Mon Oct 12, 2009 4:43 pm

Pete,

I have never tried a data driven browse with a database class but you could try something like: just store the fieldname then when you build the browse use:

oCustomer:fieldPos( cFieldname )

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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 58 guests

cron