Pular para o conteúdo principal

Postagem em destaque

BlackTDN :: cArqTab :: Otimizando a Abertura do Sistema: Como a Escolha do Método de Carregamento Afeta o Desempenho

_Créditos da imagem: Gerada com auxílio do ChatGPT_ # cArqTab :: Como o carregamento de informações em uma variável pode tornar lenta a abertura do sistema TOTVS Microsiga Protheus --- # Comparando LoadFromDBQuery e LoadFromDBWhile: Vantagens e Desempenho No desenvolvimento de soluções para o TOTVS Microsiga Protheus, otimizar o tempo de execução das funções é essencial, especialmente quando lidamos com grandes volumes de dados. Neste artigo, vamos analisar a diferença de desempenho entre os métodos `LoadFromDBQuery` e `LoadFromDBWhile`, utilizando os tempos de execução para demonstrar a vantagem de cada abordagem. ## Contexto do Teste Para avaliar o desempenho, executamos dois procedimentos distintos: - **U_TSTArqTabLoadDBQuery**: utiliza a função `LoadFromDBQuery`. - **U_TSTArqTabLoadDBWhile**: utiliza a função `LoadFromDBWhile`. Os comandos foram executados no ambiente Cygwin, e PowerShell e os tempos foram medidos da seguinte forma: *Cygwin ```bash $ time C:/totvs/tst/sma

Protheus :: ADVPL : Obtendo valores de um arquivo de configuração (*.INI)



ADVPL possui algumas funções padrões para leitura e/ou manipulação de arquivos de configuração (*.INI)  [tdn : Manipulação do arquivo de configuração (*.INI)  ].

O grande problema dessas funções é: ou manipulam arquivos no Client do Usuário ou arquivos de configuração do Próprio Protheus.

Caso necessitemos trabalhar com arquivos (*.INI) customizados teremos que escrever nosso próprio código para esse fim.

Para fins didáticos, implementei a função:

 INIGetPValue( cFile , cSession , cPropertyName , cDefaultValue , cIgnoreToken )

Para auxiliar no entendimento e aprendizado de Leitura de Arquivos .INI.

Utilizei nela a classe FT [ Protheus :: Alternativa às Funções do Tipo FT_F* ]

O Código:

#DEFINE SESSION_POSITION 1
#DEFINE PROPERTY_POSITION 2

#DEFINE PROPERTY_NAME  1
#DEFINE PROPERTY_VALUE  2

#DEFINE PROPERTY_ELEMENTS 2

/*/
 Funcao:  INIGetPValue
 Autor:  Marinaldo de Jesus
 Data:  26/05/2011
 Uso:  Retornar o Valor Atribuido a uma Propriedade de Acordo com a Sessao em um arquivo .INI
 Sintaxe: StaticCall( INIGetPValue , INIGetPValue , cFile , cSession , cPropertyName , cDefault )
/*/
Static Function INIGetPValue( cFile , cSession , cPropertyName , cDefaultValue , cIgnoreToken )

 Local aProperties  := {}
 
 Local cPropertyValue := "@__PROPERTY_NOT_FOUND__@"

 Local lExit
 
 Local nAT
 Local nATLine
 Local nSession
 Local nProperty
 Local nProperties
 Local nATIgnoreTkn

 Local ofT

 BEGIN SEQUENCE
 
  IF Empty( cFile )
   BREAK
  EndIF

  IF !File( cFile )
         BREAK
  ENDIF

  ofT := fT():New()

  IF ( ofT:ft_fUse( cFile ) <= 0 )
   ofT:ft_fUse()
   BREAK
  EndIF

  DEFAULT cSession  := Chr(255)
  DEFAULT cPropertyName := ""
  DEFAULT cIgnoreToken := ";"
  
  cSession  := Lower( AllTrim( cSession ) )
  cPropertyName := Lower( AllTrim( cPropertyName ) )

  While !( ofT:ft_fEof() )
   cLine  := ofT:ft_fReadLn()
   BEGIN SEQUENCE
    IF Empty( cLine )
     BREAK
    EndIF
    IF ( cIgnoreToken $ cLine )
     cLine   := AllTrim( cLine )
     nATIgnoreTkn := AT( cIgnoreToken , cLine )
     IF ( nATIgnoreTkn == 1 )
      BREAK
     EndIF
     cLine := SubStr( cLine , 1  , nATIgnoreTkn - 1 )
    EndIF 
    IF !( "[" $ cLine )
     BREAK
    ENDIF
    lExit  := .F.
    nATLine  := 0
    aAdd( aProperties , { Lower( AllTrim( StrTran( StrTran( cLine , "[" , "" ) , "]" , "" ) ) ) , Array( 0 ) } )
    nProperties := Len( aProperties )
    ofT:ft_fSkip()
    While !( ofT:ft_fEof() )
     cLine := ofT:ft_fReadLn()
      BEGIN SEQUENCE
       IF Empty( cLine )
        BREAK
       EndIF
      IF ( cIgnoreToken $ cLine )
       cLine   := AllTrim( cLine )
       nATIgnoreTkn := AT( cIgnoreToken , cLine )
       IF ( nATIgnoreTkn == 1 )
        nATLine  := 0
        lExit  := .T.
        BREAK
       EndIF
       cLine := SubStr( cLine , 1  , nATIgnoreTkn - 1 )
      EndIF
      IF ( "[" $ cLine )
       lExit := .T.
       BREAK
      EndIF
       aAdd( aProperties[ nProperties ][ PROPERTY_POSITION ] , Array( PROPERTY_ELEMENTS ) )
       nProperty := Len( aProperties[ nProperties ][ PROPERTY_POSITION ] )
       nAT   := AT( "=" , cLine )
       aProperties[ nProperties ][ PROPERTY_POSITION ][ nProperty ][ PROPERTY_NAME  ] := Lower( AllTrim( SubStr( cLine , 1 , nAT - 1 ) ) )
       aProperties[ nProperties ][ PROPERTY_POSITION ][ nProperty ][ PROPERTY_VALUE ] := SubStr( cLine , nAT + 1 )
       cLine  := ""
     END SEQUENCE
     IF ( lExit )
      EXIT
     EndIF
     nATLine  := ofT:ft_fRecno()
     ofT:ft_fSkip()
    End While
    IF ( nATLine > 0 )
     ofT:ft_fGoto( nATLine )
    EndIF
   END SEQUENCE
   ofT:ft_fSkip()
  End While

  ofT:ft_fUse()

  nSession := aScan( aProperties , { |aFindSession| ( aFindSession[ SESSION_POSITION ] == cSession ) } )
  IF ( nSession == 0 )
   BREAK
  EndIF

  nProperty  := aScan( aProperties[ nSession ][ PROPERTY_POSITION ] , { |aValues| ( aValues[ PROPERTY_NAME ] == cPropertyName ) } )
  IF ( nProperty == 0 )
   BREAK
  EndIF

  cPropertyValue := aProperties[ nSession ][ PROPERTY_POSITION ][ nProperty ][ PROPERTY_VALUE ]

 END SEQUENCE

 IF ( cPropertyValue == "@__PROPERTY_NOT_FOUND__@" )
  IF !Empty( cDefaultValue )
   cPropertyValue := cDefaultValue
  Else
   cPropertyValue := ""
  EndIF 
 EndIF

Return( cPropertyValue )

Static Function __Dummy( lRecursa )
 BEGIN SEQUENCE
  lRecursa := .F.
  IF !( lRecursa )
   BREAK
  EndIF
  INIGetPValue()
     lRecursa := __Dummy( lRecursa )
 END SEQUENCE
Return( lRecursa )

O Conteúdo do Arquivo INI:

;[session1]
PropertyName1=PropertiValue1

[session2]
PropertyName1=PropertyValue1;Isso é um comentario
PropertyName2=PropertyValue2

;[session3]
PropertyName1=PropertyValue1
PropertyName2=PropertyValue2
PropertyName2=PropertyValue3
[session4] ;Isso é um Comentário
PropertyName1=PropertyValue1
PropertyName2=PropertyValue2
PropertyName3=PropertyValue3
PropertyName4=PropertyValue4


O Exemplo de Uso:

#INCLUDE "PROTHEUS.CH"
User Function IniPValue()

 cPVS1 := StaticCall( INIGetPValue , INIGetPValue , "D:\INIGetPValue\INIGetPValue.INI" , "session1" , "PropertyName1" , "NO_FOUND" , ";" )
 cPVS2 := StaticCall( INIGetPValue , INIGetPValue , "D:\INIGetPValue\INIGetPValue.INI" , "session2" , "PropertyName2" , "NO_FOUND" , ";" )
 cPVS3 := StaticCall( INIGetPValue , INIGetPValue , "D:\INIGetPValue\INIGetPValue.INI" , "session3" , "PropertyName3" , "NO_FOUND" , ";" )
 cPVS4 := StaticCall( INIGetPValue , INIGetPValue , "D:\INIGetPValue\INIGetPValue.INI" , "session4" , "PropertyName3" , "NO_FOUND" , ";" )
 
Return( NIL )

Para baixar o código fonte e o arquivo de exemplo, clique aqui

[]s
иαldσ dj


Comentários

  1. Olá Marinaldo,
    Fiz o teste com essa rotina, mas só retorna vazio.

    Elisandro

    ResponderExcluir

Postar um comentário

Postagens mais visitadas