Page 1 of 1

Database clase. Detectado una incidencia.

Posted: Thu Jun 15, 2017 6:38 pm
by thefull
Buenas

He decidido usar _ autoincremental que nos provee Harbour en la estructura de una DBF, pero si se usa la clase DATABASE,
en un registro nuevo, ejemplo;

Code: Select all

oDbf:Blank()
oDbf:Append()

oDbf:loquesea := "LALALA"

oDbf:Save()
 
El campo autoincremental vamos a tener un bonito cero
El tema es que , creo, la autoasignación que se realiza al llamar a :blank() ocasiona esto. No he podido mirar más la clase, pero para solucionarlo
antes, del Save(), asignarle NIL al campo autoincremental soluciona el problema.

Ala, ahí lo dejo ;-)

Re: Database clase. Detectado una incidencia.

Posted: Thu Jun 15, 2017 7:17 pm
by Frafive
Rafa, no sabia lo del campo autoincremental, siempre he utilizado el recno(), donde se puede ver el campo autoincremental ?

Saludos
Gabriel

Re: Database clase. Detectado una incidencia.

Posted: Thu Jun 15, 2017 7:59 pm
by thefull
Buenas, supongo que viendo el changelog en su día, la verdad es que si te quieres
enterar lo que trae harbour, ver el Changelog es una fuente de sorpresas.

Es triste que muchas cosas que se implementan en este lenguaje, pasen desapercibidos para la mayoría,
que solo lo ve como un Clipper 32 bits. ;-(

Re: Database clase. Detectado una incidencia.

Posted: Sun Jun 18, 2017 4:03 pm
by James Bott
Gabriel,

Nunca utilice recno () para IDs. Cuando elimine registros y empaquete la base de datos toda la base de datos obtendrá nuevos números de registro y todo estará dañado.

Al definir la base de datos, defina el campo ID como "+" para obtener un campo de autoincremento.

James

Re: Database clase. Detectado una incidencia.

Posted: Mon Jun 19, 2017 3:11 pm
by nageswaragunupudi
TDatabase works perfectly with AutoIncrement ( "+" ) fields and also timestamp ( "=" ) fields perfectly well, unless you are using a very very old version of FWH.

There is no need to fix FWH library of TDatabase.

Code: Select all

   DBCREATE( "TESTAUTO.DBF", { { "ID", "+", 4, 0 }, { "NAME", "C", 20, 0 }, ;
                              { "UPDT", "=", 8, 0 } }, "DBFCDX" )
   USE TESTAUTO
   DATABASE oDbf

   oDbf:Blank()
   oDbf:name := "name-one"
   oDbf:Append()
   oDbf:Save()

   oDbf:Blank()
   oDbf:name := "name-second"
   oDbf:Append()
   oDbf:Save()

   XBROWSER oDbf
 
Image

Re: Database clase. Detectado una incidencia.

Posted: Mon Jun 19, 2017 8:39 pm
by thefull
Hi nageswaragunupudi

Sorry, the order, and the field database is create with "I+" , i use ntx ;

oDbf:Append()
oDbf:Blank()
oDbf:name := "name-one"
oDbf:Save()

Please, confirm, i have new release of FWH 1705

Re: Database clase. Detectado una incidencia.

Posted: Mon Jun 19, 2017 8:47 pm
by nageswaragunupudi
thefull wrote:Hi nageswaragunupudi

Sorry, the order, and the field database is create with "I+" , i use ntx ;

oDbf:Append()
oDbf:Blank()
oDbf:name := "name-one"
oDbf:Save()

Please, confirm, i have new release of FWH 1705
This also works.
But not recommended.

We recommend:
1) oDbf:Blank()
2) Edit blank record
3) if the user wants to save then
(a) oDbf:Append() and oDbf:Save()
4) else ( user decides not to save)
(b) oDbf:Load()

Re: Database clase. Detectado una incidencia.

Posted: Tue Jun 20, 2017 12:53 am
by James Bott
Rafa,

You always want to do the Append() just before the Save().

Remember TDatabase is using buffers, so you just call oDBF:blank() to get an empty buffer. Then you add the data then call Append(). Note that Append() does not replace the current buffer with blank data, so your data in the buffer is still the same. Finally, you do the Save() which writes the buffer data to the disk, and in the case of autoincrement, the new value is generated and written to disk also.

Doing the append just before saving, as Nages has pointed out, gives the user the option to decline to save their changes. If the Append() is done before a user edit and they back out, then you end up with a bunch of blank records except for the autoincremented number field.

Regards,
James

Re: Database clase. Detectado una incidencia.

Posted: Tue Jun 20, 2017 8:13 am
by thefull
HI
Thank you by your explanation, James !
I alwways call Append and after Blank, change ;-)

Nageswaragunupudi , correct if yoy create field with "+" , correct, but if you create field "I+" , not correct.
I change at type "+"

Thank you!

Re: Database clase. Detectado una incidencia.

Posted: Tue Jun 20, 2017 8:16 am
by nageswaragunupudi
There is no field type as "I+"

Re: Database clase. Detectado una incidencia.

Posted: Tue Jun 20, 2017 8:19 am
by thefull
Hi, this example show

If activate line code assing NIL, this example is correct, if not, autoincrement not working

Code: Select all

DBCREATE( "TESTAUTO.DBF", { { "ID", "I:+", 4, 0 }, { "NAME", "C", 20, 0 }, ;
                              { "UPDT", "=", 8, 0 } }, "DBFNTX" )
   USE TESTAUTO
   DATABASE oDbf

   oDbf:Blank()
   oDbf:Append()
 //  oDbf:ID := NIL  
   oDbf:name := "name-one"
 
   oDbf:Save()

   oDbf:Blank()
   oDbf:Append()
   //oDbf:ID := NIL
   oDbf:name := "name-second"
   oDbf:Save()

   XBROWSER oDbf

Re: Database clase. Detectado una incidencia.

Posted: Tue Jun 20, 2017 8:24 am
by nageswaragunupudi
This is WRONG
{ "ID", "I:+", 4, 0 }
There is NO field type "I:+".
The problem is with your using "I:+" as field type.
Not with FWH library

Use

Code: Select all

{ "ID", "+", 4, 0 }
 

Re: Database clase. Detectado una incidencia.

Posted: Tue Jun 20, 2017 8:28 am
by thefull
HI,
Yes, i change at "+" in my code, but this feature is the Harbour ;

If the user FWH use TDatabase AND have field "I:+" , then he has a problem.

From Changelog Harbour;

2015-02-17 16:35 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* src/rdd/dbf1.c
+ added support for autoincrement fields with counter longer then 4 bytes
Warning: if someone created tables with such fields i.e. { "I:+", 8, 0 }
after my modification which added support for AutoInc flags in
all numeric DBF fields then he should update counters manually
using DBS_COUNTER flag. New code uses 64bit counters for such
field located in different part of DBFFIELD structure.

Re: Database clase. Detectado una incidencia.

Posted: Tue Jun 20, 2017 8:53 am
by nageswaragunupudi
Mr Rafa

Right. But because this practice is rarely used now, we took care of "+" and "=" only in TDatabase.
However I have added "I:+" also now. In FWH version 17.06, TDatabase will recognize "I:+" also but I advise you to change to "+" instead of "I:+". Is that okay with you?

Re: Database clase. Detectado una incidencia.

Posted: Tue Jun 20, 2017 11:06 am
by thefull
Hi nageswaragunupudi
Perfect!

Thank you very much!