FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ORM power in next FWH
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
ORM power in next FWH
Posted: Sun Apr 14, 2019 01:51 PM
Thanks to Harbour Magazine meeting in Calpe, Carlos Mora explained us the power of ORM :-)



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 (fw): Select all Collapse
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 (fw): Select all Collapse
oUsers:Find( 120 ):Edit()


This is really nice:
Code (fw): Select all Collapse
oUsers:Where( "country", "Spain" ):Where( "city", "Barcelona" ):Browse()

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

as simple as this:
Code (fw): Select all Collapse
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
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: ORM power in next FWH
Posted: Sun Apr 14, 2019 03:06 PM

+1

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

Regards,

Dutch



FWH 2304 / 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)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: ORM power in next FWH
Posted: Sun Apr 14, 2019 03:47 PM

Duth,

Of course it does :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3
Joined: Fri Nov 28, 2008 03:19 AM
Re: ORM power in next FWH
Posted: Mon Apr 15, 2019 03:12 AM

Que Bueno que se está poniendo FWH Antonio !!! Lo felicito !!!

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: ORM power in next FWH
Posted: Mon Apr 15, 2019 07:28 AM
This is working already :-)

Code (fw): Select all Collapse
oUsers:Find( 3 ):Invoices:Browse()
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: ORM power in next FWH
Posted: 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 (fw): Select all Collapse
   
oCn   := maria_Connect( cServer, cDB, cUser, cPwd )
   XBROWSER oCn:ListTables() SETUP ( ;
      oBrw:aCols[ 1 ]:bLDClickData := { |r,c,f,o| XBrowse( oCn:RowSet( o:Value ) ) } )
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: ORM power in next FWH
Posted: 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
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: ORM power in next FWH
Posted: Mon Apr 15, 2019 12:46 PM

excelente

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: ORM power in next FWH
Posted: Tue Apr 16, 2019 09:58 PM
Notice this interesting detail:

Code (fw): Select all Collapse
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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: ORM power in next FWH
Posted: Sat May 18, 2019 09:04 AM
Example of setting relationships between tables on different servers connected by different libraries:



Code (fw): Select all Collapse
#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
Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Re: ORM power in next FWH
Posted: 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

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: ORM power in next FWH
Posted: Tue Jul 23, 2019 06: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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: ORM power in next FWH
Posted: Thu Jul 25, 2019 04: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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: ORM power in next FWH
Posted: Fri Jul 26, 2019 08: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
Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Re: ORM power in next FWH
Posted: Tue Jul 30, 2019 05: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 (fw): Select all Collapse
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 (fw): Select all Collapse
   //
   // 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 (fw): Select all Collapse
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

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]