Database clase. Detectado una incidencia.

Post Reply
User avatar
thefull
Posts: 720
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona
Contact:

Database clase. Detectado una incidencia.

Post 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 ;-)
Saludos
Rafa Carmona ( rafa.thefullARROBAgmail.com___quitalineas__)
Frafive
Posts: 189
Joined: Wed Apr 05, 2006 9:48 pm

Re: Database clase. Detectado una incidencia.

Post by Frafive »

Rafa, no sabia lo del campo autoincremental, siempre he utilizado el recno(), donde se puede ver el campo autoincremental ?

Saludos
Gabriel
User avatar
thefull
Posts: 720
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona
Contact:

Re: Database clase. Detectado una incidencia.

Post 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. ;-(
Saludos
Rafa Carmona ( rafa.thefullARROBAgmail.com___quitalineas__)
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Database clase. Detectado una incidencia.

Post 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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Database clase. Detectado una incidencia.

Post 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
Regards

G. N. Rao.
Hyderabad, India
User avatar
thefull
Posts: 720
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona
Contact:

Re: Database clase. Detectado una incidencia.

Post 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
Saludos
Rafa Carmona ( rafa.thefullARROBAgmail.com___quitalineas__)
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Database clase. Detectado una incidencia.

Post 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()
Regards

G. N. Rao.
Hyderabad, India
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Database clase. Detectado una incidencia.

Post 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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
thefull
Posts: 720
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona
Contact:

Re: Database clase. Detectado una incidencia.

Post 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!
Saludos
Rafa Carmona ( rafa.thefullARROBAgmail.com___quitalineas__)
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Database clase. Detectado una incidencia.

Post by nageswaragunupudi »

There is no field type as "I+"
Regards

G. N. Rao.
Hyderabad, India
User avatar
thefull
Posts: 720
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona
Contact:

Re: Database clase. Detectado una incidencia.

Post 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
Saludos
Rafa Carmona ( rafa.thefullARROBAgmail.com___quitalineas__)
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Database clase. Detectado una incidencia.

Post 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 }
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
thefull
Posts: 720
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona
Contact:

Re: Database clase. Detectado una incidencia.

Post 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.
Saludos
Rafa Carmona ( rafa.thefullARROBAgmail.com___quitalineas__)
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Database clase. Detectado una incidencia.

Post 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?
Regards

G. N. Rao.
Hyderabad, India
User avatar
thefull
Posts: 720
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona
Contact:

Re: Database clase. Detectado una incidencia.

Post by thefull »

Hi nageswaragunupudi
Perfect!

Thank you very much!
Saludos
Rafa Carmona ( rafa.thefullARROBAgmail.com___quitalineas__)
Post Reply