How would you like to solve it, using ObjectScript?
For example, like this:
ClassMethod Test()
{
s C = 2500,
r = 0.5,
S = 3000000,
T = 35,
W = 5
w $$maxWeddingCost(C, r, S, T, W),! ; => 93278.3281405256664
s S = 2000000
w $$maxWeddingCost(C, r, S, T, W),! ; => 174425.0762746580325
maxWeddingCost(C,r,S,T,W) s r=r/100,a=1+r**12,b=a**(T-W) q a**W-1/r*C+$$LEAST^%qarfunc(0,b-1/r*C-S/b)
}
We have our own challenge with very specific conditions and goals: #Code Golf And what is the purpose of your challenge, I do not quite understand: speed, code size, etc? Rewriting the code in ObjectScript is too simple and not interesting.
esthetic()
ClassMethod esthetic(num = 441) As %String
{
set estheticBases=""
for base=2:1:10{
set digits = $$toBase(num, base)
if $$isEstheticInBase(digits) set estheticBases=estheticBases_$listbuild(base)
}
quit $listtostring(estheticBases)
toBase(n,base)
; Convert number n to a given base and return the digits as a list.
set digits=""
while n {
set digits=(n#base)_digits,
n=n\base
}
quit digits
isEstheticInBase(digits)
; Check if the given list of digits is esthetic.
for i=2:1:$length(digits){
if $zabs($extract(digits,i)-$extract(digits,i-1))'=1 {
return 0
}
}
return 1
}
ClassMethod GetTreeInfo(
pRoot As %String,
Output pTree,
ByRef pParms) As %Status
{
Set MyId=..GetId,pos=1
&Sql(Select Name,ID into :name,:id from MSDS_COM.Loc where Parent=:MyId)
Set:SQLCODE (name,id)=""
if pRoot=""
{
Set pTree(0,"ch",1) = ""
Set pTree(1) = $LB(name,id,1,"","")
}
Quit $$$OK
}
For further examples, see the class ZENTest.DynaTreeTest in the SAMPLES namespace.
Through %ZEN.proxyObject is unlikely to work, since the q parameter cannot be disabled in this case
q - output numeric values unquoted even when they come from a non-numeric property
Use your own class, for example:
Class dc.proxyObject Extends %RegisteredObject
{
Property ID As %VarString;
}
set object = ##class(dc.proxyObject).%New()
set object.ID = 123456
set x = ##class(%ZEN.Auxiliary.jsonProvider).%WriteJSONStreamFromObject(.json,object,,,,"aelotw")
Common Parameters:TRUNCATE
TRUNCATE — Specifies whether to truncate the string to MAXLEN characters, where 1 is TRUE and 0 is FALSE. This parameter is used by the Normalize() and IsValid() methods but is not used by database drivers.
Class dc.test Extends %Persistent
{
Property s1 As %String(TRUNCATE = 1);
Property s2 As %String;
ClassMethod Test()
{
d ..%KillExtent(,$$$YES)
s t=..%New()
s t.s1=$tr($j("",51)," ","a")
s sc=t.%Save()
w "s1: ",$s($$$ISERR(sc):$system.Status.GetErrorText(sc),1:"OK"),!
s t=..%New()
s t.s2=$tr($j("",51)," ","a")
s sc=t.%Save()
w "s2: ",$s($$$ISERR(sc):$system.Status.GetErrorText(sc),1:"OK"),!
}
}
USER>d ##class(dc.test).Test()
s1: OK
s2: ERROR #7201: Datatype value 'aaaa..aa' length longer than MAXLEN allowed of 50
> ERROR #5802: Datatype validation failed on property 'dc.test:s2', with value equal to "aaaa..aa"
I noticed that you are using the {Stream} syntax, which is typical for trigger code or calculated field.
Could you check the following code at your place:
Class dc.test Extends %Persistent
{
Property stream As %GlobalCharacterStream;
Trigger NewTrigger1 [ Event = INSERT ]
{
i $IsObject({stream}) {
s t={stream}
s ^||tmp=t.Size
}
}
ClassMethod Test()
{
d ..%KillExtent(,$$$YES)
s f=##class(%Stream.FileBinary).%New()
d f.LinkToFile("C:\test.jpg")
&sql(insert into dc.test(stream) values(:f))
i 'SQLCODE {
&sql(select CHAR_LENGTH(stream) into :len from dc.test where %id=1)
w len," ",^||tmp,!
}
}
}
The resulting archive is easily recognized/unpacked in WinRAR, 7z:
s f=##class(%Stream.FileCharacterGzip).%New()
s f.TranslateTable="UTF8"
s f.Filename="C:\test.gz"
d f.WriteLine("test")
d f.Write("Привет Caché")
d f.%Save()
Class dc.test [ Abstract ]
{
Query Intervals(
start As %TimeStamp,
end As %TimeStamp,
minute As %TinyInt) As %Query(ROWSPEC = "intStart:%PosixTime,intEnd:%PosixTime") [ SqlName = Intervals, SqlProc ]
{
}
ClassMethod IntervalsExecute(
ByRef qHandle As %Binary,
start As %TimeStamp,
end As %TimeStamp,
minute As %TinyInt) As %Status
{
s qHandle(0)=##class(%PosixTime).OdbcToLogical(start),
qHandle(1)=##class(%PosixTime).OdbcToLogical(end),
qHandle=minute
q $$$OK
}
ClassMethod IntervalsFetch(
ByRef qHandle As %Binary,
ByRef Row As %List,
ByRef AtEnd As %Integer = 0) As %Status [ PlaceAfter = IntervalsExecute ]
{
i qHandle(0)<=qHandle(1) {
s j=$system.SQL.Functions.DATEADD("minute",qHandle,qHandle(0)),
Row=$lb(qHandle(0),$s(j>=qHandle(1):qHandle(1),1:j-1)),
qHandle(0)=j=qHandle(1)+j
}else{
s Row="", AtEnd=$$$YES
}
q $$$OK
}
ClassMethod IntervalsClose(ByRef qHandle As %Binary) As %Status [ PlaceAfter = IntervalsExecute ]
{
q $$$OK
}
}
The result of calling a stored procedure in the Management Portal:
SELECT * FROM dc.Intervals({ts '2024-01-01 10:00:00'},{ts '2024-01-01 11:00:00'},15)
Display/ODBC Mode
intStart
intEnd
2024-01-01 10:00:00
2024-01-01 10:14:59.999999
2024-01-01 10:15:00
2024-01-01 10:29:59.999999
2024-01-01 10:30:00
2024-01-01 10:44:59.999999
2024-01-01 10:45:00
2024-01-01 11:00:00.000000
Logical Mode
intStart
intEnd
1154625607806846976
1154625608706846975
1154625608706846976
1154625609606846975
1154625609606846976
1154625610506846975
1154625610506846976
1154625611406846976
Accordingly, your query needs to be rewritten, for example:
SELECT
intStart,
intEnd,
COALESCE((SELECT SUM(CASE WHEN value_after_changing = 'GENERATE' THEN 1 ELSE 0 END) FROM service_log WHERE id = 11 AND created_at BETWEEN intStart AND intEnd), 0) generatedCount,
COALESCE((SELECT SUM(CASE WHEN value_after_changing = 'FINISH' THEN 1 ELSE 0 END) FROM service_log WHERE id = 11 AND created_at BETWEEN intStart AND intEnd), 0) finishedCount,
COALESCE((SELECT SUM(CASE WHEN value_after_changing = 'DROPOUT' THEN 1 ELSE 0 END) FROM service_log WHERE id = 11 AND created_at BETWEEN intStart AND intEnd), 0) dropoutCount,
COALESCE((SELECT SUM(CASE WHEN value_after_changing = 'CANCEL' THEN 1 ELSE 0 END) FROM service_log WHERE id = 11 AND created_at BETWEEN intStart AND intEnd), 0) cancelledCount
FROM dc.Intervals({ts '2024-01-01 10:00:00'},{ts '2024-01-01 11:00:00'},15)
However a collection property is actually stored, the property can be projected as a column in the parent table, as a child table, or in both ways (as of release 2022.1, this is true for both list and array properties). To control this, you specify the SQLPROJECTION parameter of the property.
go to post
go to post
We have our own challenge with very specific conditions and goals: #Code Golf
And what is the purpose of your challenge, I do not quite understand: speed, code size, etc? Rewriting the code in ObjectScript is too simple and not interesting.
go to post
The calculateTotalSavingsAtTime method can be shortened because initialPrincipal is always 0:
go to post
Try this:
For further examples, see the class ZENTest.DynaTreeTest in the SAMPLES namespace.
go to post
Through %ZEN.proxyObject is unlikely to work, since the q parameter cannot be disabled in this case
Use your own class, for example:
Output:
go to post
I do not observe any differences in the behavior of xDBC and Portal.
Given:
Result for any JDBC/ODBC tools (DBVisualizer, SQL Data Lens, etc.):
Result for Management Portal:
go to post
Check your TRUNCATE parameter.
The same error occurs in the Management Portal.
go to post
MAXLEN is not applicable for %GlobalCharacterStream (Blob). You will get compilation error #5480
go to post
go to post
I noticed that you are using the {Stream} syntax, which is typical for trigger code or calculated field.
Could you check the following code at your place:
I have saved a 16 MB file without any problems:
go to post
String Length Limit
go to post
The resulting archive is easily recognized/unpacked in WinRAR, 7z:
go to post
See Defining Custom Class Queries
The result of calling a stored procedure in the Management Portal:
Logical Mode
Accordingly, your query needs to be rewritten, for example:
go to post
I think it will also be useful to mention here the links to the documentation:
go to post
I would like to supplement the above with such parameters as STORAGEDEFAULT, SQLTABLENAME, and SQLPROJECTION: Storage and SQL Projection of Collection Properties
go to post
Thanks for the hint, I fixed it.
By the way, your code can be reduced to 173: f i=$i(r):1:a
go to post
Also look at the events OnEndRequest()/OnStartRequest()
go to post
There is no limit to perfection.
By the way, your code shows 175 characters, where did the number 174 come from?
go to post
Ah, got it.
I improved my score to 179 (see above).
go to post
Have you used a test case?