Database clase. Detectado una incidencia.

Database clase. Detectado una incidencia.

Postby thefull » Thu Jun 15, 2017 6:38 pm

Buenas

He decidido usar los campos 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  Expand view

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__)
User avatar
thefull
 
Posts: 729
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona

Re: Database clase. Detectado una incidencia.

Postby Frafive » Thu Jun 15, 2017 7:17 pm

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

Saludos
Gabriel
Frafive
 
Posts: 189
Joined: Wed Apr 05, 2006 9:48 pm

Re: Database clase. Detectado una incidencia.

Postby thefull » Thu Jun 15, 2017 7:59 pm

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
thefull
 
Posts: 729
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona

Re: Database clase. Detectado una incidencia.

Postby James Bott » Sun Jun 18, 2017 4:03 pm

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
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Database clase. Detectado una incidencia.

Postby nageswaragunupudi » Mon Jun 19, 2017 3:11 pm

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  Expand view
  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
nageswaragunupudi
 
Posts: 10209
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Database clase. Detectado una incidencia.

Postby thefull » Mon Jun 19, 2017 8:39 pm

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
thefull
 
Posts: 729
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona

Re: Database clase. Detectado una incidencia.

Postby nageswaragunupudi » Mon Jun 19, 2017 8:47 pm

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
nageswaragunupudi
 
Posts: 10209
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Database clase. Detectado una incidencia.

Postby James Bott » Tue Jun 20, 2017 12:53 am

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
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Database clase. Detectado una incidencia.

Postby thefull » Tue Jun 20, 2017 8:13 am

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
thefull
 
Posts: 729
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona

Re: Database clase. Detectado una incidencia.

Postby nageswaragunupudi » Tue Jun 20, 2017 8:16 am

There is no field type as "I+"
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10209
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Database clase. Detectado una incidencia.

Postby thefull » Tue Jun 20, 2017 8:19 am

Hi, this example show

If activate line code assing NIL, this example is correct, if not, autoincrement not working
Code: Select all  Expand view
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
thefull
 
Posts: 729
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona

Re: Database clase. Detectado una incidencia.

Postby nageswaragunupudi » Tue Jun 20, 2017 8:24 am

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  Expand view

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10209
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Database clase. Detectado una incidencia.

Postby thefull » Tue Jun 20, 2017 8:28 am

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
thefull
 
Posts: 729
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona

Re: Database clase. Detectado una incidencia.

Postby nageswaragunupudi » Tue Jun 20, 2017 8:53 am

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
nageswaragunupudi
 
Posts: 10209
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Database clase. Detectado una incidencia.

Postby thefull » Tue Jun 20, 2017 11:06 am

Hi nageswaragunupudi
Perfect!

Thank you very much!
Saludos
Rafa Carmona ( rafa.thefullARROBAgmail.com___quitalineas__)
User avatar
thefull
 
Posts: 729
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 27 guests