ORM power in next FWH

ORM power in next FWH

Postby Antonio Linares » Sun Apr 14, 2019 1:51 pm

Thanks to Harbour Magazine meeting in Calpe, Carlos Mora explained us the power of ORM :-)

Image

In a few words, ORM it is a set of classes to greatly simplify the use of SQL relational DataBases.

An example is worth a thousand words:
Code: Select all  Expand view  RUN
function Main()

   local oUsers := Users():New( "www.fivetechsoft.com:3306",;
                                "fivetech_users",;
                                "fivetech_antonio",;
                                "****" )
   
   oUsers:First:Edit()
   
   oUsers:Browse()

return nil


See how simple ORM turns our code:
Code: Select all  Expand view  RUN
oUsers:Find( 120 ):Edit()


This is really nice:
Code: Select all  Expand view  RUN
oUsers:Where( "country", "Spain" ):Where( "city", "Barcelona" ):Browse()

and this:
Code: Select all  Expand view  RUN
oUsers:Where( "country", "Sp%", "Br%", "Ind%" ):OrderBy( "city" ):Browse()

as simple as this:
Code: Select all  Expand view  RUN
oUsers:Select( "username", "city" ):Browse()


We are currently working on this ORM implementation for FWH and you will be using it real soon ;-)

Stay tuned for more examples comming these days!!!
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: ORM power in next FWH

Postby dutch » Sun Apr 14, 2019 3:06 pm

+1

It will be great, if it supports multi sql database (MySQL/MsSql/Oracle).
Regards,
Dutch

FWH 19.01 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio
FWPPC 10.02 / Harbour for PPC (FTDN)
ADS V.9 / MySql / MariaDB
R&R 12 Infinity / Crystal Report XI R2
(Thailand)
User avatar
dutch
 
Posts: 1543
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: ORM power in next FWH

Postby Antonio Linares » Sun Apr 14, 2019 3:47 pm

Duth,

Of course it does :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: ORM power in next FWH

Postby PabloHarbour » Mon Apr 15, 2019 3:12 am

Que Bueno que se está poniendo FWH Antonio !!! Lo felicito !!!
User avatar
PabloHarbour
 
Posts: 3
Joined: Fri Nov 28, 2008 3:19 am

Re: ORM power in next FWH

Postby Antonio Linares » Mon Apr 15, 2019 7:28 am

This is working already :-)

Code: Select all  Expand view  RUN
oUsers:Find( 3 ):Invoices:Browse()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: ORM power in next FWH

Postby Otto » Mon Apr 15, 2019 10:19 am

Dear Antonio,
can you please tell me the differences to what we have had so far.
Best regards
Otto



Code: Select all  Expand view  RUN
 
oCn   := maria_Connect( cServer, cDB, cUser, cPwd )
   XBROWSER oCn:ListTables() SETUP ( ;
      oBrw:aCols[ 1 ]:bLDClickData := { |r,c,f,o| XBrowse( oCn:RowSet( o:Value ) ) } )
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: ORM power in next FWH

Postby Antonio Linares » Mon Apr 15, 2019 11:15 am

Dear Otto,

The strongest difference comes when we manage tables with relations:

oUsers:Invoices:Browse()

oUsers:Invoices mimics "SET RELATION TO ..."

You select a user and invoices automatically deliver his invoices

There are more examples to come. You will notice how ORM is much simpler :-)

oUsers:Invoices:First:Items:First:Name ...
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: ORM power in next FWH

Postby Marcelo Via Giglio » Mon Apr 15, 2019 12:46 pm

excelente
Marcelo Via Giglio
 
Posts: 1065
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: ORM power in next FWH

Postby Antonio Linares » Tue Apr 16, 2019 9:58 pm

Notice this interesting detail:

Code: Select all  Expand view  RUN
METHOD Invoices() CLASS Users

   if ::nLastId != ::oRs:Id
      ::nLastId = ::oRs:Id
      ::_Invoices:Where( "user_id", ::oRs:Id )
   endif

return ::_Invoices


Only if a different user is selected then the Invoices are reloaded.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: ORM power in next FWH

Postby nageswaragunupudi » Sat May 18, 2019 9:04 am

Example of setting relationships between tables on different servers connected by different libraries:

Image

Code: Select all  Expand view  RUN
#include "fivewin.ch"

static oMySql, oMsSql   // Servers

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

function Main()

   local oStates, oCustomers

   oMySql   := ORM_Connection():New( "DOLPHIN",   "DEMO" )
   oMsSql   := ORM_Connection():New( "MSSQL",     "DEMO" )

   oStates     := oMySql:Table( "states" ):OrderBy( "code" )
   oCustomers  := oMsSql:Table( "customer" ):OrderBy( "first" )

   oCustomers:Relate( "state", oStates, "code" )

   BrowseStates( oStates, oCustomers )

   oStates:Close()
   oCustomers:Close()

   oMySql:Close()
   oMsSql:Close()

return nil

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

function BrowseStates( oStates, oCustomers )

   local oDlg, oFont, oBold, oBrwStates, oBrwCust

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-14 BOLD

   DEFINE DIALOG oDlg SIZE 1000,600 PIXEL TRUEPIXEL FONT oFont ;
      TITLE "FWH ORM POWER"

   @ 60, 20 XBROWSE oBrwStates SIZE 300,-20 PIXEL OF oDlg ;
      DATASOURCE oStates:oRs COLUMNS "Code", "Name" ;
      CELL LINES NOBORDER

   WITH OBJECT oBrwStates
      :bChange := { || oCustomers:First(), oBrwCust:GoTop(), oBrwCust:Refresh() }
      :CreateFromCode()
   END

   @ 60,320 XBROWSE oBrwCust SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oCustomers:oRs ;
      COLUMNS "State", "City", "First", "Salary" ;
      CELL LINES NOBORDER

   oBrwCust:CreateFromCode()

   @ 10, 20 SAY "States table on MYSQL Server" + CRLF + ;
                "Connected with DOLPHIN" ;
                SIZE 300,48 PIXEL OF oDlg FONT oBold CENTER ;
                COLOR CLR_HRED, oDlg:nClrPane

   @ 10,320 SAY "Customer Table on Microsoft SQL Server" + CRLF + ;
                "Connected with ADO"  ;
                SIZE 660,48 PIXEL OF oDlg FONT oBold CENTER ;
                COLOR CLR_HRED, oDlg:nClrPane

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont, oBold

return nil

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

EXTERNAL TDOLPHINSRV
 
Regards

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

Re: ORM power in next FWH

Postby leandro » Mon Jul 22, 2019 11:27 pm

Good afternoon everyone,

I would like to know how the ORM development is going and if there is already documentation or information to consult.
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1676
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: ORM power in next FWH

Postby Antonio Linares » Tue Jul 23, 2019 6:34 am

Leandro,

Please review FWH\samples\ormtest1.prg, ormtest2.prg and ormtest3.prg examples

full source code is here:
FWH\source\classes\fworm.prg
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: ORM power in next FWH

Postby James Bott » Thu Jul 25, 2019 4:19 pm

oUsers:Invoices mimics "SET RELATION TO ..."

You select a user and invoices automatically deliver his invoices


I presume "users" is really describing customers?

You can use objects to do this too:

oCustomer:Invoices()
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: ORM power in next FWH

Postby Antonio Linares » Fri Jul 26, 2019 8:35 am

James,

yes

Yes, the ORM idea is to manage databases as very simple and intuitive objects
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: ORM power in next FWH

Postby leandro » Tue Jul 30, 2019 5:20 pm

Buenos días para todos

Estoy intentando crear una conexión ORM, según el ejemplo que menciona antonio, pero no logro hacerlo andar.

Code: Select all  Expand view  RUN

vCnd := "DSN=dlyma;Uid="+oLamcla:cUsuario+";Pwd="+oLamcla:cPassword+";"
oCnFtr := FW_OpenAdoConnection( vCnd )
oCnOrm   := ORM_Connection():New( oCnFtr )
 


En el ejemplo ormtest1.prg estan comentadas estas líneas, asumo que debe funcionar con el objeto ya creado de ADO
Code: Select all  Expand view  RUN

   //
   // If we have already connected directly to ADO, DOLPHIN or FWMARIADB
   // We can also use that connection, without providing credentials again
   // ORM_Connection():New( oExistingConnectionObject )
   //
 

El errror que me arroja es el siguiente:
Code: Select all  Expand view  RUN
Application
===========
   Path and name: C:\DLYMA\dlyma.exe (32 bits)
   Size: 6,153,728 bytes
   Compiler version: xHarbour 1.2.3 Intl. (SimpLex) (Build 20190613)
   FiveWin  version: FWH 19.06
   C compiler version: Borland/Embarcadero C++ 7.3 (32-bit)
   Windows version: 6.2, Build 9200

   Time from start: 0 hours 0 mins 8 secs
   Error occurred at: 30/07/2019, 12:14:56
   Error description: Error BASE/1005  Message not found: ORM_CONNECTION:LOWNCONNCTION

Stack Calls
===========
   Called from: .\source\function\HARBOUR.PRG => _CLSSETERROR( 247 )
   Called from: .\source\classes\FWORM.PRG => ORM_CONNECTION:_LOWNCONNCTION( 209 )
   Called from: .\source\classes\FWORM.PRG => ORM_CONNECTION:NEW( 68 )
   Called from: c:\dlyma\prg\R32_fact.prg => R32_FACT( 32 )
   Called from: c:\dlyma\prg\Alyma.prg => (b)TLYMA:AUTORIZA( 1139 )
   Called from: c:\dlyma\prg\Alyma.prg => TLYMA:AUTORIZA( 1139 )
   Called from: c:\dlyma\prg\R32_menu.prg => (b)MAIN( 440 )
   Called from: .\source\classes\TRBTN.PRG => TRBTN:CLICK( 717 )
   Called from: .\source\classes\TRBTN.PRG => TRBTN:LBUTTONUP( 917 )
   Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1791 )
   Called from: .\source\classes\TRBTN.PRG => TRBTN:HANDLEEVENT( 1575 )
   Called from: .\source\classes\WINDOW.PRG => _FWH( 3546 )
   Called from:  => WINRUN( 0 )
   Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE( 1078 )
   Called from: c:\dlyma\prg\R32_menu.prg => MAIN( 529 )
 


De antemano gracias
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1676
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], nageswaragunupudi and 56 guests