Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #12576 > unrolled thread
| Started by | Stefan Dietl <info@sdsoft.it> |
|---|---|
| First post | 2019-08-03 22:24 +0200 |
| Last post | 2019-08-07 23:28 +0200 |
| Articles | 6 — 2 participants |
Back to article view | Back to comp.lang.clipper.visual-objects
Copy 2 dbf (dbfcdx) into one Stefan Dietl <info@sdsoft.it> - 2019-08-03 22:24 +0200
Re: Copy 2 dbf (dbfcdx) into one nk <norbert.k@chello.at> - 2019-08-04 03:11 +0200
Re: Copy 2 dbf (dbfcdx) into one nk <norbert.k@chello.at> - 2019-08-04 03:19 +0200
Re: Copy 2 dbf (dbfcdx) into one Stefan Dietl <info@sdsoft.it> - 2019-08-05 09:53 +0200
Re: Copy 2 dbf (dbfcdx) into one nk <norbert.k@chello.at> - 2019-08-06 00:10 +0200
Re: Copy 2 dbf (dbfcdx) into one Stefan Dietl <info@sdsoft.it> - 2019-08-07 23:28 +0200
| From | Stefan Dietl <info@sdsoft.it> |
|---|---|
| Date | 2019-08-03 22:24 +0200 |
| Subject | Copy 2 dbf (dbfcdx) into one |
| Message-ID | <gqm8s5Fr7brU1@mid.individual.net> |
What is the fastest method to copy all records of 2 dbf's with exactly the same structure into one? dbServer: appendDB and copyDB are a bit slow. I wonder if there exists not a low-level file-level method that could be much faster. Thanks Stefan
[toc] | [next] | [standalone]
| From | nk <norbert.k@chello.at> |
|---|---|
| Date | 2019-08-04 03:11 +0200 |
| Message-ID | <qi5bbr$t96$1@gioia.aioe.org> |
| In reply to | #12576 |
Hello, Stefan,
you can try this method, it worked for me.
FUNCTION Start()
// Kopiert 2 DBF-Dateien mit der exakt gleichen Struktur
// in einer neuen Datei zusammen.
LOCAL cDb01 AS STRING
LOCAL cDb02 AS STRING
LOCAL cDb12 AS STRING
LOCAL cTemp AS STRING
LOCAL nPos AS DWORD
LOCAL nLen1 AS DWORD
LOCAL nLen2 AS DWORD
LOCAL nSatz1 AS DWORD
LOCAL nSatz2 AS DWORD
LOCAL nSatz AS DWORD
LOCAL ptr01 AS PTR
LOCAL ptr02 AS PTR
LOCAL ptr12 AS PTR
// Dateien
cDb01 := "D:\wrk\Vo28\Test\Test01.dbf"
cDb02 := "D:\wrk\Vo28\Test\Test02.dbf"
cDb12 := "D:\wrk\Vo28\Test\Test12.dbf"
// Dateien öffnen
ptr01 := FOpen(cDb01)
ptr02 := FOpen(cDb02)
ptr12 := FCreate(cDb12)
// Dateilängen ermitteln
nLen1 := DWORD(FSeek(ptr01, 0, FS_END))
nLen2 := DWORD(FSeek(ptr02, 0, FS_END))
// Anzahl der Sätze der 1. Datei ermitteln
cTemp := " "
FSeek(ptr01, 4, FS_SET)
FRead(ptr01, @cTemp, 1)
nSatz1 := Asc(cTemp)
FRead(ptr01, @cTemp, 1)
nSatz1 += Asc(cTemp)*28
FRead(ptr01, @cTemp, 1)
nSatz1 += Asc(cTemp)*2^16
FRead(ptr01, @cTemp, 1)
nSatz1 += Asc(cTemp)*2^24
// Beginn des 1. Datensatzes ermitteln
FRead(ptr01, @cTemp, 1)
nPos := Asc(cTemp)
FRead(ptr01, @cTemp, 1)
nPos += Asc(cTemp)*2^8
// Anzahl der Sätze der 2. Datei ermitteln
FSeek(ptr02, 4, FS_SET)
FRead(ptr02, @cTemp, 1)
nSatz2 := Asc(cTemp)
FRead(ptr02, @cTemp, 1)
nSatz2 += Asc(cTemp)*2^8
FRead(ptr02, @cTemp, 1)
nSatz2 += Asc(cTemp)*2^16
FRead(ptr02, @cTemp, 1)
nSatz2 += Asc(cTemp)*2^24
// 1. Datei komplett in Ergebnisdatei übertragen
cTemp := Space(nLen1-1)
FSeek(ptr01, 0, FS_SET)
FRead(ptr01, @cTemp, nLen1-1)
FWrite(ptr12, cTemp, SLen(cTemp))
// Nur die Daten der 2. Datei übertragen
cTemp := Space(nLen2-nPos)
FSeek(ptr02, nPos, FS_SET)
FRead(ptr02, @cTemp, nLen2-nPos)
FWrite(ptr12, cTemp, SLen(cTemp))
// Anzahl der neuen Datensätze eintragen
nSatz := nSatz1 + nSatz2
cTemp := CHR(_AND(nSatz >> 24, 0b11111111))
cTemp += CHR(_AND(nSatz >> 16, 0b11111111))
cTemp += CHR(_AND(nSatz >> 8, 0b11111111))
cTemp += CHR(_AND(nSatz, 0b11111111))
FSeek(ptr12, 4, FS_SET)
FWrite(ptr12, cTemp, SLen(cTemp))
// Dateien schließen
FClose(ptr01)
FClose(ptr02)
FClose(ptr12)
RETURN NIL
Norbert
Am 03.08.2019 um 22:24 schrieb Stefan Dietl:
> What is the fastest method to copy all records of 2 dbf's with exactly
> the same structure into one? dbServer: appendDB and copyDB are a bit
> slow. I wonder if there exists not a low-level file-level method that
> could be much faster.
> Thanks Stefan
[toc] | [prev] | [next] | [standalone]
| From | nk <norbert.k@chello.at> |
|---|---|
| Date | 2019-08-04 03:19 +0200 |
| Message-ID | <qi5brh$uj6$1@gioia.aioe.org> |
| In reply to | #12577 |
I'm sorry, please replace the following: // Anzahl der neuen Datensätze eintragen nSatz := nSatz1 + nSatz2 cTemp := CHR(_AND(nSatz, 0b11111111)) cTemp += CHR(_AND(nSatz >> 8, 0b11111111)) cTemp += CHR(_AND(nSatz >> 16, 0b11111111)) cTemp += CHR(_AND(nSatz >> 24, 0b11111111))
[toc] | [prev] | [next] | [standalone]
| From | Stefan Dietl <info@sdsoft.it> |
|---|---|
| Date | 2019-08-05 09:53 +0200 |
| Message-ID | <gqq5jcFm40mU1@mid.individual.net> |
| In reply to | #12578 |
Hi Norbert, thank You for the code! It work fast as expected, but the second file is not inserted correctly. It seems that everything is shifted by one byte. Is this line correct? nSatz1 += Asc(cTemp)*28 or should it be nSatz1 += Asc(cTemp)*2^8? I tried both variants, unfortunately always with the same wrong result Stefan
[toc] | [prev] | [next] | [standalone]
| From | nk <norbert.k@chello.at> |
|---|---|
| Date | 2019-08-06 00:10 +0200 |
| Message-ID | <qia9g6$hr0$1@gioia.aioe.org> |
| In reply to | #12580 |
Hello Stefan,
I'm sorry, but it was a little bit late.
Here the new version. I hope the function is now correct.
Best regards
Norbert
FUNCTION Start()
// Kopiert 2 DBF-Dateien mit der exakt gleichen Struktur
// in eine neuen Datei zusammen.
LOCAL cDb01 AS STRING
LOCAL cDb02 AS STRING
LOCAL cDb12 AS STRING
LOCAL cTemp AS STRING
LOCAL nPos AS DWORD
LOCAL nLen1 AS DWORD
LOCAL nLen2 AS DWORD
LOCAL nSatz1 AS DWORD
LOCAL nSatz2 AS DWORD
LOCAL nSatz AS DWORD
LOCAL ptr01 AS PTR
LOCAL ptr02 AS PTR
LOCAL ptr12 AS PTR
// Dateien
cDb01 := "D:\wrk\Vo28\Test\Test01.dbf"
cDb02 := "D:\wrk\Vo28\Test\Test02.dbf"
cDb12 := "D:\wrk\Vo28\Test\Test12.dbf"
// Dateien öffnen
ptr01 := FOpen(cDb01)
ptr02 := FOpen(cDb02)
ptr12 := FCreate(cDb12)
// Dateilängen ermitteln
nLen1 := DWORD(FSeek(ptr01, 0, FS_END))
nLen2 := DWORD(FSeek(ptr02, 0, FS_END))
// Anzahl der Sätze der 1. Datei ermitteln
cTemp := " "
FSeek(ptr01, 4, FS_SET)
FRead(ptr01, @cTemp, 1)
nSatz1 := Asc(cTemp)
FRead(ptr01, @cTemp, 1)
nSatz1 += Asc(cTemp)*2^8
FRead(ptr01, @cTemp, 1)
nSatz1 += Asc(cTemp)*2^16
FRead(ptr01, @cTemp, 1)
nSatz1 += Asc(cTemp)*2^24
// Beginn des 1. Datensatzes ermitteln
FRead(ptr01, @cTemp, 1)
nPos := Asc(cTemp)
FRead(ptr01, @cTemp, 1)
nPos += Asc(cTemp)*2^8
// Anzahl der Sätze der 2. Datei ermitteln
FSeek(ptr02, 4, FS_SET)
FRead(ptr02, @cTemp, 1)
nSatz2 := Asc(cTemp)
FRead(ptr02, @cTemp, 1)
nSatz2 += Asc(cTemp)*2^8
FRead(ptr02, @cTemp, 1)
nSatz2 += Asc(cTemp)*2^16
FRead(ptr02, @cTemp, 1)
nSatz2 += Asc(cTemp)*2^24
// 1. Datei bis auf das Dateiendezeichen Chr(26)
// komplett in die Ergebnisdatei übertragen
cTemp := Space(nLen1-1)
FSeek(ptr01, 0, FS_SET)
FRead(ptr01, @cTemp, SLen(cTemp))
FWrite(ptr12, cTemp, SLen(cTemp))
// Nur die Daten der 2. Datei übertragen
cTemp := Space(nLen2-nPos)
FSeek(ptr02, nPos, FS_SET)
FRead(ptr02, @cTemp, SLen(cTemp))
FWrite(ptr12, cTemp, SLen(cTemp))
// Anzahl der neuen Datensätze eintragen
nSatz := nSatz1 + nSatz2
cTemp := CHR(_AND(nSatz, 0b11111111))
cTemp += CHR(_AND(nSatz >> 8, 0b11111111))
cTemp += CHR(_AND(nSatz >> 16, 0b11111111))
cTemp += CHR(_AND(nSatz >> 24, 0b11111111))
FSeek(ptr12, 4, FS_SET)
FWrite(ptr12, cTemp, SLen(cTemp))
// Dateien schließen
FClose(ptr01)
FClose(ptr02)
FClose(ptr12)
RETURN NIL
[toc] | [prev] | [next] | [standalone]
| From | Stefan Dietl <info@sdsoft.it> |
|---|---|
| Date | 2019-08-07 23:28 +0200 |
| Message-ID | <gr0u33F6hkjU1@mid.individual.net> |
| In reply to | #12582 |
Thank You Norbert! On dbf's with few fields it works perfect. I have a dbf with many fields (81) and there the calculation of the header length is wrong by one byte. So I have to do nPos-=1 before appending data of the second file. (The result of nPos in my file is something over 1500) Stefan Am 06.08.2019 um 00:10 schrieb nk: > Hello Stefan, > I'm sorry, but it was a little bit late. > Here the new version. I hope the function is now correct. > > Best regards > Norbert > > FUNCTION Start() > // Kopiert 2 DBF-Dateien mit der exakt gleichen Struktur > // in eine neuen Datei zusammen. > > LOCAL cDb01 AS STRING > LOCAL cDb02 AS STRING > LOCAL cDb12 AS STRING > LOCAL cTemp AS STRING > LOCAL nPos AS DWORD > LOCAL nLen1 AS DWORD > LOCAL nLen2 AS DWORD > LOCAL nSatz1 AS DWORD > LOCAL nSatz2 AS DWORD > LOCAL nSatz AS DWORD > LOCAL ptr01 AS PTR > LOCAL ptr02 AS PTR > LOCAL ptr12 AS PTR > > // Dateien > cDb01 := "D:\wrk\Vo28\Test\Test01.dbf" > cDb02 := "D:\wrk\Vo28\Test\Test02.dbf" > cDb12 := "D:\wrk\Vo28\Test\Test12.dbf" > > // Dateien öffnen > ptr01 := FOpen(cDb01) > ptr02 := FOpen(cDb02) > ptr12 := FCreate(cDb12) > > // Dateilängen ermitteln > nLen1 := DWORD(FSeek(ptr01, 0, FS_END)) > nLen2 := DWORD(FSeek(ptr02, 0, FS_END)) > > // Anzahl der Sätze der 1. Datei ermitteln > cTemp := " " > FSeek(ptr01, 4, FS_SET) > FRead(ptr01, @cTemp, 1) > nSatz1 := Asc(cTemp) > FRead(ptr01, @cTemp, 1) > nSatz1 += Asc(cTemp)*2^8 > FRead(ptr01, @cTemp, 1) > nSatz1 += Asc(cTemp)*2^16 > FRead(ptr01, @cTemp, 1) > nSatz1 += Asc(cTemp)*2^24 > > // Beginn des 1. Datensatzes ermitteln > FRead(ptr01, @cTemp, 1) > nPos := Asc(cTemp) > FRead(ptr01, @cTemp, 1) > nPos += Asc(cTemp)*2^8 > > // Anzahl der Sätze der 2. Datei ermitteln > FSeek(ptr02, 4, FS_SET) > FRead(ptr02, @cTemp, 1) > nSatz2 := Asc(cTemp) > FRead(ptr02, @cTemp, 1) > nSatz2 += Asc(cTemp)*2^8 > FRead(ptr02, @cTemp, 1) > nSatz2 += Asc(cTemp)*2^16 > FRead(ptr02, @cTemp, 1) > nSatz2 += Asc(cTemp)*2^24 > > // 1. Datei bis auf das Dateiendezeichen Chr(26) > // komplett in die Ergebnisdatei übertragen > cTemp := Space(nLen1-1) > FSeek(ptr01, 0, FS_SET) > FRead(ptr01, @cTemp, SLen(cTemp)) > FWrite(ptr12, cTemp, SLen(cTemp)) > > // Nur die Daten der 2. Datei übertragen > cTemp := Space(nLen2-nPos) > FSeek(ptr02, nPos, FS_SET) > FRead(ptr02, @cTemp, SLen(cTemp)) > FWrite(ptr12, cTemp, SLen(cTemp)) > > // Anzahl der neuen Datensätze eintragen > nSatz := nSatz1 + nSatz2 > cTemp := CHR(_AND(nSatz, 0b11111111)) > cTemp += CHR(_AND(nSatz >> 8, 0b11111111)) > cTemp += CHR(_AND(nSatz >> 16, 0b11111111)) > cTemp += CHR(_AND(nSatz >> 24, 0b11111111)) > > FSeek(ptr12, 4, FS_SET) > FWrite(ptr12, cTemp, SLen(cTemp)) > > // Dateien schließen > FClose(ptr01) > FClose(ptr02) > FClose(ptr12) > > RETURN NIL >
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.clipper.visual-objects
csiph-web