Page 1 of 2

It is possible to create a dbf table with two...

PostPosted: Wed Mar 09, 2011 9:16 am
by MarcoBoschi
...or more fields with the same name?

The answer is Yes:

#include "Fivewin.ch"

REQUEST DBFCDX

FUNCTION MAIN()

LOCAL aStru1 := { }
LOCAL aStru2 := { }

AADD( aStru1 , { "FIRST" , "C" , 20 , 0 } )
AADD( aStru1 , { "LAST" , "C" , 20 , 0 } )

DbCreate( "OK" , aStru1 , "DBFCDX" )

AADD( aStru1 , { "FIRST" , "C" , 20 , 0 } )
AADD( aStru1 , { "LAST" , "C" , 20 , 0 } )
AADD( aStru1 , { "SAMENAME" , "C" , 20 , 0 } )
AADD( aStru1 , { "SAMENAME" , "C" , 20 , 0 } )
AADD( aStru1 , { "SAMENAME" , "C" , 20 , 0 } )
AADD( aStru1 , { "SAMENAME" , "C" , 20 , 0 } )
AADD( aStru1 , { "SAMENAME" , "C" , 20 , 0 } )
AADD( aStru1 , { "SAMENAME" , "C" , 20 , 0 } )

DbCreate( "NOTOK" , aStru1 , "DBFCDX" )

RETURN NIL


Just an alert

Best regards

marco

Re: It is possible to create a dbf table with two...

PostPosted: Wed Mar 09, 2011 9:40 am
by Silvio
I think it is no possible

Re: It is possible to create a dbf table with two...

PostPosted: Wed Mar 09, 2011 9:44 am
by MarcoBoschi
Silvio,
take a look at

http://groups.google.com/group/comp.lan ... d7247170b#

it seems that it is possible

bye

Re: It is possible to create a dbf table with two...

PostPosted: Wed Mar 09, 2011 10:54 am
by Silvio
hiii...

but then how save the record ?

replace ctext to samename
replace ctext1to samename
replace ctext2 to samename

I think you'll save on the same field

Re: It is possible to create a dbf table with two...

PostPosted: Wed Mar 09, 2011 12:34 pm
by StefanHaupt
Marco, Silvio,

yes, it´s possible, see this sample

Code: Select all  Expand view
// The example shows how to create a new database from a
// structure definition array using the DBFCDX driver.
#include "Fivewin.ch"


   REQUEST DBFCDX

   PROCEDURE Main()
      LOCAL aStruct := { ;
               { "CHARACTER", "C", 25, 0 }, ;
               { "NUMERIC"  , "N",  8, 0 }, ;
               { "DOUBLE"   , "N",  8, 2 }, ;
               { "DATE"     , "D",  8, 0 }, ;
               { "LOGICAL"  , "L",  1, 0 }, ;
               { "MEMO"     , "M", 10, 0 }, ;
               { "MEMO"     , "M", 10, 0 }  ;
            }
      ? "Creating Database...."
      DbCreate( "testdbf", aStruct, "DBFCDX", .T., "MYALIAS" )
      MyAlias->(dbAppend())

      MyAlias->Memo := "Memofield 1"  // Insert text to Menmfield 1
      FieldPut (7, "Memofield 2")     // Insert text to Memofield 2

      Browse()

   RETURN

Re: It is possible to create a dbf table with two...

PostPosted: Wed Mar 09, 2011 2:11 pm
by MarcoBoschi
Please try this:

#include "Fivewin.ch"

REQUEST DBFCDX

FUNCTION MAIN()

LOCAL aStru := { }

AADD( aStru , { "FIRST" , "C" , 20 , 0 } )
AADD( aStru , { "LAST" , "C" , 20 , 0 } )
AADD( aStru , { "SAMENAME" , "C" , 20 , 0 } )
AADD( aStru , { "SAMENAME" , "C" , 20 , 0 } )
AADD( aStru , { "SAMENAME" , "C" , 20 , 0 } )
AADD( aStru , { "SAMENAME" , "C" , 20 , 0 } )
AADD( aStru , { "SAMENAME" , "C" , 20 , 0 } )
AADD( aStru , { "SAMENAME" , "C" , 20 , 0 } )

DbCreate( "NOTOK" , aStru , "DBFCDX" )

USE NOTOK
APPEND BLANK
REPLACE field->first WITH "test 1"
REPLACE field->samename WITH "replace samename"

APPEND BLANK
REPLACE field->first WITH "test 2"
fieldput( 5 , "FIELDPUT 5" )
fieldput( 6 , "FIELDPUT 6" )

APPEND BLANK
REPLACE field->first WITH "test 3"
fieldput( 5 , "FIELDPUT 5" )

APPEND BLANK
REPLACE field->first WITH "test 4"
fieldput( 6 , "FIELDPUT 6" )

APPEND BLANK
REPLACE field->first WITH "test 5"
fieldput( 3 , "FIELDPUT 3" )
RETURN NIL

Many thanks
marco

Re: It is possible to create a dbf table with two...

PostPosted: Wed Mar 09, 2011 2:43 pm
by Bayron
Hi all,

If the code to manipulate the introduction of data is bigger, and harder to remember what it was introducted where, I wonder what will be the use of having the same name in the fields???

Re: It is possible to create a dbf table with two...

PostPosted: Wed Mar 09, 2011 2:56 pm
by James Bott
I think Marco was pointing out that this is a bug.

Regards,
James

Re: It is possible to create a dbf table with two...

PostPosted: Wed Mar 09, 2011 3:59 pm
by MarcoBoschi
Stefan Please compile your sample without fivewin
Please remove this line and compile again

#include "Fivewin.ch" // REMOVE THIS LINE AND COMPILE AGAIN


REQUEST DBFCDX

PROCEDURE Main()
LOCAL aStruct := { ;
{ "CHARACTER", "C", 25, 0 }, ;
{ "NUMERIC" , "N", 8, 0 }, ;
{ "DOUBLE" , "N", 8, 2 }, ;
{ "DATE" , "D", 8, 0 }, ;
{ "LOGICAL" , "L", 1, 0 }, ;
{ "MEMO" , "M", 10, 0 }, ;
{ "MEMO" , "M", 10, 0 } ;
}
? "Creating Database...."
DbCreate( "testdbf", aStruct, "DBFCDX", .T., "MYALIAS" )
MyAlias->(dbAppend())

MyAlias->Memo := "Memofield 1" // Insert text to Menmfield 1
FieldPut (7, "Memofield 2") // Insert text to Memofield 2

Browse()

RETURN

I've tested and with fivewin works fine, without not.

Re: It is possible to create a dbf table with two...

PostPosted: Wed Mar 09, 2011 4:03 pm
by driessen
Marco,

I did the test and it works indeed.

But, fields with the same name in a DBF don't have any sence.

I browsed the result of your test. If I change the data in one field "SAMENAME", all the fields "SAMENAME" are changed.
So in fact there is only one field "SAMENAME".

Re: It is possible to create a dbf table with two...

PostPosted: Wed Mar 09, 2011 4:21 pm
by Bayron
Hi Driessen;
As James pointed up, Marco is reporting this issue as a bug....

Re: It is possible to create a dbf table with two...

PostPosted: Wed Mar 09, 2011 4:39 pm
by MarcoBoschi
Can any of you test the last sample?
Hello, see you tomorrow

Re: It is possible to create a dbf table with two...

PostPosted: Wed Mar 09, 2011 8:55 pm
by Enrico Maria Giordano
MarcoBoschi wrote:Please try this:


I just tried with Clipper 5.3b and found a similar behavior. Anyway, I will try to report it to the developers.

EMG

Re: It is possible to create a dbf table with two...

PostPosted: Wed Mar 09, 2011 9:39 pm
by Enrico Maria Giordano
It's a browse bug. Try this (many thanks to Andi):

Code: Select all  Expand view
FUNCTION MAIN()

    DBCREATE( "MYTEST", { { "TEST", "C", 35, 0 },;
                          { "TEST", "C", 35, 0 } } )

    USE MYTEST

    APPEND BLANK

    FIELDPUT( 1, "Test 1" )
    FIELDPUT( 2, "Test 2" )

    ? FIELDGET( 1 )
    ? FIELDGET( 2 )

    CLOSE

    INKEY( 0 )

    RETURN NIL


EMG

Re: It is possible to create a dbf table with two...

PostPosted: Thu Mar 10, 2011 7:24 am
by MarcoBoschi
Many Thanks Enrico!