Función para indexar

Función para indexar

Postby fergonm » Thu Oct 02, 2008 11:48 am

Buenos días.

Tengo una función que indexa la base de datos (Varias tablas y varios índices por cada tabla).

Me gustaría introducir un "meter" que indique la marcha de cada índice.

¿Hay algún ejemplo?

Muchas gracias.
Saludos. Fernando
fergonm
 
Posts: 133
Joined: Fri Nov 30, 2007 11:34 am
Location: Zaragoza (España)

Postby karinha » Thu Oct 02, 2008 12:01 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Postby fergonm » Thu Oct 02, 2008 4:58 pm

Gracias Karinha, probaré.

Un saludo.
Saludos. Fernando
fergonm
 
Posts: 133
Joined: Fri Nov 30, 2007 11:34 am
Location: Zaragoza (España)

Re: Función para indexar

Postby FranciscoA » Fri Oct 03, 2008 1:44 pm

fergonm wrote:Buenos días.

Tengo una función que indexa la base de datos (Varias tablas y varios índices por cada tabla).

Me gustaría introducir un "meter" que indique la marcha de cada índice.

¿Hay algún ejemplo?

Muchas gracias.



Si deseas algo sencillo, prueba este:
//--------------------
FUNCTION IndTabla1()
DBSELECTAREA("TABLA1")
MsgMeter( { | oMeter, oText, oDlg, lEnd | ;
BuildIndex( oMeter, oText, oDlg, @lEnd,"TABLA1->NUMDOC","DCTOHIST") },;
"Integrando Indice DCTOHIST" )

MsgMeter( { | oMeter, oText, oDlg, lEnd | ;
BuildIndex( oMeter, oText, oDlg, @lEnd,;
"TABLA1->CTA","CTAHIST") },;
"Integrando Indice CTAHIST" )
RETURN NIL

//---------------------------
FUNCTION IndTabla2()
DBSELECTAREA("TABLA2")

DBSELECTAREA("TABLA2")
MsgMeter( { | oMeter, oText, oDlg, lEnd | ;
BuildIndex( oMeter, oText, oDlg, @lEnd,;
"TABLA2->CUENTA","MCONTAH") },;
"Integrando Indice MCONTAH" )

RETURN NIL

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

function BuildIndex( oMeter, oText, oDlg, lEnd, Campos,xIndice )
oMeter:nTotal = RecCount()
INDEX ON &(Campos) TO &(xIndice);
EVAL ( oMeter:Set( RecNo() ), SysRefresh(), ! lEnd )
return nil

//----------------------------------------------------------------------------//
function MsgMeter( bAction, cMsg, cTitle, lBoton )
local oDlg, oMeter, oText, oBtn, oFont
local lEnd := .f., lCancel := .f.
local nVal := 0

DEFAULT bAction := { || nil },;
cMsg := "Procesando...", cTitle := "Aguarde por favor",;
lBoton := .f.

DEFINE DIALOG oDlg RESOURCE "MSGMETER" COLOR "W+/B"
REDEFINE TSAYT ID 111 OF oDlg
REDEFINE TSAYT oText VAR cMsg ID 110 OF oDlg
REDEFINE METER oMeter VAR nVal TOTAL 10 ID 130 OF oDlg


if lBoton
@ 2.8, 18 BUTTON oBtn PROMPT "&Cancel" OF oDlg ;
ACTION ( lEnd:= .t., lCancel:= .t. ) SIZE 32, 11
endif

// This block gets evaluated only the first time the DialogBox is painted !!!
oDlg:bStart = { || Eval( bAction, oMeter, oText, oDlg, @lEnd, oBtn ),;
lEnd := .t., oDlg:End() }

ACTIVATE DIALOG oDlg CENTERED ;
VALID lEnd

return lCancel



Si deseas algo mas vistoso, prueba este ejemplo:

//---------------------------------------------------------------------
Function ReIndexar(aAlias, lTodo)
local oDlg, oAnimate, oMeter1, oMeter2, oSay1, oSay2, oSay3, oBtnCancel
local lEnd:=.f.
local n:=0, nMonto1:=0, nMonto2:=0

local oBrush,cBrush:="Fondo1.BMP"
local nClrTxt:= RGB(0,0,0)

DEFAULT lTodo:=.f.

DEFINE BRUSH oBrush FILENAME cBrush

DEFINE DIALOG oDlg RESOURCE "CopyFiles" BRUSH oBrush TRANSPARENT ;
TITLE "Creando ficheros indices (Reindexando)"

oAnimate = TAnimate():Redefine( 160, oDlg )

REDEFINE TSAYT oSay1 ID 110 OF oDlg COLOR nClrTxt
REDEFINE TSAYT oSay2 ID 120 OF oDlg COLOR nClrTxt
REDEFINE PROGRESS oMeter1 ID 130 OF oDlg

REDEFINE TSAYT oSay3 ID 140 OF oDlg COLOR nClrTxt
REDEFINE PROGRESS oMeter2 ID 150 OF oDlg

REDEFINE BUTTON oBtnCancel ID 2 OF oDlg

oDlg:bStart := { || oBtnCancel:Hide(), oAnimate:CopyFiles(), oAnimate:Play(),;
Reindexe( aAlias, oSay1, oSay2, oSay3, oMeter1, oMeter2, @lEnd, oDlg, oAnimate, lTodo ) }

ACTIVATE DIALOG oDlg CENTERED

SysRefresh()

Return NIL

//---------------------------------------------------------------------------
Function Reindexe( aAlias, oSay1, oSay2, oSay3, oMeter1, oMeter2, lEnd, oDlg, oAnimate, lTodo )
local n:=0, nTotReg:=0

for n := 1 to Len( aAlias )
if ! File( aAlias[ n ]+".dbf" )
MsgInfo( "Fichero no encontrado: " + aAlias[ n ], "Advertencia" )
else
If UPPER( aAlias[n] )="TABLA1"
nTotReg += (aAlias[n])->(RecCount()) * 2 //Cant de Reg*Cant de indices
ElseIf UPPER( aAlias[n] )="TABLA2"
nTotReg += (aAlias[n])->(RecCount()) * x num de indices
endif
SysRefresh()
next

oMeter2:SetRange(0,nTotReg)
nTotReg:=0

For n:=1 to len(aAlias)
DBSELECTAREA( aAlias[n] )

oSay1:SetText( "Base de Datos Actual: " + upper(aAlias[n]) )

If UPPER( aAlias[n] )="MCONTAB"
IntegIndex( oSay2,oMeter1,oMeter2,oSay3,@nTotReg,;
"TABLA2->cuenta","MCONTCTA" )


ElseIf UPPER( aAlias[n] )="TABLA1"
IntegIndex( oSay2,oMeter1,oMeter2,oSay3,@nTotReg,;
"TABLA1->","MCONTAH" )

IntegIndex( oSay2,oMeter1,oMeter2,oSay3,@nTotReg,;
"TABLA1->FECHCIERRE","MCONTFEC" )

Endif
Next

oAnimate:Stop()

if lTodo
MisAreas()
WritePProString("config","UltReindex",Dtoc(date()),cIniFile)
SysRefresh()
MsgWait("Reindexación completada.",,2)
endif

SysRefresh()
oDlg:End()
return(NIL)

//----------------------------------------------------------------
Function IntegIndex( oSay2,oMeter1,oMeter2,oSay3,nTotReg,Campos,cNombIndice )
oSay2:SetText( "Integrando Indice " + cNombIndice )
oMeter1:SetRange(0,RecCount())
INDEX ON &(Campos) TO &(cNombIndice);
EVAL( oMeter1:SetPos( RecNo() ),oMeter2:SetPos(nTotReg+RecNo()), oSay3:SetText( "Registros Indexados: "+Transform(nTotReg+RecNo(),"99,999,999") ), SysRefresh() )
(),"99,999,999") ), SysRefresh() )
nTotReg+=RecCount()
Return nil

Saludos.
FranciscoA
User avatar
FranciscoA
 
Posts: 2110
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Función para indexar

Postby wyerco » Sun Oct 05, 2008 5:11 am

fergonm wrote:Buenos días.

Tengo una función que indexa la base de datos (Varias tablas y varios índices por cada tabla).

Me gustaría introducir un "meter" que indique la marcha de cada índice.

¿Hay algún ejemplo?

Muchas gracias.



MsgMeter({|oMeter,oText,oDlg,lEnd|;
CrearInd(oMeter,oText,oDlg,@lEnd,aBas)},;
"","Creando Indices")

Return(NIL)

*************************************************************
/*

Función CrearInd()

*/

Function CrearInd(oMeter,oText,oDlg,lEnd,aBas)
Local nPor,aInd,nBas,nTot,nLargo,i,cDir
Field RUTCLI,NOMCLI,DIRCLI,MARCA,MODELO,PATENTE,NUMLIQ,FECHA,CODIGO,FACNUM,FACFE,RUTPRO,BOLNUM,BOLFE
Field REPAR,DETALLE,CARGOS,ABONOS,COMUNA,CIUDAD,PRVRUT,PRVNOM,PRVGIR,PRVDIR,NUMDOC,NUMFAC,FEFAC,CLIGIR
Field MARCAVE,FEVENCI,RUT

cDir:=Alltrim(cDirBas)+""

aInd:={{1,"PROV01","PRVRUT" ,{|| PRVRUT}},;
{1,"PROV02","PRVNOM" ,{|| PRVNOM}},;
{1,"PROV03","PRVGIR" ,{|| PRVGIR}},;
{1,"PROV04","PRVDIR" ,{|| PRVDIR}},;
.
.
// todas los indices por tabla. Es para NTX pero tambien te sirve para CDX
.
.


for i=1 to Len(aInd)
if File(cDir+aInd[i,2]+".NTX")
FErase(cDir+aInd[i,2]+".NTX")
endif
next

nPor:=5.26
nBas:=1
nTot:=100
nLargo:=Len(aInd)
oMeter:nTotal:=nTot
oMeter:Set( nPor )

while nPor<=nTot .and. nBas<=19 .and. !lEnd
Memory(-1)
if aBas[nBas,1]
oText:SetText("Creando Indices de "+aBases[nBas])

DBUSEAREA(.T.,,cDir+aNomBas[nBas]) // Nombre de las tablas

for i=1 to nLargo
if nBas=aInd[i,1]
DBCreateIndex(cDir+aInd[i,2],aInd[i,3],aInd[i,4])
endif
next
DBCloseAll()
nPor+=5.26
oMeter:Set( nPor )
endif
nBas++
SysRefresh()
end

if lEnd
MsgBeep()
MsgStop("! Reordenamiento Detenido por Usuario !","Precaución")
endif

Return(NIL)


Ojala te sirva

Saludos

Waldemar
Santiago Chile
User avatar
wyerco
 
Posts: 58
Joined: Thu Aug 14, 2008 9:35 pm
Location: Santiago - Chile

Postby fergonm » Mon Oct 06, 2008 9:31 am

Muchas gracias por la información.

Un saludo.
Saludos. Fernando
fergonm
 
Posts: 133
Joined: Fri Nov 30, 2007 11:34 am
Location: Zaragoza (España)


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 80 guests