Necsito hacer una extension a la clase MARIADB

Necsito hacer una extension a la clase MARIADB

Postby goosfancito » Sun Apr 17, 2022 8:04 am

Hola.
La forma en que se graba en la DB con el souce original de FWH es tedioso cuando tenes muchos campos, hablo de esto:
Code: Select all  Expand view
                    "idcarpeta, iddante, generacion, fecha_a, lugar_a, tipo_registro," + ;
                     ;
                     "nombre1, nombre2, nombre3, nombre4, apellido1, apellido2, edad_registro, edad_unidad, nacionalidad, " + ;
                     ;
                     "idprogenitor1, idprogenitor2, " + ;
                     "p_nombre1, p_nombre2, p_nombre3, p_nombre4, p_apellido1, p_apellido2, " + ;
                     "p_fecha_a, p_edad_registro, p_edad_unidad, p_nacionalidad, " + ;
                     "m_nombre1, m_nombre2, m_nombre3, m_nombre4, m_apellido1, m_apellido2, " + ;
                     "m_fecha_a, m_edad_registro, m_edad_unidad, m_nacionalidad, " + ;
                     ;
                     "idabuelo1_p, idabuelo2_p, " + ;
                     "abo_p_nombre1, abo_p_nombre2, abo_p_nombre3, abo_p_nombre4, abo_p_apellido1, abo_p_apellido2, " + ;
                     "abo_p_fecha_a, abo_p_edad_registro, abo_p_edad_unidad, abo_p_nacionalidad, " + ;
                     "aba_p_nombre1, aba_p_nombre2, aba_p_nombre3, aba_p_nombre4, aba_p_apellido1, aba_p_apellido2, " + ;
                     "aba_p_fecha_a, aba_p_edad_registro, aba_p_edad_unidad, aba_p_nacionalidad, " + ;
                     ;
 


Necesito adaptar lo que yo venia utilizando que es pasarle un par de valores
Code: Select all  Expand view
{ [campo], [valor] }


Como hago una extensión a esa clase para poder hacer un metodo Insert_2?

gracias.
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: Necsito hacer una extension a la clase MARIADB

Postby nageswaragunupudi » Sun Apr 17, 2022 1:59 pm

Can you show one sample call to insert method you are using.
We will suggest simper approach.
Regards

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

Re: Necsito hacer una extension a la clase MARIADB

Postby goosfancito » Sun Apr 17, 2022 4:10 pm

::oCnx:insert(
Code: Select all  Expand view
IIf( lArbol, "tbauxiliar", "tba" ), ;
                     "idcarpeta, iddante, generacion, fecha_a, lugar_a" + ;
                     { ;
                       ::nIdCarpeta , ;
                       ::nIDa , ;
                       ::oGets[ 133 ]:nAt , ;
                       fecha( ::vGets[ 01 ] ) , ;
                     } ;
                   )
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: Necsito hacer una extension a la clase MARIADB

Postby nageswaragunupudi » Sun Apr 17, 2022 5:32 pm

Ok.
1) If you have a new method insert_2, then how do you want to simplify the above code?
Can you please show us the simplified code?

2) "idcarpeta, iddante, generacion, fecha_a, lugar_a" +
Are they all fields of the table? Or only some selected fields?
Regards

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

Re: Necsito hacer una extension a la clase MARIADB

Postby goosfancito » Sun Apr 17, 2022 7:59 pm

1)
Code: Select all  Expand view

FUNCTION insert_2( cTabla, aFV )

   LOCAL this:= QSelf()
   LOCAL aItems
   LOCAL aFlds := { }
   LOCAL aVals := { }

   FOR EACH aItems IN aFV
      IF HB_IsString( aItems[ 02 ] )
         aItems[ 02 ] := LTrim( aItems[ 02 ] )
      ENDIF
      AAdd( aFlds, aItems[ 01 ] )
      AAdd( aVals, aItems[ 02 ] )
   NEXT

   RETURN this:Insert( cTabla, aFlds, aVals )

//------------------------------------------------------------------------------

FUNCTION update_2( cTabla, aFV, cCampo, nId )

   LOCAL this:= QSelf()
   LOCAL aItems
   LOCAL aFlds := { }
   LOCAL aVals := { }
   LOCAL cWhere:= cCampo + " = " + ClipValue2SQL(nId)

   FOR EACH aItems IN aFV
      IF HB_IsString( aItems[ 02 ] )
         aItems[ 02 ] := LTrim( aItems[ 02 ] )
      ENDIF
      AAdd( aFlds, aItems[ 01 ] )
      AAdd( aVals, aItems[ 02 ] )
   NEXT

   RETURN this:update( cTabla, aFlds, aVals, cWhere )
 


for example:
Code: Select all  Expand view
::oCnx:insert_2("tba",;
                                   {;
                                       { ::nIdCarpeta, ::ogets[133]:nAt},;
                                       {::nIda, ::ogets[01]};
                                   };
                                 )



2) yes! are my field name.
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: Necsito hacer una extension a la clase MARIADB

Postby nageswaragunupudi » Mon Apr 18, 2022 2:28 am

for example:

Code: Select all  Expand view
::oCnx:insert_2("tba",;
                                   {;
                                       { ::nIdCarpeta, ::ogets[133]:nAt},;
                                       {::nIda, ::ogets[01]};
                                   };
                                 )
 


This is not correct.
Probably you meant
Code: Select all  Expand view
::oCnx:insert_2("tba",;
                                   {;
                                       { "nIdCarpeta", ::ogets[133]:nAt},;
                                       {  "nIda", ::ogets[01]};
                                   };
                                 )
 


If so, you need not have a new method.
Present insert method also does it.
Please try
Code: Select all  Expand view
::oCnx:insert("tba",;
                                   {;
                                       { "nIdCarpeta", ::ogets[133]:nAt},;
                                       {  "nIda", ::ogets[01]};
                                   };
                                 )
 

This also works with the existing method Insert()
Please go through the documentation again before you think of any extensions.
Regards

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

Re: Necsito hacer una extension a la clase MARIADB

Postby goosfancito » Mon Apr 18, 2022 2:46 am

wow!
so good!
thanks
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: Necsito hacer una extension a la clase MARIADB

Postby nageswaragunupudi » Mon Apr 18, 2022 4:13 am

ClipValue2SQL() is not availabe in FWH native SQL library.
Instead, you can use
Code: Select all  Expand view

oCn:ValToSQL( uValue )
 


You can also use Update method like this:
Code: Select all  Expand view

oCn:Update( cTable, { { fieldname1, uVal1 }, ;
                      { fieldname2, uVal2 }, ;
                      ...
                      { fieldnameN, uValN }  }, nil, { "id", 250 } )
 

This method translates { "id", 250 } as proper Where clause as "id = 250"
Regards

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

Re: Necsito hacer una extension a la clase MARIADB

Postby goosfancito » Wed Apr 27, 2022 7:52 pm

i need do this:

update tbarbol where id=20

Code: Select all  Expand view
     
    ::nIdCortar:=20
    nIdPegar:= 10
   
    ::oCnx:update( "tbarbol", ;
                     { ;
                       { "nidpadre", nIdPegar } ;
                     }, NIL, ;
                     { "nid", ::nIdCortar } ;
                   )
 

but when i see the last select, it show:
UPDATE `tbarbol` SET `nidpadre` = 12 WHERE ( `nid` IS NULL OR `nid` = NULL )


How do I have to do it?
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: Necsito hacer una extension a la clase MARIADB

Postby nageswaragunupudi » Fri Apr 29, 2022 6:45 am

We are looking into this.
Regards

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

Re: Necsito hacer una extension a la clase MARIADB

Postby nageswaragunupudi » Fri Apr 29, 2022 3:48 pm

Please check this.
This is the correct syntax:

Code: Select all  Expand view
::nIdCortar:=20
nIdPegar:= 10
 
::oCnx:update( "tbarbol", ;
                { ;
                  { "nidpadre", nIdPegar } ;
                }, ;
                NIL, ;
                { ;
                  { "nid", ::nIdCortar } ;
                }
             )
 


I am sorry I gave you a wrong syntax earlier.
Regards

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

Re: Necsito hacer una extension a la clase MARIADB

Postby goosfancito » Sat Apr 30, 2022 12:15 am

Now it is work!
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 87 guests

cron