OCLOperators sqlpassthrough
No edit summary
(Automatically adding template at the end of the page.)
 
(11 intermediate revisions by 5 users not shown)
Line 1: Line 1:
The sqlPassThorugh is described here [[PSExpression , or how to do things in the DB from MDriven]]
<code>SomeClass.sqlpassthrough('SqlExpression',Type1OfTupleResult,Type2OfTupleResult,...)</code>


=== Example of using the sqlpassthroughobjects ===
'''Example of how the OCL looks like to call a stored procedure:'''
The two examples below can be used in a derived association
Anvandare.sqlpassthrough('sp_Upd_Losen ' + self.AnvId.asString + ', \<nowiki>''</nowiki> + self.Anvandarnamn + '\', @aNyttLosenord', Int32)
'''Notes:'''
* @aNyttLosenord here is automatically available because it's a variable available when the function is called.
* You need to quote strings to be passed (if they aren't variables), like ''self.Anvandarnamn'' above. The \' is an escaped quote in OCL ([[Escape codes]]).


===== If you already have the primary key available to can to like this =====
* Int32 at the end is the SQL server return code.
Kundfaktura.sqlpassthroughobjects('select ' + self.FakturaReferensnummer.toString )->first
* Your expression starts with a '''class,''' not an object.
A use case and examples of using sqlPassThrough can be found here: "[[PSExpression , or how to do things in the DB from MDriven|PSExpression, or how to do things in the DB from MDriven]]"


===== If looking for a specific object using some field =====
''Note also'' that the sqlPassThrough can create tuples:
  Kundfaktura.sqlpassthroughobjects('select FAKTURA_ID from tbl_FAKTUROR where FAKTURA_ID = ' + self.FakturaReferensnummer.toString )->first
  AccountPlan.SQLPassthrough('select somekey,sum(somestuff),sum(someotherstuff) from table1,2,3 where ...',String,Integer,Integer)->collect(xtuple|let xobject=SomeNewTransient.Create in (xobject.Key:=xtuple.Part1;xobject.SomeSum:=xtuple.Part2))
Also, look here: [[OCLOperators sqlpassthroughobjects]]
[[Category:OCLOperators]]
{{Edited|July|12|2024}}

Latest revision as of 15:43, 10 February 2024

SomeClass.sqlpassthrough('SqlExpression',Type1OfTupleResult,Type2OfTupleResult,...)

Example of how the OCL looks like to call a stored procedure:

Anvandare.sqlpassthrough('sp_Upd_Losen ' + self.AnvId.asString + ', \'' + self.Anvandarnamn + '\', @aNyttLosenord', Int32)

Notes:

  • @aNyttLosenord here is automatically available because it's a variable available when the function is called.
  • You need to quote strings to be passed (if they aren't variables), like self.Anvandarnamn above. The \' is an escaped quote in OCL (Escape codes).
  • Int32 at the end is the SQL server return code.
  • Your expression starts with a class, not an object.

A use case and examples of using sqlPassThrough can be found here: "PSExpression, or how to do things in the DB from MDriven"

Note also that the sqlPassThrough can create tuples:

AccountPlan.SQLPassthrough('select somekey,sum(somestuff),sum(someotherstuff) from table1,2,3 where ...',String,Integer,Integer)->collect(xtuple|let xobject=SomeNewTransient.Create in (xobject.Key:=xtuple.Part1;xobject.SomeSum:=xtuple.Part2))

Also, look here: OCLOperators sqlpassthroughobjects

This page was edited 93 days ago on 02/10/2024. What links here