Comparar tablas dbf de misma Estructura
Moderator: Rathinagiri
- Ismach
- Posts: 164
- Joined: Wed Nov 28, 2012 5:55 pm
- DBs Used: DBF, mySQL, Mariadb, postgreSQL, Oracle, Db2, Interbase, Firebird, and SQLite
- Location: Buenos Aires - Argentina
Comparar tablas dbf de misma Estructura
necesito comparar muchas tablas .dbf version anterior y nueva version de igual estructura e igual nombre pero los datos no necesariamente sean iguales
el problemita que tengo es que son casi 2000 tablas a comparar
quiero hacer un programa que reciba como parametro el nombre de la tabla
y me compare el contenido de los campos, alguien hizo algo parecido o me puede orientar como hacerlo?
el problemita que tengo es que son casi 2000 tablas a comparar
quiero hacer un programa que reciba como parametro el nombre de la tabla
y me compare el contenido de los campos, alguien hizo algo parecido o me puede orientar como hacerlo?
Re: Comparar tablas dbf de misma Estructura
No capte realmente tu necesidad, Tal vez de esta forma...necesito comparar muchas tablas .dbf version anterior y nueva version de igual estructura e igual nombre pero los datos no necesariamente sean iguales
el problemita que tengo es que son casi 2000 tablas a comparar
quiero hacer un programa que reciba como parametro el nombre de la tabla
y me compare el contenido de los campos, alguien hizo algo parecido o me puede orientar como hacerlo?
aDirect := DIRECTORY( "*.dbf" )
FOR i = 1 TO LEN( aDirect )
Compara( cPath1, cPath2, aDirect[ i ] )
NEXT i
------------------------------------------------------
FUNCTION Compara( cPath1, cPath2, DBF )
USE cPath1+DBF
Estruct1 := DBSTRUCT()
CLOSE
USE cPath2+DBF
Estruct2 := DBSTRUCT()
CLOSE
RETURN IF( Estruct1 = Estruct2, .T., .F. )
Tendrías que crear una funciona que compare cada elemento de los 2 arreglos...
Andrés González López
Desde Guadalajara, Jalisco. México.
Desde Guadalajara, Jalisco. México.
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: Comparar tablas dbf de misma Estructura
andyglezl wrote:Code: Select all
aDirect := DIRECTORY( "*.dbf" ) FOR i = 1 TO LEN( aDirect ) Compara( cPath1, cPath2, aDirect[ i ] ) NEXT i ------------------------------------------------------ FUNCTION Compara( cPath1, cPath2, DBF ) USE cPath1+DBF Estruct1 := DBSTRUCT() CLOSE USE cPath2+DBF Estruct2 := DBSTRUCT() CLOSE RETURN IF( Estruct1 = Estruct2, .T., .F. )
Code: Select all
/*
Test comparing arrays
*/
#include <hmg.ch>
PROC Main()
DEFINE WINDOW frmMiniFMan ;
ROW 0 ;
COL 0 ;
WIDTH 550 ;
HEIGHT 470 ;
TITLE 'Compare Arrays' ;
ON INIT DoTest();
MAIN
END WINDOW // MAIN
frmMiniFMan.Center()
frmMiniFMan.Activate()
ON KEY ESCAPE ACTION frmMiniFMan.Release
RETU // CompArrs.Main()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._
PROC DoTest()
aArry1 := { 1, 2, 3, 4 }
aArry2 := { 1, 2, 3, 4 }
* MsgDebug( IF( aArry1 = aArry2, "Equal", "Not egual" ) ) // Argument error
MsgDebug( IF( aArry1 == aArry2, "Equal", "Not egual" ) ) // Not Equal
RETU // DoTest()
Viva INTERNATIONAL HMG 

- Ismach
- Posts: 164
- Joined: Wed Nov 28, 2012 5:55 pm
- DBs Used: DBF, mySQL, Mariadb, postgreSQL, Oracle, Db2, Interbase, Firebird, and SQLite
- Location: Buenos Aires - Argentina
Re: Comparar tablas dbf de misma Estructura
Antes que nada muchas gracias por las respuestas, lo que necesito comparar son los datos, las estructuras son exactamente igual.
Re: Comparar tablas dbf de misma Estructura
Básicamente es lo mismo, solo que en vez de comparar el arreglo, comparas el contenido.
Ya tienes los nombres de campos, carga el contenido y compara.
Otra forma es:
Que obtengas el valor numérico (checksum) de todo el contenido del registro y lo compares
contra el valor del otro registro.
Ya tienes los nombres de campos, carga el contenido y compara.
Otra forma es:
Que obtengas el valor numérico (checksum) de todo el contenido del registro y lo compares
contra el valor del otro registro.
Andrés González López
Desde Guadalajara, Jalisco. México.
Desde Guadalajara, Jalisco. México.
- Ismach
- Posts: 164
- Joined: Wed Nov 28, 2012 5:55 pm
- DBs Used: DBF, mySQL, Mariadb, postgreSQL, Oracle, Db2, Interbase, Firebird, and SQLite
- Location: Buenos Aires - Argentina
Re: Comparar tablas dbf de misma Estructura
Ok... gracias. en cuanto lo finalice lo cuelgo. Saludos y gracias
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: Comparar tablas dbf de misma Estructura
Hi Ismach and Andy
As far as I understand right, Ismach ask a way for compare only structures, no records.
Anyway "Checksum" isn't adequate and practical way.
I may propose another method;
If you ask your question by a language I can understand right; sorry this is only English (may be also Turkish
).
Viva HMG
As far as I understand right, Ismach ask a way for compare only structures, no records.
Anyway "Checksum" isn't adequate and practical way.
I may propose another method;
If you ask your question by a language I can understand right; sorry this is only English (may be also Turkish

Viva HMG

Viva INTERNATIONAL HMG 

Re: Comparar tablas dbf de misma Estructura
Hola esgici
Yo entendí que Ismach, quería comparar las estructuras, pero el quiere
comparar el contenido de cada campo.
-------------------------------------------------------------------------------------------
Hello esgici
I understood that Ismach, wanted to compare the structures, but he wants
compare the contents of each field.
Yo entendí que Ismach, quería comparar las estructuras, pero el quiere
comparar el contenido de cada campo.
-------------------------------------------------------------------------------------------
Hello esgici
I understood that Ismach, wanted to compare the structures, but he wants
compare the contents of each field.
Andrés González López
Desde Guadalajara, Jalisco. México.
Desde Guadalajara, Jalisco. México.
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: Comparar tablas dbf de misma Estructura
Comparing content of fields, but no records; interestingandyglezl wrote:...
Hello esgici
I understood that Ismach, wanted to compare the structures, but he wants
compare the contents of each field.

Anyway, it's clear that I had understand wrong


Viva HMG

Viva INTERNATIONAL HMG 

- serge_girard
- Posts: 3309
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: Comparar tablas dbf de misma Estructura
Ismach,
This little sample will do the job:
Condition is both DBF must be the same structure and must have a unique key field.
Open both files with an index on the key.
Read the key fields and compare the key: (3 possibilties):
- if keys are equal: compare non-key fields
- key1 greater : missing in file2
- key2 greater: missing in file1.
On EOF of one of both files: STOP
Loop through EOF1 : missing in 2
Loop through EOF2 : missing in 1
Origin of this program is one of my very first COBOL exercise in 1980..
Succes, Serge
This little sample will do the job:
Condition is both DBF must be the same structure and must have a unique key field.
Open both files with an index on the key.
Read the key fields and compare the key: (3 possibilties):
- if keys are equal: compare non-key fields
- key1 greater : missing in file2
- key2 greater: missing in file1.
On EOF of one of both files: STOP
Loop through EOF1 : missing in 2
Loop through EOF2 : missing in 1
Origin of this program is one of my very first COBOL exercise in 1980..
Code: Select all
// STRUCTURE OF BOTH DBF MUST BE EQUAL !!!
// EXAMPLE DATABASE WITH 2 FIELDS : KEY + SOME ATTRIBUTE (NAME)
USE C:\TEST\DBF_1 NEW
INDEX ON DBF_KEY TO WW1
EOF01 := EOF()
USE C:\TEST\DBF_2 NEW
INDEX ON DBF_KEY TO WW2
EOF02 := EOF()
SET PRINTER TO C:\TEST\COMPARE.TXT
SET PRINTER ON
SET CONSOLE OFF
SELECT DBF_1
GO TOP
DO WHILE .NOT. EOF01 .AND. .NOT. EOF02
IF DBF_1->DBF_KEY == DBF_2->DBF_KEY
? '01 ' + DBF_1->DBF_KEY + ' ' + DBF_1->NAME + ' 10 ' + DBF_2->DBF_KEY + ' ' + DBF_2->NAME
IF UPPER(ALLTRIM(DBF_1->NAME)) == UPPER(ALLTRIM(DBF_2->NAME))
? ' 100% EQUAL '
ELSE
? ' NAME # '
ENDIF
SELECT DBF_1
SKIP
EOF01 := EOF()
SELECT DBF_2
SKIP
EOF02 := EOF()
ELSE
IF DBF_1->DBF_KEY < DBF_2->DBF_KEY
// MISSING RECORD IN DBF2
? '01 ' + DBF_1->DBF_KEY + ' ' + DBF_1->NAME
SELECT DBF_1
SKIP
EOF01 := EOF()
ELSE
// MISSING RECORD IN DBF1
? '02 ' + DBF_2->DBF_KEY + ' ' + DBF_2->NAME
SELECT DBF_2
SKIP
EOF02 := EOF()
ENDIF
ENDIF
ENDDO
DO WHILE .NOT. EOF01
// MISSING RECORDS IN DBF2
? '01 ' + DBF_1->DBF_KEY + ' ' + DBF_1->NAME
SELECT DBF_1
SKIP
EOF01 := EOF()
ENDDO
DO WHILE .NOT. EOF02
// MISSING RECORD IN DBF1
? '02 ' + DBF_2->DBF_KEY + ' ' + DBF_2->NAME
SELECT DBF_2
SKIP
EOF02 := EOF()
ENDDO
CLOSE ALL
SET PRINTER TO
SET PRINTER OFF
SET CONSOLE ON
RETURN
There's nothing you can do that can't be done...