From ebb0f4b8027af752c7bfe4acf539d6b5308f8733 Mon Sep 17 00:00:00 2001 From: Eduard Date: Tue, 22 Dec 2015 14:13:54 +0300 Subject: [PATCH 1/6] Create Cheat.md --- Cheat.md | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 Cheat.md diff --git a/Cheat.md b/Cheat.md new file mode 100644 index 0000000..0e03b16 --- /dev/null +++ b/Cheat.md @@ -0,0 +1,135 @@ +# Cheat sheet +Some most encountered COS expressions + +## Object/SQL Basics + +| Action | Code | +|----------------------------------------------|-----------------------------------------------------------------------------------| +| Call a class method | Do ##class(package.class).method(arguments)
Set variable = ##class(package.class).method(arguments)
Note: place a . before each pass-by-reference argument | +| Call an instance method | Do object.method(arguments)
Set variable = object.method(arguments)
Note: place a . before each pass-by-reference argument | +| Create a new object | Set object = ##class(package.class).%New() | +| Open an existing object | Set object = ##class(package.class).%OpenId(id, concurrency, .status) | +| Save an object | Set status = object.%Save() | +| Retrieve the ID of a saved object | Set id = object.%Id() | +| Retrieve the OID of a saved object | Set oid = object.%Oid() | +| Validate an object without saving | Set status = object.%ValidateObject(), | +| Validate a property without saving | Set status = ##class(package.class).PropertyIsValid(object.Property) | +| Print status after error | Do $system.Status.DisplayError(status)
ZWrite status (v2012.2+) | +| Obtain status details after error | Do $system.Status.DecomposeStatus(status, .err) | +| Remove an object from process memory | Set object = "" | +| Delete an existing object of a class | Set status = ##class(package.class).%DeleteId(id) | +| Delete all saved objects of a class | Do ##class(package.class).%DeleteExtent()
Do ##class(package.class).%KillExtent() | +| Reload properties of a saved object | Do object.%Reload() | +| Clone an object | Set cloneDobject = object.%ConstructClone() | +| Write a property | Write object.property | +| Set a property | Set object.property = value | +| Set a serial (embedded) property | Set object.property.embeddedProperty = value | +| Link two objects | Set object1.referenceProperty = object2 | +| Populate a class | Do ##class(package.class).Populate(count, verbose) | +| Remove all objects in process memory | kill | +| List all objects in process memory | Do $system.OBJ.ShowObjects() | +| Display all properties of an object | Do $system.OBJ.Dump(object) zWrite object (v2012.2+) | +| Determine If variable is an object reference | If $isobject(variable) ; 1=yes, 0=no | +| Find classname of an object | Write $classname(oref) | +| Start the SQL shell | Do $system.SQL.Shell() | +| Test a class query | Do ##class(%ResultSet).RunQuery(class, query) | + +## ObjectScript Commands + +| Command | Description | +|-------------------------------|-------------------------------------------------------------------------------------| +| Write | Display text strings, value of variable or expression. | +| Set | Set value of variable. | +| Do | Execute method, procedure, or routine. | +| Quit or Return (v2013.1) | Terminate method, procedure, or routine. Optionally return value to calling method. | +| Halt | Stop Caché process and close Terminal. | +| Kill | Destroy variable(s). | +| If {} ElseIf {} Else {} | Evaluate conditions and branch. | +| For {}, While {}, Do {} While | Execute block of code repeatedly. | +| Try {} Catch {}, Throw | Handle errors. | + +## ObjectScript Functions + +| Action | Code | +|--------------------------------------------------|-------------------------------------------------------------| +| Date conversion (external → internal) | Set variable = $zdh(“mm/dd/yyyy”) | +| Date conversion (internal → external) | Set variable = $zd(internalDate, format) | +| Time conversion (external → internal) | Set variable = $zth(“hh:mm:ss”) | +| Time conversion (internal → external) | Set variable = $zt(internalTime, format) | +| Display current internal date/time string | Write $horolog | +| Display UTC date/time string | Write $ztimestamp | +| Display length of a string | Write $length(string) | +| Build a list | Set listString = $listbuild(list items, separated by comma) | +| Retrieve an item from a list | Set variable = $list(listString, position) | +| Display the length of a list | Write $listlength(listString) | +| Display ranDom integer from start to count | Write $ranDom(count) + start | +| Check If variable exists | Write $data(variable) | +| Return value of variable, or "" If undefined | Write $get(variable) | + +## Collections + +| Action | Code | +|--------------------------------------------------------------|--------------------------------------------------------------------------------------------------------| +| Create a new standalone list
Work with a list property | Set listObject=##class(%ListOfDataTypes).%New()
Use methods below on a list collection property | +| Insert an element at the end of a list | Do listObject.Insert(value)
Do object.listProperty.Insert(value) | +| Insert an element into a list | Do listObject.SetAt(value, position)
Do object.listProperty.SetAt(value, position) | +| Remove an element from a list | Do listObject.RemoveAt(position)
Do object.listProperty.RemoveAt(position) | +| Display an element of a list | Write listObject.GetAt(position)
Write object.listProperty.GetAt(position) | +| Display the size of a list | Write listObject.Count()
Write object.listProperty.Count() | +| Clear all the elements of a list | Do listObject.Clear()
Do object.listProperty.Clear() | +| Create a new standalone array
Work with an array property | Set arrayObject=##class(%ArrayOfDataTypes).%New()
Use methods below on an array collection property | +| Insert an element into an array | Do arrayObject.SetAt(value, key)
Do object.arrayProperty.SetAt(value, key) | +| Remove an element from an array | Do arrayObject.RemoveAt(key)
Do object.arrayProperty.RemoveAt(key) | +| Display an element of an array | Write arrayObject.GetAt(key)
Do object.arrayProperty.GetAt(key) | +| Display the size of an array | Write arrayObject.Count()
Do object.arrayProperty.Count() | +| Clear all elements of an array | Do arrayObject.Clear()
Do object.arrayProperty.Clear() | + +## Relatioships + +| Action | Code | +|-----------------------------------------|----------------------------------------------------------------------------------------------------------| +| Parent-to-children object linking | Do parentObject.childRefProperty.Insert(chilDobject)
Set chilDobject.parentRefProperty = parentObject | +| One-to-many object linking | Do oneObject.manyRefProperty.Insert(manyObject)
Set manyObject.OneRefProperty = OneObject | +| Write a property of a child object | Write parentObject.childRefProperty.GetAt(position).property
| +| Write a property of a many object | Write oneObject.manyRefProperty.GetAt(position).property | +| Display the count of child/many objects | Write parentObject.childRefProperty.Count()
Write oneObject.manyRefProperty.Count() | +| Open a many/child object directly | Set object = ##class(package.class).IDKEYOpen(parentID, childsub) | +| Retrieve the id of a child object | Set status = ##class(package.class).IDKEYExists(parentID, childsub, .childID) | +| Clear the child/many objects | Do parentObject.childRefProperty.Clear()
Do oneObject.manyRefProperty.Clear() | + +## Streams + +| Action | Code | +|-------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Create a new stream | Set streamObject=##class(%Stream.GlobalCharacter).%New()
Set streamObject=##class(%Stream.GlobalBinary).%New()
Use methods below on a stream property | +| Add text to a stream | Do streamObject.Write(text)
Do object.streamProperty.Write(text) | +| Add a line of text to a stream | Do streamObject.WriteLine(text)
Do object.streamProperty.WriteLine(text) | +| Read len characters of text from a stream | Write streamObject.Read(len)
Write object.streamProperty.Read(len) | +| Read a line of text from a stream | Write streamObject.ReadLine(len)
Write object.streamProperty.ReadLine(len) | +| Go to the beginning of a stream | Do streamObject.Rewind()
Do object.streamProperty.Rewind() | +| Go to the end of a stream, for appending | Do streamObject.MoveToEnd()
Do object.streamProperty.MoveToEnd() | +| Clear a stream | Do streamObject.Clear()
Do object.streamProperty.Clear() | +| Display the length of a stream | Write streamObject.Size
Write object.streamProperty.Size | + +## Unit Testing Macros + +| Action | Code | +|-----------------------------|------------------------------------------------| +| Assert equality | Do $$$AssertEquals(value1, value2, message) | +| Assert inequality | Do $$$AssertNotEquals(value1, value2, message) | +| Assert status is OK | Do $$$AssertStatusOK(status, message) | +| Assert status isn't OK | Do $$$AssertStatusNotOK(status, message) | +| Assert condition is true | Do $$$AssertTrue(condition, message) | +| Assert condition isn't true | Do $$$AssertNotTrue(condition, message) | +| Log message | Do $$$LogMessage(message) | + +## Other Macros + +| Action | Code | +|----------------------------------|-----------------------------------------| +| Return a good status | Quit $$$OK | +| Return an error status | Quit $$$ERROR($$$GeneralError, message) | +| Check If status is good | If $$$ISOK(status) | +| Check If status is an error | If $$$ISERR(status) | +| Return a null object reference | Quit $$$NULLOREF | +| Place a new line within a string | Write string1_$$$NL_string2 | From 6de5ef16dae231b81c3c16ba3f56e5b950a60c18 Mon Sep 17 00:00:00 2001 From: Eduard Date: Tue, 22 Dec 2015 14:14:24 +0300 Subject: [PATCH 2/6] Rename Cheat.md to CHEAT.md --- Cheat.md => CHEAT.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Cheat.md => CHEAT.md (100%) diff --git a/Cheat.md b/CHEAT.md similarity index 100% rename from Cheat.md rename to CHEAT.md From 20338764fc8bfd35100a567f6292d6eb3ba1b11f Mon Sep 17 00:00:00 2001 From: Eduard Date: Tue, 22 Dec 2015 14:18:07 +0300 Subject: [PATCH 3/6] Reference to cheat sheet from readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 27ac7bd..a290232 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,10 @@ If there is some style already established in the class or utility being modifie to continue use that same style, than introducing yet another one, which may be more recommended but which will be introducing some unnecessary inconsistency. +## Cheat sheet + +For COS cheat sheet refer [here](CHEAT.md). + ## Mandatory part * Only "modern" syntax permitted, dotted syntax is not generally allowed (with few exceptions); From 7e42b52bd7190b187a0aebbda97f7c27f33736ca Mon Sep 17 00:00:00 2001 From: Eduard Date: Tue, 22 Dec 2015 16:19:38 +0300 Subject: [PATCH 4/6] Add $$$TOE macro --- CHEAT.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHEAT.md b/CHEAT.md index 0e03b16..0635674 100644 --- a/CHEAT.md +++ b/CHEAT.md @@ -129,6 +129,7 @@ Some most encountered COS expressions |----------------------------------|-----------------------------------------| | Return a good status | Quit $$$OK | | Return an error status | Quit $$$ERROR($$$GeneralError, message) | +| Throw exception on error | $$$ThrowOnError(status, code) or $$$TOE(status, code) | | Check If status is good | If $$$ISOK(status) | | Check If status is an error | If $$$ISERR(status) | | Return a null object reference | Quit $$$NULLOREF | From 666dd0c59326f5669e72b23c42704b31724ef0fe Mon Sep 17 00:00:00 2001 From: Timur Safin Date: Wed, 23 Dec 2015 00:13:39 +0300 Subject: [PATCH 5/6] A lot of formatting changes Some subtle punctuation changes, few typos --- CHEAT.md | 210 +++++++++++++++++++++++++++---------------------------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/CHEAT.md b/CHEAT.md index 0635674..cb6dd5a 100644 --- a/CHEAT.md +++ b/CHEAT.md @@ -5,132 +5,132 @@ Some most encountered COS expressions | Action | Code | |----------------------------------------------|-----------------------------------------------------------------------------------| -| Call a class method | Do ##class(package.class).method(arguments)
Set variable = ##class(package.class).method(arguments)
Note: place a . before each pass-by-reference argument | -| Call an instance method | Do object.method(arguments)
Set variable = object.method(arguments)
Note: place a . before each pass-by-reference argument | -| Create a new object | Set object = ##class(package.class).%New() | -| Open an existing object | Set object = ##class(package.class).%OpenId(id, concurrency, .status) | -| Save an object | Set status = object.%Save() | -| Retrieve the ID of a saved object | Set id = object.%Id() | -| Retrieve the OID of a saved object | Set oid = object.%Oid() | -| Validate an object without saving | Set status = object.%ValidateObject(), | -| Validate a property without saving | Set status = ##class(package.class).PropertyIsValid(object.Property) | -| Print status after error | Do $system.Status.DisplayError(status)
ZWrite status (v2012.2+) | -| Obtain status details after error | Do $system.Status.DecomposeStatus(status, .err) | -| Remove an object from process memory | Set object = "" | -| Delete an existing object of a class | Set status = ##class(package.class).%DeleteId(id) | -| Delete all saved objects of a class | Do ##class(package.class).%DeleteExtent()
Do ##class(package.class).%KillExtent() | -| Reload properties of a saved object | Do object.%Reload() | -| Clone an object | Set cloneDobject = object.%ConstructClone() | -| Write a property | Write object.property | -| Set a property | Set object.property = value | -| Set a serial (embedded) property | Set object.property.embeddedProperty = value | -| Link two objects | Set object1.referenceProperty = object2 | -| Populate a class | Do ##class(package.class).Populate(count, verbose) | -| Remove all objects in process memory | kill | -| List all objects in process memory | Do $system.OBJ.ShowObjects() | -| Display all properties of an object | Do $system.OBJ.Dump(object) zWrite object (v2012.2+) | -| Determine If variable is an object reference | If $isobject(variable) ; 1=yes, 0=no | -| Find classname of an object | Write $classname(oref) | -| Start the SQL shell | Do $system.SQL.Shell() | -| Test a class query | Do ##class(%ResultSet).RunQuery(class, query) | +| Call a class method | `Do ##class(package.class).method(arguments)`
`Set variable = ##class(package.class).method(arguments)`
Note: place a . before each pass-by-reference argument | +| Call an instance method | `Do object.method(arguments)`
`Set variable = object.method(arguments)`
Note: place a . before each pass-by-reference argument | +| Create a new object | `Set object = ##class(package.class).%New()` | +| Open an existing object | `Set object = ##class(package.class).%OpenId(id, concurrency, .status)` | +| Save an object | `Set status = object.%Save()` | +| Retrieve the ID of a saved object | `Set id = object.%Id()` | +| Retrieve the OID of a saved object | `Set oid = object.%Oid()` | +| Validate an object without saving | `Set status = object.%ValidateObject()` | +| Validate a property without saving | `Set status = ##class(package.class).PropertyIsValid(object.Property)` | +| Print status after error | `Do $system.Status.DisplayError(status)`
`ZWrite status` (v2012.2+) | +| Obtain status details after error | `Do $system.Status.DecomposeStatus(status, .err)` | +| Remove an object from process memory | `Set object = ""` | +| Delete an existing object of a class | `Set status = ##class(package.class).%DeleteId(id)` | +| Delete all saved objects of a class | `Do ##class(package.class).%DeleteExtent()`
`Do ##class(package.class).%KillExtent()` | +| Reload properties of a saved object | `Do object.%Reload()` | +| Clone an object | `Set clonedObject = object.%ConstructClone()` | +| Write a property | `Write object.property` | +| Set a property | `Set object.property = value` | +| Set a serial (embedded) property | `Set object.property.embeddedProperty = value` | +| Link two objects | `Set object1.referenceProperty = object2` | +| Populate a class | `Do ##class(package.class).Populate(count, verbose)` | +| Remove all objects in process memory | `Kill` | +| List all objects in process memory | `Do $system.OBJ.ShowObjects()` | +| Display all properties of an object | `Do $system.OBJ.Dump(object)`
`Zwrite object` (v2012.2+) | +| Determine If variable is an object reference | `If $isobject(variable) ; 1=yes, 0=no` | +| Find classname of an object | `Write $classname(oref)` | +| Start the SQL shell | `Do $system.SQL.Shell()` | +| Test a class query | `Do ##class(%ResultSet).RunQuery(class, query)` | ## ObjectScript Commands | Command | Description | |-------------------------------|-------------------------------------------------------------------------------------| -| Write | Display text strings, value of variable or expression. | -| Set | Set value of variable. | -| Do | Execute method, procedure, or routine. | -| Quit or Return (v2013.1) | Terminate method, procedure, or routine. Optionally return value to calling method. | -| Halt | Stop Caché process and close Terminal. | -| Kill | Destroy variable(s). | -| If {} ElseIf {} Else {} | Evaluate conditions and branch. | -| For {}, While {}, Do {} While | Execute block of code repeatedly. | -| Try {} Catch {}, Throw | Handle errors. | +| `Write` | Display text strings, value of variable or expression. | +| `Set` | Set value of variable. | +| `Do` | Execute method, procedure, or routine. | +| `Quit` or `Return` (v2013.1) | Terminate method, procedure, or routine. Optionally return value to calling method. | +| `Halt` | Stop Caché process and close Terminal. | +| `Kill` | Destroy variable(s). | +| `If {} ElseIf {} Else {}` | Evaluate conditions and branch. | +| `For {}`, `While {}`, `Do {} While` | Execute block of code repeatedly. | +| `Try {} Catch {}`, `Throw` | Handle errors. | ## ObjectScript Functions | Action | Code | |--------------------------------------------------|-------------------------------------------------------------| -| Date conversion (external → internal) | Set variable = $zdh(“mm/dd/yyyy”) | -| Date conversion (internal → external) | Set variable = $zd(internalDate, format) | -| Time conversion (external → internal) | Set variable = $zth(“hh:mm:ss”) | -| Time conversion (internal → external) | Set variable = $zt(internalTime, format) | -| Display current internal date/time string | Write $horolog | -| Display UTC date/time string | Write $ztimestamp | -| Display length of a string | Write $length(string) | -| Build a list | Set listString = $listbuild(list items, separated by comma) | -| Retrieve an item from a list | Set variable = $list(listString, position) | -| Display the length of a list | Write $listlength(listString) | -| Display ranDom integer from start to count | Write $ranDom(count) + start | -| Check If variable exists | Write $data(variable) | -| Return value of variable, or "" If undefined | Write $get(variable) | +| Date conversion (external → internal) | `Set variable = $zdh("mm/dd/yyyy")` | +| Date conversion (internal → external) | `Set variable = $zd(internalDate, format)` | +| Time conversion (external → internal) | `Set variable = $zth("hh:mm:ss")` | +| Time conversion (internal → external) | `Set variable = $zt(internalTime, format)' | +| Display current internal date/time string | `Write $horolog` | +| Display UTC date/time string | `Write $ztimestamp` | +| Display length of a string | `Write $length(string)` | +| Build a list | `Set listString = $listbuild(list items, separated by comma)` | +| Retrieve an item from a list | `Set variable = $list(listString, position)` | +| Display the length of a list | `Write $listlength(listString)` | +| Display random integer from start to start+count | `Write $random(count) + start` | +| Check if variable exists | `Write $data(variable)` | +| Return value of variable, or "" If undefined | `Write $get(variable)` | ## Collections | Action | Code | |--------------------------------------------------------------|--------------------------------------------------------------------------------------------------------| -| Create a new standalone list
Work with a list property | Set listObject=##class(%ListOfDataTypes).%New()
Use methods below on a list collection property | -| Insert an element at the end of a list | Do listObject.Insert(value)
Do object.listProperty.Insert(value) | -| Insert an element into a list | Do listObject.SetAt(value, position)
Do object.listProperty.SetAt(value, position) | -| Remove an element from a list | Do listObject.RemoveAt(position)
Do object.listProperty.RemoveAt(position) | -| Display an element of a list | Write listObject.GetAt(position)
Write object.listProperty.GetAt(position) | -| Display the size of a list | Write listObject.Count()
Write object.listProperty.Count() | -| Clear all the elements of a list | Do listObject.Clear()
Do object.listProperty.Clear() | -| Create a new standalone array
Work with an array property | Set arrayObject=##class(%ArrayOfDataTypes).%New()
Use methods below on an array collection property | -| Insert an element into an array | Do arrayObject.SetAt(value, key)
Do object.arrayProperty.SetAt(value, key) | -| Remove an element from an array | Do arrayObject.RemoveAt(key)
Do object.arrayProperty.RemoveAt(key) | -| Display an element of an array | Write arrayObject.GetAt(key)
Do object.arrayProperty.GetAt(key) | -| Display the size of an array | Write arrayObject.Count()
Do object.arrayProperty.Count() | -| Clear all elements of an array | Do arrayObject.Clear()
Do object.arrayProperty.Clear() | - -## Relatioships - -| Action | Code | -|-----------------------------------------|----------------------------------------------------------------------------------------------------------| -| Parent-to-children object linking | Do parentObject.childRefProperty.Insert(chilDobject)
Set chilDobject.parentRefProperty = parentObject | -| One-to-many object linking | Do oneObject.manyRefProperty.Insert(manyObject)
Set manyObject.OneRefProperty = OneObject | -| Write a property of a child object | Write parentObject.childRefProperty.GetAt(position).property
| -| Write a property of a many object | Write oneObject.manyRefProperty.GetAt(position).property | -| Display the count of child/many objects | Write parentObject.childRefProperty.Count()
Write oneObject.manyRefProperty.Count() | -| Open a many/child object directly | Set object = ##class(package.class).IDKEYOpen(parentID, childsub) | -| Retrieve the id of a child object | Set status = ##class(package.class).IDKEYExists(parentID, childsub, .childID) | -| Clear the child/many objects | Do parentObject.childRefProperty.Clear()
Do oneObject.manyRefProperty.Clear() | +| Create a new standalone list
Work with a list property | `Set listObject=##class(%ListOfDataTypes).%New()`
Use methods below on a list collection property | +| Insert an element at the end of a list | `Do listObject.Insert(value)`
`Do object.listProperty.Insert(value)` | +| Insert an element into a list | `Do listObject.SetAt(value, position)`
`Do object.listProperty.SetAt(value, position)` | +| Remove an element from a list | `Do listObject.RemoveAt(position)`
`Do object.listProperty.RemoveAt(position)` | +| Display an element of a list | `Write listObject.GetAt(position)`
`Write object.listProperty.GetAt(position)` | +| Display the size of a list | `Write listObject.Count()`
`Write object.listProperty.Count()` | +| Clear all the elements of a list | `Do listObject.Clear()`
`Do object.listProperty.Clear()` | +| Create a new standalone array
Work with an array property | `Set arrayObject=##class(%ArrayOfDataTypes).%New()`
Use methods below on an array collection property | +| Insert an element into an array | `Do arrayObject.SetAt(value, key)`
`Do object.arrayProperty.SetAt(value, key)` | +| Remove an element from an array | `Do arrayObject.RemoveAt(key)`
`Do object.arrayProperty.RemoveAt(key)` | +| Display an element of an array | `Write arrayObject.GetAt(key)`
`Do object.arrayProperty.GetAt(key)` | +| Display the size of an array | `Write arrayObject.Count()`
`Do object.arrayProperty.Count()` | +| Clear all elements of an array | `Do arrayObject.Clear()`
`Do object.arrayProperty.Clear()` | + +## Relationships + +| Action | Code | +|-----------------------------------------|------------------------------------------------------------------------------------------| +| Parent-to-children object linking | `Do parentObject.childRefProperty.Insert(chilDobject)`
`Set chilDobject.parentRefProperty = parentObject` | +| One-to-many object linking | `Do oneObject.manyRefProperty.Insert(manyObject)`
`Set manyObject.OneRefProperty = OneObject` | +| Write a property of a child object | `Write parentObject.childRefProperty.GetAt(position).property` | +| Write a property of a many object | `Write oneObject.manyRefProperty.GetAt(position).property` | +| Display the count of child/many objects | `Write parentObject.childRefProperty.Count()`
`Write oneObject.manyRefProperty.Count()` | +| Open a many/child object directly | `Set object = ##class(package.class).IDKEYOpen(parentID, childsub)` | +| Retrieve the id of a child object | `Set status = ##class(package.class).IDKEYExists(parentID, childsub, .childID)` | +| Clear the child/many objects | `Do parentObject.childRefProperty.Clear()
Do oneObject.manyRefProperty.Clear()` | ## Streams -| Action | Code | -|-------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Create a new stream | Set streamObject=##class(%Stream.GlobalCharacter).%New()
Set streamObject=##class(%Stream.GlobalBinary).%New()
Use methods below on a stream property | -| Add text to a stream | Do streamObject.Write(text)
Do object.streamProperty.Write(text) | -| Add a line of text to a stream | Do streamObject.WriteLine(text)
Do object.streamProperty.WriteLine(text) | -| Read len characters of text from a stream | Write streamObject.Read(len)
Write object.streamProperty.Read(len) | -| Read a line of text from a stream | Write streamObject.ReadLine(len)
Write object.streamProperty.ReadLine(len) | -| Go to the beginning of a stream | Do streamObject.Rewind()
Do object.streamProperty.Rewind() | -| Go to the end of a stream, for appending | Do streamObject.MoveToEnd()
Do object.streamProperty.MoveToEnd() | -| Clear a stream | Do streamObject.Clear()
Do object.streamProperty.Clear() | -| Display the length of a stream | Write streamObject.Size
Write object.streamProperty.Size | +| Action | Code | +|-------------------------------------------|---------------------------------------------------------------------------------------| +| Create a new stream | `Set streamObject=##class(%Stream.GlobalCharacter).%New()`
`Set streamObject=##class(%Stream.GlobalBinary).%New()`
Use methods below on a stream property | +| Add text to a stream | `Do streamObject.Write(text)`
`Do object.streamProperty.Write(text)` | +| Add a line of text to a stream | `Do streamObject.WriteLine(text)`
`Do object.streamProperty.WriteLine(text)` | +| Read len characters of text from a stream | `Write streamObject.Read(len)`
`Write object.streamProperty.Read(len)` | +| Read a line of text from a stream | `Write streamObject.ReadLine(len)`
`Write object.streamProperty.ReadLine(len)` | +| Go to the beginning of a stream | `Do streamObject.Rewind()`
`Do object.streamProperty.Rewind()` | +| Go to the end of a stream, for appending | `Do streamObject.MoveToEnd()`
`Do object.streamProperty.MoveToEnd()` | +| Clear a stream | `Do streamObject.Clear()`
`Do object.streamProperty.Clear()` | +| Display the length of a stream | `Write streamObject.Size`
`Write object.streamProperty.Size` | ## Unit Testing Macros -| Action | Code | -|-----------------------------|------------------------------------------------| -| Assert equality | Do $$$AssertEquals(value1, value2, message) | -| Assert inequality | Do $$$AssertNotEquals(value1, value2, message) | -| Assert status is OK | Do $$$AssertStatusOK(status, message) | -| Assert status isn't OK | Do $$$AssertStatusNotOK(status, message) | -| Assert condition is true | Do $$$AssertTrue(condition, message) | -| Assert condition isn't true | Do $$$AssertNotTrue(condition, message) | -| Log message | Do $$$LogMessage(message) | +| Action | Code | +|-----------------------------|--------------------------------------------------| +| Assert equality | `Do $$$AssertEquals(value1, value2, message)` | +| Assert inequality | `Do $$$AssertNotEquals(value1, value2, message)` | +| Assert status is OK | `Do $$$AssertStatusOK(status, message)` | +| Assert status isn't OK | `Do $$$AssertStatusNotOK(status, message)` | +| Assert condition is true | `Do $$$AssertTrue(condition, message)` | +| Assert condition isn't true | `Do $$$AssertNotTrue(condition, message)` | +| Log message | `Do $$$LogMessage(message)` | ## Other Macros -| Action | Code | -|----------------------------------|-----------------------------------------| -| Return a good status | Quit $$$OK | -| Return an error status | Quit $$$ERROR($$$GeneralError, message) | -| Throw exception on error | $$$ThrowOnError(status, code) or $$$TOE(status, code) | -| Check If status is good | If $$$ISOK(status) | -| Check If status is an error | If $$$ISERR(status) | -| Return a null object reference | Quit $$$NULLOREF | -| Place a new line within a string | Write string1_$$$NL_string2 | +| Action | Code | +|----------------------------------|-------------------------------------------| +| Return a good status | `Quit $$$OK` | +| Return an error status | `Quit $$$ERROR($$$GeneralError, message)` | +| Throw exception on error | `$$$ThrowOnError(status, code)` or `$$$TOE(status, code)` | +| Check if status is good | `If $$$ISOK(status)` | +| Check if status is an error | `If $$$ISERR(status)` | +| Return a null object reference | `Quit $$$NULLOREF` | +| Place a new line within a string | `Write string1_$$$NL_string2` | From de4bbbb644525804d82af7e7277657648d897e55 Mon Sep 17 00:00:00 2001 From: Timur Safin Date: Wed, 23 Dec 2015 00:14:34 +0300 Subject: [PATCH 6/6] ZWrite > Zwrite --- CHEAT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHEAT.md b/CHEAT.md index cb6dd5a..787da32 100644 --- a/CHEAT.md +++ b/CHEAT.md @@ -14,7 +14,7 @@ Some most encountered COS expressions | Retrieve the OID of a saved object | `Set oid = object.%Oid()` | | Validate an object without saving | `Set status = object.%ValidateObject()` | | Validate a property without saving | `Set status = ##class(package.class).PropertyIsValid(object.Property)` | -| Print status after error | `Do $system.Status.DisplayError(status)`
`ZWrite status` (v2012.2+) | +| Print status after error | `Do $system.Status.DisplayError(status)`
`Zwrite status` (v2012.2+) | | Obtain status details after error | `Do $system.Status.DecomposeStatus(status, .err)` | | Remove an object from process memory | `Set object = ""` | | Delete an existing object of a class | `Set status = ##class(package.class).%DeleteId(id)` |