Editar RowSet con dos tablas - At. Mr. Rao

Editar RowSet con dos tablas - At. Mr. Rao

Postby Marcelo Roggeri » Tue Jul 09, 2019 4:09 pm

Mr. Rao necesito editar una tabla de ventas mostrando el nombre del cliente, pero no logro ver el campo del cliente en oRec
Este es un ejemplo de practica para ir entendiendo el manejo nativo de mysql

Code: Select all  Expand view

#include "fivewin.ch"

STATIC oConn

Function main()
         local lDBOk, aStru, cQuery, oQry

         FWCONNECT oConn HOST "127.0.0.1" USER "root" PASSWORD "1234"  DB "fwhnativo"  PORT 3306
         IF oConn==nil
            ? "ERROR DE CONEXION"
            RETURN NIL
         ENDIF

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

         aStru := { { "id_cliente",   "+",  11, 0 },;
                    { "name",         "C", 100, 0,"utf8" } }

         oConn:DropTable( "clientes" )

         oConn:CreateTable( "clientes", aStru, , "utf8" )

         oConn:Insert( "clientes", "name", { 'Distribuidora Pepe' } )
         oConn:Insert( "clientes", "name", { 'Estacion de Servicio YPF' } )
         oConn:Insert( "clientes", "name", { 'Agropecuaria Venado' } )

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

         aStru := { { "id_venta",     "+", 11, 0 },;
                    { "id_cliente",   "INT", 11, 0 },;
                    { "fecha",        "D",  8, 0 },;
                    { "cpte",         "C", 15, 0,"utf8" },;
                    { "importe",      "N", 12, 2 } }

         oConn:DropTable( "ventas" )

         if !oConn:TableExists( "ventas" )

         oConn:CreateTable( "ventas", aStru, , "utf8" )

         oConn:Insert( "ventas", "id_cliente,fecha,cpte,importe", { 1,'2019-07-01','Factura',1200 } )
         oConn:Insert( "ventas", "id_cliente,fecha,cpte,importe", { 2,'2019-07-01','Factura',2400 } )
         oConn:Insert( "ventas", "id_cliente,fecha,cpte,importe", { 3,'2019-07-01','Factura',3500 } )
         oConn:Insert( "ventas", "id_cliente,fecha,cpte,importe", { 2,'2019-07-01','Factura', 200 } )
         oConn:Insert( "ventas", "id_cliente,fecha,cpte,importe", { 3,'2019-07-01','Factura',1000 } )
         oConn:Insert( "ventas", "id_cliente,fecha,cpte,importe", { 1,'2019-07-01','Factura', 950 } )
         oConn:Insert( "ventas", "id_cliente,fecha,cpte,importe", { 2,'2019-07-01','Factura', 350 } )
         oConn:Insert( "ventas", "id_cliente,fecha,cpte,importe", { 2,'2019-07-01','Factura',9500 } )
         oConn:Insert( "ventas", "id_cliente,fecha,cpte,importe", { 3,'2019-07-01','Factura',2200 } )
         oConn:Insert( "ventas", "id_cliente,fecha,cpte,importe", { 2,'2019-07-01','Factura',3200 } )
         oConn:Insert( "ventas", "id_cliente,fecha,cpte,importe", { 1,'2019-07-01','Factura',4200 } )
         oConn:Insert( "ventas", "id_cliente,fecha,cpte,importe", { 3,'2019-07-01','Factura',5200 } )
         oConn:Insert( "ventas", "id_cliente,fecha,cpte,importe", { 3,'2019-07-01','Factura',5200 } )
         oConn:Insert( "ventas", "id_cliente,fecha,cpte,importe", { 1,'2019-07-01','Factura',6200 } )

         ENDIF
         //-----------------------------------------------------------------

         if !oConn:TableExists( "ventas_item" )
            oConn:CreateTable( "ventas_item", { ;
                                                { "id_item",         '+',   11, 0 }, ;
                                                { "id_venta", "REFERENCES ventas(id_venta) ON UPDATE CASCADE ON DELETE CASCADE" },;
                                                { "cantidad",        'N',   12, 2 }, ;
                                                { "precio_unitario", 'N',   12, 2 }, ;
                                                { "fecha_creada",    '=',    8, 0 };
                                              }, nil, "utf8" )


            oConn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", { 1,2,600 } )
            oConn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", { 2,3,800 } )
            oConn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", { 3,1,3500 } )
            oConn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", { 4,2, 100 } )
            oConn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", { 5,2, 500 } )
            oConn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", { 6,1, 950 } )
            oConn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", { 7,1, 350 } )
            oConn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", { 8,1,9500 } )
            oConn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", { 9,2,1100 } )
            oConn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", {10,1,3200 } )
            oConn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", {11,1,4200 } )
            oConn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", {12,1,5200 } )
            oConn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", {13,1,5200 } )
            oConn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", {14,1,6200 } )

         endif

         brw()

Return nil

// EDICION DE VENTAS CON LEFT JOIN A CLIENTES
function brw()
   local oDlg, oQry, oBrw

   oQry := oConn:RowSet("SELECT t1.*, t2.name FROM ventas t1 LEFT JOIN clientes t2 ON t1.id_cliente=t2.id_cliente WHERE t1.id_venta=6")

   xbrowse(oQry)

   DEFINE DIALOG oDlg SIZE 400,470 PIXEL TRUEPIXEL

      @ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg;
              DATASOURCE oQry AUTOCOLS;
              COLSIZES -4, -20, -20;
              CELL LINES NOBORDER FOOTERS

      oQry:EditBaseRecord( nil, .f., { |oRec| MyEditDlg( oRec ) }, oBrw )

   ACTIVATE DIALOG oDlg

   xBrowse(oQry)

return nil
//--------------------------------------------------------------------------
function MyEditDlg( oRec )
   local lNew     := ( oRec:RecNo == 0 )
   local oDlg, oFont
   LOCAL cCliente  //  :=oRec:aData["name"]

xbrowse(oRec:aData)

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-15
   
   DEFINE DIALOG oDlg SIZE 400,470 PIXEL TRUEPIXEL FONT oFont;
          TITLE If( lNew, "ADD NEW ", "EDIT" ) + " RECORD"

      @ 030,020 SAY "ID Cliente:"      SIZE 80,20 PIXEL OF oDlg RIGHT
      @ 060,020 SAY "First"            SIZE 80,20 PIXEL OF oDlg RIGHT
      @ 090,020 SAY "Last"             SIZE 80,20 PIXEL OF oDlg RIGHT
      @ 120,020 SAY "Cliente"          SIZE 80,20 PIXEL OF oDlg RIGHT
     
     
      @ 030,120 GET oRec:id_cliente    SIZE 100,22 PIXEL OF oDlg READONLY RIGHT
     
      @ 060,120 GET oRec:fecha         SIZE 240,22 PIXEL OF oDlg VALID !Empty( oRec:fecha )
     
      @ 090,120 GET oRec:importe       SIZE 240,22 PIXEL OF oDlg PICTURE "999999.99" VALID !Empty( oRec:importe )
     
      @ 120,120 GET cCliente           SIZE 240,22 PIXEL OF oDlg READONLY
     
      @ 420,020 BTNBMP PROMPT "Save"   SIZE 150,30 PIXEL FLAT OF oDlg ;
                ACTION ( If( oRec:Modified(), oRec:Save(), nil ), oDlg:End() ) WHEN oRec:Modified()
     
      @ 420,240 BTNBMP PROMPT "Cancel" SIZE 150,30 PIXEL FLAT OF oDlg ACTION oDlg:End()
     
   ACTIVATE DIALOG oDlg CENTERED

      //ON PAINT oDlg:Box( 15, 10, 395, 390 )
   xBrowse(oRec:aData)

return nil
//--------------------------------------------------------------------------
 

Gracias
Saludos
FWH - Harbour - BCC7 - PellesC
User avatar
Marcelo Roggeri
 
Posts: 325
Joined: Sat Jul 22, 2006 9:04 pm
Location: Venado Tuerto - Santa Fe -Argentina

Re: Editar RowSet con dos tablas - At. Mr. Rao

Postby armando.lagunas » Wed Jul 10, 2019 1:24 pm

es idea mía o no tienes la equivalencia a la llamada id_cliente?

Code: Select all  Expand view

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

         aStru := { { "id_cliente",   "+",  11, 0 },;
                    { "name",         "C", 100, 0,"utf8" } }

         oConn:DropTable( "clientes" )

         oConn:CreateTable( "clientes", aStru, , "utf8" )

         oConn:Insert( "clientes", "name", { 'Distribuidora Pepe' } )
         oConn:Insert( "clientes", "name", { 'Estacion de Servicio YPF' } )
         oConn:Insert( "clientes", "name", { 'Agropecuaria Venado' } )

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

para mi sería asi...
oConn:Insert( "clientes","id_cliente", "name", { 1, 'Distribuidora Pepe' } )

para que tome de forma correcta la clave del LEFT JOIN t1.id_cliente=t2.id_cliente

Code: Select all  Expand view

   oQry := oConn:RowSet("SELECT t1.*, t2.name FROM ventas t1 LEFT JOIN clientes t2 ON t1.id_cliente=t2.id_cliente WHERE t1.id_venta=6")
 


seria lo único que encuentro para que el nombre no aparezca en el resultado de la consulta
SkyPe: armando.lagunas@hotmail.com
Mail: armando.lagunas@gmail.com
User avatar
armando.lagunas
 
Posts: 346
Joined: Mon Oct 05, 2009 3:35 pm
Location: Curico-Chile

Re: Editar RowSet con dos tablas - At. Mr. Rao

Postby Marcelo Roggeri » Wed Jul 10, 2019 1:59 pm

Armando ante todo gracias por tomarte el tiempo de responder, si compilas el ejemplo te vas a dar cuenta de lo que menciono.
Solo cambiale el pass a la conexion.
a name solo lo necesito para mostrar el nombre del cliente en este caso, cuando hago la edicion
Saludos
FWH - Harbour - BCC7 - PellesC
User avatar
Marcelo Roggeri
 
Posts: 325
Joined: Sat Jul 22, 2006 9:04 pm
Location: Venado Tuerto - Santa Fe -Argentina

Re: Editar RowSet con dos tablas - At. Mr. Rao

Postby nageswaragunupudi » Thu Jul 11, 2019 4:22 am

Please do not use EditBaseRecord for normal editing. This method has a special purpose to be used under particual situations. We will explain this in the next post.

When you open a RowSet, it is immediately ready to be edited by calling
Code: Select all  Expand view

oRs:Edit()  // editing current record
oRs:Edit( .t. ) // Adding new record
 

By default, the default Edit Dialog of FWH is used, which provides for navigation, save, undo, etc.

If you want to use your custom dialog, then
Code: Select all  Expand view

oRs:bEdit := { |oRec| MyEditDlg( oRec ) }
 

In this case, oRs:Edit() and oRs:Edit( .t. ) will use the custom dialog, i.e., MyEditDlg.

When you browse the RowSet with XBrwose, use oBrw:EditSource() and oBrw:EditSource( .t. ) for editing and appending. These methods of XBrowse, in turn, call oRs:Edit() and oRs:Edit(.t.).

We have re-written your sample. We used FWH DemoServer for the purpose of testing and you can change it to your own server. You can copy this program to FWH Samples folder and build with buildx.bat or buildh.bat without any changes.

You can provide a 2-dimensional array to oCn:Insert() method to insert many rows in a single call. Please see the sample.
Code: Select all  Expand view
#include "fivewin.ch"

static oCn

function Main()

   local oRs, cSql

   SET DATE ITALIAN
   SET CENTURY ON
   SetGetColorFocus()

// FWCONNECT oCn HOST "127.0.0.1" USER "root" PASSWORD "1234"  DB "fwhnativo"  PORT 3306
// For purpose of testing, we will use FWH Demo Server in the Cloud

   oCn   := FW_DemoDB()

   if oCn == nil
      ? "ERROR DE CONEXION"
      return nil
   endif

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

   MsgRun( "Creating Tables", "MYSQL", { || CreateTables() } )

TEXT INTO cSql
 SELECT t1.*, t2.name AS cliente
 FROM   ventas t1
 LEFT JOIN clientes t2
 ON     t1.id_cliente = t2.id_cliente
ENDTEXT

   oRs         := oCn:RowSet( cSql )

   // Call Edit() for editing and Edit( .t. ) for appending
   oRs:Edit()        // Use FW Default Dialog
   oRs:bEdit   := { |oRec| MyEditDlg( oRec ) } // Custom Dialog
   oRs:Edit()        // now edit uses custom dialog

   BrowseRowSet( oRs )

   oRs:Close()
   oCn:Close()

Return nil

function BrowseRowSet( oRs )

   local oDlg, oFont, oBrw

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 900,470 PIXEL TRUEPIXEL FONT oFont

   @ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg;
           DATASOURCE oRs AUTOCOLS;
           CELL LINES NOBORDER FOOTERS

   WITH OBJECT oBrw
      :CreateFromCode()
   END

   @ 20,20 BTNBMP PROMPT "EDIT" SIZE 100,40 PIXEL OF oDlg FLAT ;
      ACTION oBrw:EditSource()

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil
//--------------------------------------------------------------------------

function MyEditDlg( oRec )

   local lNew     := ( oRec:RecNo == 0 )
   local oDlg, oFont

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-15

   DEFINE DIALOG oDlg SIZE 400,470 PIXEL TRUEPIXEL FONT oFont;
          TITLE If( lNew, "ADD NEW ", "EDIT" ) + " RECORD"

   @ 040,020 SAY "ID Venta"         SIZE 80,20 PIXEL OF oDlg RIGHT
   @ 070,020 SAY "ID Cliente:"      SIZE 80,20 PIXEL OF oDlg RIGHT
   @ 100,020 SAY "Fecha"            SIZE 80,20 PIXEL OF oDlg RIGHT
   @ 130,020 SAY "Importe"          SIZE 80,20 PIXEL OF oDlg RIGHT
   @ 160,020 SAY "Cliente"          SIZE 80,20 PIXEL OF oDlg RIGHT

   @ 040,120 GET oRec:id_venta      SIZE 100,22 PIXEL OF oDlg READONLY UPDATE RIGHT

   @ 070,120 GET oRec:id_cliente    SIZE 100,22 PIXEL OF oDlg READONLY UPDATE RIGHT

   @ 100,120 GET oRec:fecha         SIZE 120,22 PIXEL OF oDlg UPDATE VALID !Empty( oRec:fecha )

   @ 130,120 GET oRec:importe       SIZE 120,22 PIXEL OF oDlg PICTURE "999999.99" RIGHT UPDATE VALID ( oRec:importe > 0 )

   @ 160,120 GET oRec:cliente       SIZE 240,22 PIXEL OF oDlg READONLY UPDATE

   @ 380,020 BTNBMP PROMPT "<<" SIZE 40,30 PIXEL FLAT OF oDlg ACTION ( oRec:GoTop(), oDlg:Update() )
   @ 380,060 BTNBMP PROMPT "<"  SIZE 40,30 PIXEL FLAT OF oDlg ACTION ( oRec:GoUp(), oDlg:Update() )
   @ 380,100 BTNBMP PROMPT ">"  SIZE 40,30 PIXEL FLAT OF oDlg ACTION ( oRec:GoDown(), oDlg:Update() )
   @ 380,140 BTNBMP PROMPT ">>" SIZE 40,30 PIXEL FLAT OF oDlg ACTION ( oRec:GoBottom(), oDlg:Update() )

   @ 420,080 BTNBMP PROMPT "Undo"   SIZE 090,30 PIXEL FLAT OF oDlg WHEN oRec:Modified() ;
             ACTION ( oRec:Undo(), oDlg:Update() )

   @ 420,180 BTNBMP PROMPT "Save"   SIZE 090,30 PIXEL FLAT OF oDlg WHEN oRec:Modified() ;
             ACTION ( oRec:Save(), oDlg:Update() )

   @ 420,280 BTNBMP PROMPT "Close" SIZE 090,30 PIXEL FLAT OF oDlg ACTION oDlg:End()

   ACTIVATE DIALOG oDlg CENTERED

      //ON PAINT oDlg:Box( 15, 10, 395, 390 )

return nil
//--------------------------------------------------------------------------

static function CreateTables()

   local aStru, aData

   oCn:DropTable( "ventas_item" )
   oCn:DropTable( "ventas" )
   oCn:DropTable( "clientes" )

   //-----------------------------------------------------------------
   // clientes

   aStru := { { "id_cliente",   "+",  11, 0 },;
              { "name",         "C", 100, 0,"utf8" } }

   aData := { { 'Distribuidora Pepe' }, { 'Estacion de Servicio YPF' }, ;
              { 'Agropecuaria Venado' }  }

   oCn:CreateTable( "clientes", aStru, , "utf8" )
   oCn:Insert( "clientes", "name", aData )

   //-----------------------------------------------------------------
   // ventas

   aStru := { { "id_venta",     "+", 11, 0 },;
              { "id_cliente",   "REFERENCES clientes( id_cliente ) ON UPDATE CASCADE ON DELETE CASCADE" },;
              { "fecha",        "D",  8, 0 },;
              { "cpte",         "C", 15, 0,"utf8" },;
              { "importe",      "N", 12, 2 } }

   aData := { ;
      { 1, STOD( "20190701" ), 'Factura', 1200 },  ;
      { 2, STOD( "20190701" ), 'Factura', 2400 },  ;
      { 3, STOD( "20190701" ), 'Factura', 3500 },  ;
      { 2, STOD( "20190701" ), 'Factura',  200 },  ;
      { 3, STOD( "20190701" ), 'Factura', 1000 },  ;
      { 1, STOD( "20190701" ), 'Factura',  950 },  ;
      { 2, STOD( "20190701" ), 'Factura',  350 },  ;
      { 2, STOD( "20190701" ), 'Factura', 9500 },  ;
      { 3, STOD( "20190701" ), 'Factura', 2200 },  ;
      { 2, STOD( "20190701" ), 'Factura', 3200 },  ;
      { 1, STOD( "20190701" ), 'Factura', 4200 },  ;
      { 3, STOD( "20190701" ), 'Factura', 5200 },  ;
      { 3, STOD( "20190701" ), 'Factura', 5200 },  ;
      { 1, STOD( "20190701" ), 'Factura', 6200 }   }

   oCn:CreateTable( "ventas", aStru, , "utf8" )
   oCn:Insert( "ventas", "id_cliente,fecha,cpte,importe", aData )

   //-----------------------------------------------------------------
   // ventas_item

   aStru   := { ;
                  { "id_item",         '+',   11, 0 }, ;
                  { "id_venta", "REFERENCES ventas(id_venta) ON UPDATE CASCADE ON DELETE CASCADE" },;
                  { "cantidad",        'N',   12, 2 }, ;
                  { "precio_unitario", 'N',   12, 2 }, ;
                  { "fecha_creada",    '=',    8, 0 }  ;
               }
   aData := { {  1, 2,  600 }, {  2, 3,  800 }, {  3, 1, 3500 }, {  4, 2,  100 }, ;
              {  5, 2,  500 }, {  6, 1,  950 }, {  7, 1,  350 }, {  8, 1, 9500 }, ;
              {  9, 2, 1100 }, { 10, 1, 3200 }, { 11, 1, 4200 }, { 12, 1, 5200 }, ;
              { 13, 1, 5200 }, { 14, 1, 6200 } }

   oCn:CreateTable( "ventas_item", aStru, nil, "utf8" )
   oCn:Insert( "ventas_item", "id_venta,cantidad,precio_unitario", aData )

return nil

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


You may use this sample as a template for editing all or any of your RowSets/Queries.
Regards

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

Re: Editar RowSet con dos tablas - At. Mr. Rao

Postby Marcelo Roggeri » Thu Jul 11, 2019 9:46 am

Mr. Rao Fantástica explicación, no aguante a probarlo por darles las gracias por tal clase.
Ya mismo lo pruebo a su modificación.
Un saludos desde aqui.
Marcelo
FWH - Harbour - BCC7 - PellesC
User avatar
Marcelo Roggeri
 
Posts: 325
Joined: Sat Jul 22, 2006 9:04 pm
Location: Venado Tuerto - Santa Fe -Argentina

Re: Editar RowSet con dos tablas - At. Mr. Rao

Postby Marcelo Roggeri » Thu Jul 11, 2019 10:00 am

Anduvo como esperaba, eso es lo que necesitaba entender.
Otra cosa Mr. Rao, en un entorno donde halla muchos puestos de trabajo, que varios usuarios modifiquen esos satos, debo hacer algún bloqueo o de eso se encarga Mysql ?
o por ejemplo un Try Catch por si hubo algun problema al querer guardar los datos suponiendo que halla problemas de conexión
Gracias y Saludos Marcelo
FWH - Harbour - BCC7 - PellesC
User avatar
Marcelo Roggeri
 
Posts: 325
Joined: Sat Jul 22, 2006 9:04 pm
Location: Venado Tuerto - Santa Fe -Argentina

Re: Editar RowSet con dos tablas - At. Mr. Rao

Postby nageswaragunupudi » Thu Jul 11, 2019 10:24 am

Once you read the RowSet, we do not need the connection to the server except when we write modified data. Even if the connection is lost, we can still browse, sort, filter and use the data in any manner.

When we write data, if the connection is lost (for reasons like time-out), the library silently tries to reconnect to the server automatically and, if connected, resumes the operation normally as if nothing happened.

In case of break of physical connection (lan cables plugged out or internet connection lost), then the program will inform the user that the connection is lost and the writing is aborted. Without writing the program continues.

If the user then rectifies and condition, by re-plugging the cables or reconnecting to the internet, etc. and retries the operation, the library will again automatically reconnects to the server and continues the operation.

You need FWH version 2017 or later.

There is no use for TRY/CATCH. The library never raises runtime error when any MySql operation fails.

The programmer needs to check oCn:nError and take action.

Programmer can also set these flags:
oCn:lLog := .t. // Log all server operations
oCn:lLogErr := .t. // Log errors only
oCn:lShowErrors := .t. // Display error messages

May we know the FWH version you are using?
Regards

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

Re: Editar RowSet con dos tablas - At. Mr. Rao

Postby Marcelo Roggeri » Thu Jul 11, 2019 11:35 am

Fantástica explicación Mr. Rao
Mi version es April/May 2019
Saludos
Marcelo
FWH - Harbour - BCC7 - PellesC
User avatar
Marcelo Roggeri
 
Posts: 325
Joined: Sat Jul 22, 2006 9:04 pm
Location: Venado Tuerto - Santa Fe -Argentina

Re: Editar RowSet con dos tablas - At. Mr. Rao

Postby Ariel » Thu Jul 11, 2019 12:20 pm

Mr. Rao,

en mi app cuando grabo un venta y uso varios archivos por ejemplo contador, cabecera de ventas, detalle de ventas, etc, uso try/catch para controlar los errores, con esta modalidad como seria ? Tiene un ejemplo practico de como controla la grabacion en varios registros o como hace el rollback ?
Uso harbour / fwh 19.05

Muchas gracias.
Ariel
 
Posts: 374
Joined: Wed Nov 29, 2006 1:51 pm
Location: Rosario - Argentina

Re: Editar RowSet con dos tablas - At. Mr. Rao

Postby nageswaragunupudi » Thu Jul 11, 2019 1:06 pm

Writing data:
1) In case you already opened the table into a RowSet, you can write your modifications in two ways:
a) oRs:field1 := <value>
oRs:fieldN := <value>
...
oRs:Save()
OR
b) oRs:Update( cFieldList, aNewVAlues )

2) Directly writing to table without opening as RowSet
a) oCn:Update( table, fieldlist, aValues )
b) oCn:Insert( table, fieldlist, aValues )
c) oCn:Upsert( table, fieldlist, aValues )

Whatever way you write data, you can enclose in Beging/Commit Transactions;

Make a separate function to Write.
Example:
Code: Select all  Expand view

function WriteAll()

  oCn:BeginTransaction()
  <write to table1>
  if oCn:nError != 0
    oCn:RollBack()
    return .f.
  endif
  <repeat for all tables>
  <finally>
  oCn:CommitTransaction()

return .t.
 
Regards

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

Re: Editar RowSet con dos tablas - At. Mr. Rao

Postby Ariel » Thu Jul 11, 2019 1:30 pm

Muchas gracias, lo vamos a probar.
Saludos.
Ariel
 
Posts: 374
Joined: Wed Nov 29, 2006 1:51 pm
Location: Rosario - Argentina

Re: Editar RowSet con dos tablas - At. Mr. Rao

Postby Marcelo Roggeri » Tue Jul 16, 2019 12:59 am

Mr. Rao siguiendo el hilo con respecto al manejo de mysql nativo, le consulto lo siguiente:
Tengo un Dialog con Pestañas donde donde edito datos de Clientes, en la pestaña 1 y datos de vehiculos en la pestaña 2.
Si uso el método
Code: Select all  Expand view
oClientes:= ::oConn:RoweSet( "Clientes" )
oMovil:= ::oConn:RowSet( "vehiculos" )

luego,
Code: Select all  Expand view
oClientes:bEdit:= { |oRec| MyEditDlg( oRec ) }  
oClientes:Edit()

Adjunto imagen de muestra
Image
Un saludo a la distancia y muy agradecido por sus ayudas
Marcelo
FWH - Harbour - BCC7 - PellesC
User avatar
Marcelo Roggeri
 
Posts: 325
Joined: Sat Jul 22, 2006 9:04 pm
Location: Venado Tuerto - Santa Fe -Argentina

Re: Editar RowSet con dos tablas - At. Mr. Rao

Postby Horizon » Wed May 27, 2020 11:59 am

nageswaragunupudi wrote:Writing data:
1) In case you already opened the table into a RowSet, you can write your modifications in two ways:
a) oRs:field1 := <value>
oRs:fieldN := <value>
...
oRs:Save()
OR
b) oRs:Update( cFieldList, aNewVAlues )

2) Directly writing to table without opening as RowSet
a) oCn:Update( table, fieldlist, aValues )
b) oCn:Insert( table, fieldlist, aValues )
c) oCn:Upsert( table, fieldlist, aValues )

Whatever way you write data, you can enclose in Beging/Commit Transactions;

Make a separate function to Write.
Example:
Code: Select all  Expand view

function WriteAll()

  oCn:BeginTransaction()
  <write to table1>
  if oCn:nError != 0
    oCn:RollBack()
    return .f.
  endif
  <repeat for all tables>
  <finally>
  oCn:CommitTransaction()

return .t.
 


Hi Mr. Rao,

Is it possible to find out the primarykeys after using Insert a data.

Code: Select all  Expand view
aResult := oCn:Insert( table, fieldlist, aValues,,aReturnVal )
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

Re: Editar RowSet con dos tablas - At. Mr. Rao

Postby Horizon » Wed May 27, 2020 12:00 pm

Horizon wrote:
nageswaragunupudi wrote:Writing data:
1) In case you already opened the table into a RowSet, you can write your modifications in two ways:
a) oRs:field1 := <value>
oRs:fieldN := <value>
...
oRs:Save()
OR
b) oRs:Update( cFieldList, aNewVAlues )

2) Directly writing to table without opening as RowSet
a) oCn:Update( table, fieldlist, aValues )
b) oCn:Insert( table, fieldlist, aValues )
c) oCn:Upsert( table, fieldlist, aValues )

Whatever way you write data, you can enclose in Beging/Commit Transactions;

Make a separate function to Write.
Example:
Code: Select all  Expand view

function WriteAll()

  oCn:BeginTransaction()
  <write to table1>
  if oCn:nError != 0
    oCn:RollBack()
    return .f.
  endif
  <repeat for all tables>
  <finally>
  oCn:CommitTransaction()

return .t.
 


Hi Mr. Rao,

Is it possible to find out the primarykeys after using Insert a data.

Code: Select all  Expand view
aResult := oCn:Insert( table, fieldlist, aValues,,aReturnfieldlist )
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1288
Joined: Fri May 23, 2008 1:33 pm

Re: Editar RowSet con dos tablas - At. Mr. Rao

Postby nageswaragunupudi » Tue Jun 09, 2020 12:11 pm

The primary keys you are using may be either auto-increment values or manually assigned values.

If your primary key is manually assigned, you already know the primary key values you yourself inserted.

If the primary key is auto-increment, then you insert each row one by one. Do not insert multiple rows. After each insert, call
Code: Select all  Expand view

AAdd( aInsertedKeys, oCn:Last_Insert_ID() )
 
Regards

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

Next

Return to FiveWin para Harbour/xHarbour

Who is online

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