Create dbf file in both harbour and clipper

636 views
Skip to first unread message

mtmigs

unread,
Sep 27, 2017, 9:52:55 AM9/27/17
to Harbour Users
I have a strange situation where I need to compile a program with both harbour and clipper. It is a simple program that just needs to create a dbf file.

I wrote one that compiles in harbour but the aadd function does not seem to exist in clipper.

  TeamDbf := {}
  AADD(TeamDbf, { "Team", "C", 10, 0 })
  AADD(TeamDbf, { "Year", "N", 1, 0 })
  AADD(TeamDbf, { "Buyers", "N", 7, 0 })
  AADD(TeamDbf, { "House", "N", 7, 0 })
  AADD(TeamDbf, { "Circ", "N", 7, 0 })
  AADD(TeamDbf, { "Grs_Ords", "N", 7, 0 })
  AADD(TeamDbf, { "Net_Ords", "N", 7, 0 })
  AADD(TeamDbf, { "Sales", "N", 7, 0 })
  AADD(TeamDbf, { "GRS_Profit", "N", 7, 0 })
  AADD(TeamDbf, { "Net_Profit", "N", 7, 0 })
  DBCREATE(alltrim(lower(MTEAMNAME)), TeamDbf)
 
There must be a way to create dbf files with clipper that harbour will also compile. All the clipper documentation has been replaced by harbour documentation.

How might I rewrite this so that it will work with clipper also?

Angel Pais

unread,
Sep 27, 2017, 10:02:15 AM9/27/17
to harbou...@googlegroups.com
Which clipper version ?
AFAIK in Clipper >= 5.0, AADD() exists !
Not very sure about the underscore character in Names...

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-users+unsubscribe@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Patrick Mast

unread,
Sep 27, 2017, 10:24:51 AM9/27/17
to Harbour Users
Hello,

Oh yes, Aadd() is a clipper function:

What is the exact Clipper error you get?

Patrick

mtmigs

unread,
Sep 27, 2017, 10:36:50 AM9/27/17
to Harbour Users
It does not say the version but it is a very old. It says Nantucket Summer '87.

Even though it is that old there still should be a way to create a dbf file.

Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.

mtmigs

unread,
Sep 27, 2017, 10:42:26 AM9/27/17
to Harbour Users
It gives two errors for each Aadd line, "unbalanced parenthesis" with a pointer under the { showing the complete line and "operand expected". This second time the pointer is under the same place but the line is truncated to where the { would be.

It is a very old version of clipper, Summer '87 is what it prints. Even so there must be a way to create a dbf file in that version that is still compatible with harbour.

Miroslav Georgiev

unread,
Sep 27, 2017, 3:03:00 PM9/27/17
to Harbour Users
Please take a look at following command:

#command CREATE <(db)> [FROM <(src)>] [VIA <rdd>] [ALIAS <a>] ;
               
[<new: NEW>] [CODEPAGE <cp>] => ;
         __dbCreate
( <(db)>, <(src)>, <rdd>, <.new.>, <(a)> [, <cp>] )

https://harbour.github.io/doc/harbour.html#__dbcreate - look at the table with FIELD_NAME and so on..

something like this may help you:
create (cDbfName) From TempStru New

mtmigs

unread,
Sep 27, 2017, 3:59:51 PM9/27/17
to Harbour Users
Please take a look at following command:

#command CREATE <(db)> [FROM <(src)>] [VIA <rdd>] [ALIAS <a>] ;
               
[<new: NEW>] [CODEPAGE <cp>] => ;
         __dbCreate
( <(db)>, <(src)>, <rdd>, <.new.>, <(a)> [, <cp>] )

https://harbour.github.io/doc/harbour.html#__dbcreate - look at the table with FIELD_NAME and so on..

something like this may help you:
create (cDbfName) From TempStru New


I actually did come across something like that and tried several variations on this:

CREATE teamdbf
APPEND BLANK
teamdbf->FIELD_NAME = "Year"
teamdbf->FIELD_TYPE = "N"
teamdbf->FIELD_LEN  = 1
teamdbf->FIELD_DEC  = 0
CLOSE
CREATE (alltrim(lower(MTEAMNAME))) FROM teamdbf

Originally I used CREATE TEMPLATE.
Then I tried FIELD-> instead of teamdbf->.

It created a messed up file with no proper dbf structure.

I cannot seem to be able to load the structure properly in to the array for CREATE to work. :-(

Klas Engwall

unread,
Sep 27, 2017, 4:36:58 PM9/27/17
to harbou...@googlegroups.com
Hi mtmigs,

> CREATE teamdbf
> APPEND BLANK
> teamdbf->FIELD_NAME = "Year"
> teamdbf->FIELD_TYPE = "N"
> teamdbf->FIELD_LEN  = 1
> teamdbf->FIELD_DEC  = 0
> CLOSE
> CREATE (alltrim(lower(MTEAMNAME))) FROM teamdbf

For S87 ... back to basics, skip the aliasing, skip the = assignments,
skip the fancy handling of the final table name, and skip the 9th file
name character :-)

CREATE teamdbf
APPEND BLANK
replace FIELD_NAME with "YEAR"
replace FIELD_TYPE with "N"
replace FIELD_LEN with 1
replace FIELD_DEC with 0
CLOSE
CREATE MTEAMNAM FROM teamdbf

Or take the easy way out and create the table with Harbour and just USE
it with S87. Some fights are not worth it :-)

Regards,
Klas

mtmigs

unread,
Sep 27, 2017, 9:25:14 PM9/27/17
to Harbour Users
For S87 ... back to basics, skip the aliasing, skip the = assignments,
skip the fancy handling of the final table name, and skip the 9th file
name character :-)

The field MTEAMNAME has mixed case and spaces so I need to clean it up for the file name.
But apart from that I converted what I had to your suggested syntax and IT WORKS!  Yeah!
 

Or take the easy way out and create the table with Harbour and just USE
it with S87. Some fights are not worth it :-)

Regards,
Klas

There is another independent process that moves this dbf to another location. So this program needs to be able to recreate the dbf if it is not there. :-)
 

Klas Engwall

unread,
Sep 28, 2017, 6:08:47 AM9/28/17
to harbou...@googlegroups.com
Hi mtmigs,

>> For S87 ... back to basics, skip the aliasing, skip the = assignments,
>> skip the fancy handling of the final table name, and skip the 9th file
>> name character :-)
>
> The field MTEAMNAME has mixed case and spaces so I need to clean it up
> for the file name.
> But apart from that I converted what I had to your suggested syntax and
> IT WORKS!  Yeah!
>
>> Or take the easy way out and create the table with Harbour and just USE
>> it with S87. Some fights are not worth it :-)
>
> There is another independent process that moves this dbf to another
> location. So this program needs to be able to recreate the dbf if it is
> not there. :-)

There is one more option regarding how to create the empty table if you
do not want to use junk files to CREATE it FROM. Since S87 does not
understand how to Aadd() field specs to a dbStruct() array to create the
file from, you can instead build the table header as a binary string in
memory and simply Fwrite() it to disk. That is how I approached the
problem at the time, and it worked nicely and wasn't too complicated.

Nantucket apparently even expected people to build their dbf files that
way, because the S87 Norton guide describes the dbf header in great
detail. I can copy that guide entry here if you want it.

Regards,
Klas
Reply all
Reply to author
Forward
0 new messages