FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Database clase. Detectado una incidencia.
Posts: 731
Joined: Fri Oct 07, 2005 07:42 AM
Database clase. Detectado una incidencia.
Posted: Thu Jun 15, 2017 06: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 (fw): Select all Collapse
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__)
Posts: 189
Joined: Wed Apr 05, 2006 09:48 PM
Re: Database clase. Detectado una incidencia.
Posted: Thu Jun 15, 2017 07:17 PM

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

Saludos
Gabriel

Posts: 731
Joined: Fri Oct 07, 2005 07:42 AM
Re: Database clase. Detectado una incidencia.
Posted: Thu Jun 15, 2017 07: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__)
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Database clase. Detectado una incidencia.
Posted: Sun Jun 18, 2017 04: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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Database clase. Detectado una incidencia.
Posted: Mon Jun 19, 2017 03: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 (fw): Select all Collapse
   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

Regards



G. N. Rao.

Hyderabad, India
Posts: 731
Joined: Fri Oct 07, 2005 07:42 AM
Re: Database clase. Detectado una incidencia.
Posted: Mon Jun 19, 2017 08: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__)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Database clase. Detectado una incidencia.
Posted: Mon Jun 19, 2017 08: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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Database clase. Detectado una incidencia.
Posted: 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
Posts: 731
Joined: Fri Oct 07, 2005 07:42 AM
Re: Database clase. Detectado una incidencia.
Posted: Tue Jun 20, 2017 08: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__)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Database clase. Detectado una incidencia.
Posted: Tue Jun 20, 2017 08:16 AM

There is no field type as "I+"

Regards



G. N. Rao.

Hyderabad, India
Posts: 731
Joined: Fri Oct 07, 2005 07:42 AM
Re: Database clase. Detectado una incidencia.
Posted: Tue Jun 20, 2017 08:19 AM
Hi, this example show

If activate line code assing NIL, this example is correct, if not, autoincrement not working
Code (fw): Select all Collapse
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__)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Database clase. Detectado una incidencia.
Posted: Tue Jun 20, 2017 08: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 (fw): Select all Collapse
{ "ID", "+", 4, 0 }
Regards



G. N. Rao.

Hyderabad, India
Posts: 731
Joined: Fri Oct 07, 2005 07:42 AM
Re: Database clase. Detectado una incidencia.
Posted: Tue Jun 20, 2017 08: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__)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Database clase. Detectado una incidencia.
Posted: Tue Jun 20, 2017 08: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
Posts: 731
Joined: Fri Oct 07, 2005 07:42 AM
Re: Database clase. Detectado una incidencia.
Posted: Tue Jun 20, 2017 11:06 AM

Hi nageswaragunupudi
Perfect!

Thank you very much!

Saludos

Rafa Carmona ( rafa.thefullARROBAgmail.com___quitalineas__)

Continue the discussion