This class contains generic debugging, translation
and error handling methods. All the other classes include this
functionality.
Properties
Property |
Description |
Error (Long) |
Contains a MyTable Error Code if an error occurred. See
ErrorTrap and InterpretError methods. |
Errorcode (Long) |
Contains a Clarion ErrorCode if an error occurred when doing
some file access. |
Inited (Long) |
Set to 1 if the object has been initialized. (ie the INIT
method for the object has been called.) |
ShowErrors |
If true then a MESSAGE will appear when ErrorTrap is called.
False by default. |
Methods
MyTableBaseClass
Error
MyTableBaseClass
ErrorCode
MyTableBaseClass
ErrorTrap
ErrorTrap
(String pMethod, String pStr)
Description
Is called whenever an object encounters an error. By default the
error is sent to Debugview so that you can note that it happened. Note
that the
Error and
Errorcode
properties are in scope here. Use InterpretError to turn the
error property into a string.
If you wish to handle errors differently then override this method and
replace it with your own code.
Parameters
Parameter |
Description |
pProcedure |
The name of the method where the error occurred. |
pStr |
Any additional information the method may pass in to make
the error easier to debug or understand. |
Return Value
Nothing
Example
mt MyTableBaseClass
code
mt.ErrorTrap('BrowseCustomers','Result is ODD')
See Also
InterpretError
MyTableBaseClass
GetElapsedTimeUTC
GetElapsedTimeUTC()
Description
Returns the milliseconds elapsed since 1 January 1970 00:00:00 UTC.
Return Value
REAL
Example
r real
mt MyTableBaseClass
code
r = mt.GetElapsedtimeUTC()
MyTableBaseClass
GetLocalTimeDifference
GetLocalTimeDifference()
Description
Returns the milliseconds difference between local time and utc time.
UTC = local time + difference.
Return Value
REAL
Example
r real
mt MyTableBaseClass
code
r = mt.GetLocalTimeDifference()
MyTableBaseClass
GetMachineID
GetMachineID()
Description
Returns the MachineGuid, as stored in the Windows registry.
Return Value
String
Example
id string(255)
mt MyTableBaseClass
code
id = mt.GetMachineID()
MyTableBaseClass
Init
Init()
Description
Sets the Inited property to true. Typically fleshed out in derived
classes. Whether this method needs to be called or not depends on the
requirements of the derived class.
Return Value
None
Example
mt MyTableBaseClass
code
mt.Init()
MyTableBaseClass
GetMachineName
GetMachineName()
Description
Returns the Machine Name, as stored in the Windows registry.
Return Value
String
Example
name string(255)
mt MyTableBaseClass
code
name = mt.GetMachineName()
MyTableBaseClass
GetWindowsUserName
GetWindowsUserName()
Description
Returns the User Name of the person currently logged into Windows.
Return Value
String
Example
user string(255)
mt MyTableBaseClass
code
user = mt.GetwindowsUserName()
MyTableBaseClass
InterpretError
InterpretError()
Description
Returns a description of an error based on the value in the error
property.
Parameters
None
Return Value
A string.
See Also
ErrorTrap
MyTableBaseClass
Start
Start()
Description
Sets the object back to a virgin state ready for reuse.
Parameters
Parameter |
Description |
pField |
The field number of the field to alert. |
Return Value
None
Example
mt MyTableBaseClass
code
mt.start()
See Also
MyTableBaseClass
Trace
Trace(String
pStr)
Description
A debugging method that makes it easy to send strings to Debugview.
Parameters
Parameter |
Description |
pStr |
A String to send to Debugview |
Return Value
None
Example
mt MyTableBaseClass
code
mt.start()
See Also
This is a generic class for dealing with tables
where the exact table definition is unknown. This allows generic code to
be written, against an unspecified table declaration. Code written using
this approach does not need to change if the table structure is updated.
This class works by finding, and then using, fields in the table based
on their label (aka their "name".)
Properties
This class is derived from the
MyTableBaseClass
so the
properties from that
class also exist.
Property |
Description |
jsonQueue |
And internal queue of JsonClass objects, used when ParseBlob
is used without passing in a JsonClass object. |
Methods
MyTableClass
CleanFieldName
CleanFieldName(*StringTheory
pFieldName)
Description
Removes the prefix (if it exists) from a fieldname. Also removes any
extended attributes (if they exist) from a fieldname. This is a
utility method and is not usually called directly.
Parameters
Parameter |
Description |
pFieldName |
A StringTheory value containing the fieldname. |
Return Value
None
Example
fieldname StringTheory
code
fieldname.SetValue(lower(Who(pGroup,FieldNumber)))
self.CleanFieldName(fieldname)
See Also
MyTableClass
ClearTable
ClearTable(*File
pTable,Long pN=0)
Description
Clears all the fields in a table record, including all BLOB and MEMO
fields (IF the table is OPEN.) Can be used in place of
Clear(table) or Clear(tab:record) so that any BLOB's or MEMO fields
are correctly initialized and cleared as well. This is especially
important for BLOBs in SQL tables which need to be initialized before
they can be used.
Parameters
Parameter |
Description |
pTable |
The table which contains the record to be cleared. |
pN |
A numeric constant; either 1 or -1. If omitted or zero,
numeric variables are cleared to zero, STRING variables are
cleared to spaces, and PSTRING and CSTRING variables are set
to zero length. If n is 1, each field is set to the highest
possible value for that data type. For the STRING, PSTRING and
CSTRING data types, that is all ASCII 255. If n is -1, each
field is set to the lowest possible value for that data type.
For the STRING data type, that is all ASCII zeroes (0). For
the PSTRING and CSTRING data types, that is a zero length
string.
BLOBs and MEMOs are not affected by this paameter. In all
cases BLOBs and MEMOs are cleared to an empty string. |
Return Value
mt:ok if the operation is successful.
mt:notok if the passed in Table parameter is
null.
Example
mt MyTable
code
mt.ClearTable(Customers)
See Also
MyTableClass
FieldInUniqueKey
FieldInUniqueKey(*File
pTable, String pFieldName, Long pLabel)
Description
Returns true if the field is in a unique key in the table declaration.
Parameters
Parameter |
Description |
pTable |
A StringTheory value containing the fieldname. |
pFieldName |
|
pLabel |
|
Return Value
If the field is in a unique key, then returns true. If not in a unique
key then returns false.
Example
mt MyTableClass
code
result = mt.FieldInUniqueKey(Customers,'Id')
See Also
MyTableClass
Get
Get (*File
pTable, String pFieldname, String pValue, Long pLabel)
Get (*File pTable, String pFieldname1, String pValue1, String
pFieldname2, String pValue2, Long pLabel)
Description
Loads a record from the table, where the fieldname matches a specific
value.
Parameters
Parameter |
Description |
pTable |
The table containing the field. |
pFieldName |
The name of the field. This name is not case sensitive. |
pValue |
The value to load. |
pLabel |
If set to mt:name then the
value in the External Name is used when matching the FieldName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used instead of
the NAME. |
Return Value
mt:ok if a record is found.
mt:notok
if the Get fails for some reason.
If the pTable parameter is null then Error is set to
mt:MissingTableParameter
and
ErrorTrap will be
called.
If the Field name is not found then Error is set to
mt:FieldNotFound
and
ErrorTrap will be
called. The table record will be cleared.
If there is no key on that field then Error is set to
mt:KeyNotFound
and
ErrorTrap will be
called. The table record will be cleared.
When selecting a key then the preference is given to single component
keys. If a multi-component key is used then the first record in that
key will be returned by this call.
If a record matching that specific value is not found then the
Error property will be set to
mt:RecordNotFound.
The record buffer will be cleared.
ErrorTrap will
NOT be called. The
Errorcode property
will contain the Table error from the read.
Errorcode()
and
Error() are still valid at the end of
the method call.
Example
SetPaid Procedure(*File pTable, Long
pValue)
mt MyTable
code
If mt.Get(pTable,'id',5) = mt:ok
mt.SetField(pTable,'Paid',pValue,mt:label)
Put(pTable)
End
See Also
GetKey,
SetField
MyTableClass
GetBlob
GetBlob(*File
pTable, String pBlobName, StringTheory pBlob, Long pLabel)
Description
Takes the value that is currently in the blob, and moves it into the
StringTheory object. It identifies the blob field using the blob name.
This method works on the currently loaded record.
This method only works on Blob fields. Use
GetField
for regular fields.
This method requires the table structure to be
open.
Parameters
Parameter |
Description |
pTable |
The table containing the blob. |
pBlobName |
The name of the blob to move to the StringTheory object.
This parameter is not case sensitive. |
pBlob |
A StringTheory object to accept the current contents of the
blob. |
pLabel |
If set to mt:name then the
value in the External NAME is used when matching the BlobName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used instead of
the NAME. |
Return Value
mt:ok if successful.
mt:notok if the pTable parameter is blank
or the pBlobName field is not found.
If the blob is not found (by name) then the Error property is set to
mt:BlobNotFound and the
ErrorTrap method will be called. The pBlob parameter will be
cleared.
If the pTable parameter is blank then the Error property will be set
to
mt:MissingTableParameter and the
ErrorTrap
method will be called.
If the table is not open then the Error property will be set to
mt:FileNotOpen and the
ErrorTrap
method will be called.
If the pBlob parameter is null then the Error property will be set to
mt:MissingStringTheoryParameter and the
ErrorTrap method will be
called.
Example
GetNotes Procedure(*File pTable)
str StringTheory
mt MyTableClass
code
mt.GetBlob(pTable,'Notes',str,mt:label)
See Also
GetBlobNumber,
SetBlob,
SetValue,
GetField,
ErrorTrap
MyTableClass
GetBlobNumber
GetBlobNumber(*File
pTable, String pBlobName, Long pLabel)
Description
Gets the Blob number for the named blob in the table structure.
Parameters
Parameter |
Description |
pTable |
The table containing the blob. |
pBlobName |
The name of the blob to find. do not include the prefix in
the name. The case of this parameter does not matter. |
pLabel |
If set to mt:name then the
value in the External NAME is used when matching the BlobName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used instead of
the NAME. |
Return Value
The number of the blob in the table structure. Blobs are numbered from
-1 to -n where n is the total number of blobs and memos in the table.
If the pTable parameter is null then Error is set to
mt:MissingTableParameter
and
ErrorTrap will be
called.
If the blob is not found then 0 is returned.
Example
mt
MyTableClass
blobNumber Long
code
blobnumber = mt.GetBlobNumber(customers,'notes',mt:label)
See Also
GetBlob,
GetField,
GetFieldNumber
MyTableClass
GetField
GetField(*File
pTable, String pFieldname, Long pLabel)
Description
Get a reference to a field inside a table, by name. This method works
on the currently loaded record.
this method only works on regular fields. Use
GetBlob for Blob fields.
Parameters
Parameter |
Description |
pTable |
The table containing the field. |
pFieldName |
The name of the field. This field is not case sensitive. |
pLabel |
If set to mt:name then the
value in the External NAME is used when matching the FieldName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used instead of
the NAME. |
Return Value
An ANY containing a reference to the field. Changing the value in the
ANY then changes the value in the field.
If the pTable parameter is null then Error is set to
mt:MissingTableParameter and
ErrorTrap
will be called.
If the field is not found then a Null is returned.
Example
GetPhoneNumber Procedure(*File
pTable)
mt
MyTableClass
Fld
Any
code
Fld &= mt.GetField(pTable,'phoneNumber',mt:label)
return Fld
See Also
GetFieldName,
GetFieldNumber,
GetKey,
GetBlob,
SetField,
GetFieldUnique,
GetFieldValue
MyTableClass
GetFieldName
GetFieldName(*File
pTable, Long pFieldNumber, Long pCase=mt:CaseLower, Long pLabel)
Description
Gets the name of a field in the Table. The field can be either a
regular field in the record, or a memo or blob field. If a memo or
blob field then the field number is < 0.
Parameters
Parameter |
Description |
pTable |
The table containing the field. |
pFieldNumber |
The field number of the field in the structure. |
pCase |
Can be one of mt:CaseLower, mt:CaseUpper or mt:CaseAsIs.
If omitted then mt:CaseLower is
used. |
pLabel |
If set to mt:name then the
value in the External Name is returned.
If set to mt:Label (recommended)
then the LABEL of the field is returned.
Note that if the case is mt:CaseAsIs
then the LABEL is always UPPER case. |
Return Value
A string containing the name of the field. The field is returned
"cleaned" with the prefix and piped values removed.
If the pTable parameter is null then Error is set to
mt:MissingTableParameter and
ErrorTrap
will be called.
If the FieldNumber is not found then a blank string is returned.
Example
mt MyTableClass
name string(100)
code
name = mt.GetFieldName(Customers, 2,mt:label)
See Also
GetField,
GetFieldNumber,
CleanFieldName,
GetFieldUnique,
GetFieldValue
MyTableClass
GetFieldNumber
GetFieldNumber(*File
pTable, String pFieldName, Long pLabel)
Description
Get the field number of a field in the table declaration.
Parameters
Parameter |
Description |
pTable |
The table containing the field. |
pFieldName |
The name of the field. Do not include the prefix in the
name. The case of this parameter does not matter. |
pLabel |
If set to mt:name then the
value in the External NAME is used when matching the FieldName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used instead of
the NAME. |
Return Value
A Long containing the number of the field.
If the pTable parameter is null then Error is set to
mt:MissingTableParameter
and
ErrorTrap will be
called.
If the field is not found then 0 is returned.
Example
mt MyTableClass
x Long
code
x = mt.GetFieldNumber(customers,'email',mt:label)
See Also
GetField,
GetFieldName,,
GetBlobNumber,
GetFieldValue
MyTableClass
GetFieldUnique
GetFieldUnique(*File
pTable, String pFieldName, Long pLabel)
Description
Determine if a field in the table is declared as unique or not. A
field is considered to be unique if it is the only component in a
unique key.
Parameters
Parameter |
Description |
pTable |
The table containing the field. |
pFieldName |
The name of the field. Do not include the prefix in the
name. The case of this parameter does not matter. |
pLabel |
If set to mt:name then the
value in the External NAME is used when matching the FieldName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used instead of
the NAME. |
Return Value
True if the field is unique,
false
if not.
If the pTable parameter is null then Error is set to
mt:MissingTableParameter
and
ErrorTrap will be
called.
If the field is not found then
false is
returned.
Example
mt MyTableClass
x Long
code
x = mt.GetFieldUnique(customers,'email',mt:label)
See Also
GetField,
GetFieldName,
,
GetBlobNumber,
GetFieldValue
MyTableClass
GetFieldValue
GetFieldValue(*File
able, String pFieldname, Long pLabel)
Description
Get the current value of a field inside a table, by name. This method
works on the currently loaded record.
This method only works on regular fields. Use
GetBlob for Blob fields.
Parameters
Parameter |
Description |
pTable |
The table containing the field. |
pFieldName |
The name of the field. This field is not case sensitive. |
pLabel |
If set to mt:name then the
value in the External NAME is used when matching the FieldName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used instead of
the NAME. |
Return Value
A string containing the contents of the field.
If the pTable parameter is null then Error is set to
mt:MissingTableParameter and
ErrorTrap
will be called.
If the field is not found then a blank string is returned.
Example
GetPhoneNumber Procedure(*File
pTable)
mt
MyTableClass
Phone
String(100)
code
Phone = mt.GetFieldValue(pTable,'phoneNumber',mt:label)
See Also
GetFieldName,
GetFieldNumber,
GetKey,
GetBlob,
SetField,
GetFieldUnique,
GetField
MyTableClass
GetKey
GetKey(*File
pTable, String pFieldname, Long pLabel)
GetKey(*File pTable, String pFieldname, String pFieldname2, Long
pLabel)
Description
Searches for a key on the table which has the fieldname as the first
component of the key. Up to two field names can be passed. If two
fields are passed then a key with those two fields, in that order, at
the start of the key will be returned.
Parameters
Parameter |
Description |
pTable |
The table containing the field. |
pFieldName |
The name of the field. This parameter is not case sensitive.
Do not include the prefix in the name. |
pFieldName2 (optional) |
The name of a second component field in the key. Do not
include the prefix in the name. The case of this
parameter does not matter. |
pLabel |
If set to mt:name then the
value in the External NAME is used when matching the FieldName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used instead of
the NAME. |
Return Value
A reference to a key, where the fieldname is the first field in the
key. Preference is given to single-component-keys (or two-component
keys in the case of two fieldnames)
If no key exists with the field as the first component of the key,
then a
NULL is returned.
Example
mt MyTableClass
key &key
code
key &= mt.GetKey(Customers,'Guid',mt:label)
See Also
Get,
GetPrimaryKey
MyTableClass
GetPrimaryKey
GetPrimaryKey(*File
pTable)
Description
Searches for a primary key on the table
Parameters
Parameter |
Description |
pTable |
The table containing the key. |
Return Value
A reference to a key, where the key is set as a primary key.
If no primary key exists, then the first declared unique key is
returned. If there is no unique key in the table declaration then a
NULL is returned.
Example
mt MyTableClass
key &key
code
key &= mt.GetPrimaryKey(Customers)
See Also
GetKey
MyTableClass
GetValueFromInsideBlob
GetValueFromInsideBlob(*File
pTable, String pBlobName, String pName, Long pLabel)
Description
This method requires jFiles.
If the blob contains a JSON Group, then this extracts a value from
inside that JSON. This method calls LoadBlob with the table and
blobname, and then parses the Json for the pName value.
This method works on the currently loaded record, it does not change
the file record buffer.
This method is not suitable for Blobs where the JSON holds a queue.
Parameters
Parameter |
Description |
pTable |
The table containing the blob. |
pBlobName |
The name of the blob in the table. |
pName |
The name of the value in the JSON to fetch. This field is
NOT case sensitive. So if there are multiple fields in the
JSON, with names differing only in case, it'll always return
the first one. |
pLabel |
If set to mt:name then the
value in the External NAME is used when matching the BlobName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used instead of
the NAME. |
Return Value
The value of the JSON node. If the node is not found then a blank
string is returned.
If the pTable parameter is null then the
Error property
is set to
mt:MissingTableParameter, and
a blank string is returned.
If there is no blob found with that name then the
Error
property is set to
mt:BlobNotFound
and a blank string is returned.
Example
mt MyTableClass
age Long
code
age = mt.LoadBlob(Customers,'attributes','age',mt:label)
See Also
SaveBlob,
LoadBlob
MyTableClass
LoadBlob
LoadBlob(*File
pTable, String pBlobName, *JsonClass pJson, Long pLabel) [1]
LoadBlob(*File pTable, String pBlobName, *Group pGroup, Long
pLabel) [1]
LoadBlob(*File pTable, String pBlobName, *Queue pQueue, Long
pLabel) [1]
LoadBlob(*File pTable, String pBlobName, *String pString, Long
pLabel)
Description
[1] This
method requires jFiles.
Use this when the blob contains a valid JSON string. This
method parses that string into a jFiles JSONCLASS object. This method
works on the currently loaded record.
If a JsonClass object is passed to the method, then it will be used.
If it is not passed, but a Group or Queue is passed instead then the
JSON will be parsed directly into the GROUP or QUEUE structure.
This method works on the currently loaded record, it does not change
the file record buffer.
Parameters
Parameter |
Description |
pTable |
TThe table containing the blob. |
pBlobName |
The name of the blob in the table. |
pJson |
A jFiles JsonClass object to hold the parsed value. |
pGroup
pQueue |
Pass one of these instead of the pJson parameter to parse
the JSON directly into the passed Group or Queue. |
pString |
This version of the method does not use jFiles. |
pLabel |
If set to mt:name then the
value in the External Name is used when matching the FieldName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used instead of
the NAME. |
Return Value
mt:ok if the method is successful.
If the pTable parameter is null then the
Error property
is set to
mt:MissingTableParameter, and
mt:notok is returned.
IIf there is no blob found with that name then the
Error
property is set to
mt:BlobNotFound
and
mt:notok is returned.
Example
mt MyTableClass
json JsonClass
code
mt.LoadBlob(Customers,'attributes',json,mt:label)
See Also
SaveBlob,
GetValueFromInsideBlob
MyTableClass
Open
Open(*File
pTable)
Description
Opens the table if it is not open. Tables are not created. There is no
equivalent Close method.
Parameters
Parameter |
Description |
pTable |
The table to Open. |
Return Value
mt:ok if successful.
mt:notok if the pTable parameter is blank
or the table cannot be opened.
If the table cannot be opened then the Error property is set to
mt:CantOpenTable and the
ErrorTrap
method will be called.
If the pTable parameter is blank then the Error property will be set
to
mt:MissingTableParameter and the
ErrorTrap
method will be called.
Example
str StringTheory
mt MyTableClass
code
str.SetValue('myTable is amazing')
mt.open(Customers)
See Also
MyTableClass
SaveBlob
SaveBlob(*File
pTable, String pBlobName, *JsonClass pJson, Long pLabel)[1]
SaveBlob(*File pTable, String pBlobName, *Group pGroup, Long pLabel)[1]
SaveBlob(*File pTable, String pBlobName, *Queue pQueue, Long pLabel)[1]
SaveBlob(*File pTable, String pBlobName, *String pString, Long
pLabel)
Description
[1]
This method requires jFiles.
Takes the contents of the pJson object, and places it in the Blob.
This method works on the currently loaded record - it does not save
the record to the disk.
If a JsonClass object is passed to the method, then it will be used.
If it is not passed, but a Group or Queue is passed instead then the
JSON will be saved directly from the GROUP or QUEUE structure.
This method works on the currently loaded record, it does not change
the file record buffer.
Parameters
Parameter |
DDescription |
pTable |
The table containing the blob. |
pBlobName |
The name of the blob in the table. |
pGroup
pQueue |
Pass one of these instead of the pJson parameter to save the
JSON directly from the passed Group or Queue. |
pString |
This version of the method does not use jFiles. |
pLabel |
If set to mt:name then the
value in the External Name is used when matching the FieldName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used instead of
the NAME. |
Return Value
mt:ok if the method is successful.
If the pTable parameter is null then the
Error property
is set to
mt:MissingTableParameter, and
mt:notok is returned.
If there is no blob found with that name then the
Error
property is set to
mt:BlobNotFound
and
mt:notok is returned.
Example
mt MyTableClass
json JsonClass
code
json.Save(AttributesGroup)
mt.ParseBlob(Customers,'attributes',json,mt:label)
See Also
Load Blob,
GetValueFromInsideBlob
MyTableClass
SetBlob
SetBlob(*File
pTable, String pBlobName, StringTheory pBlob, Long pLabel)
Description
Takes the value that is currently in the StringTheory object, and
moves it into the blob. It identifies the blob field using the blob
name. This method works on the currently loaded record.
This method requires the table structure to be
open.
Parameters
Parameter |
DDescription |
pTable |
The table containing the blob. |
pBlobName |
The name of the blob to accept the contents of the
StringTheory object. This parameter is not case sensitive. |
pBlob |
A StringTheory object to move to the blob. |
pLabel |
If set to mt:name then the
value in the External NAME is used when matching the BlobName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used instead of
the NAME. |
Return Value
mt:ok if successful.
mt:notok if the pTable parameter is blank
or the pBlobName field is not found.
If the blob is not found then the Error property is set to
mt:BlobNotFound and the
ErrorTrap
method will be called.
If the pTable parameter is blank then the Error property will be set
to
mt:MissingTableParameter and the
ErrorTrap
method will be called.
Example
str StringTheory
mt MyTableClass
code
str.SetValue('myTable is amazing')
mt.SetBlob(Customers,'Notes',str,mt:label)
See Also
GetBlobNumber,
GetBlob,
SetField,
SetValue
MyTableClass
SetField
SetField (*File
pTable, String pFieldName, String pValue, Long pLabel)
Description
Sets the value of a specific field to a specific value.
Parameters
Parameter |
Description |
pTable |
The table containing the field. |
pFieldName |
The name of the field to set. This parameter is not case
sensitive. |
pValue |
The new value for the field. |
pLabel |
If set to mt:name then the
value in the External NAME is used when matching the FieldName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used instead of
the NAME. |
Return Value
mt:ok if successful.
mt:notok if not successful.
If the field is not found then the Error property is set to
mt:FieldNotFound and the
ErrorTrap
method will be called. The current value of the field will be
unchanged.
If the pTable parameter is blank then the Error property will be set
to
mt:MissingTableParameter and the
ErrorTrap
method will be called. The current value of the field will be
unchanged.
Example
SetPaid Procedure(*File pTable)
mt MyTableClass
ans Long
code
ans = mt.SetField(pTable,'paid',mt:label)
See Also
GetBlobNumber,
GetBlob,
GetField,
SetValue
MyTableClass
SetValue
SetValue (*File
pTable, String pFieldName, String pValue, Long pLabel)
Description
Sets the value of a specific field, or blob to a specific value. Use
SetField or
SetBlob
if you know the FieldName is a field, or blob. Use this method when
you don't know if the field is a regular field, or a blob.
Parameters
Parameter |
Description |
pTable |
The table containing the field or blob. |
pFieldName |
The name of the field or blob to set. This parameter is not
case sensitive. |
pValue |
The new value for the field or blob. |
pLabel |
If set to mt:name then the
value in the External NAME is used when matching the FieldName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used
instead of the NAME. |
Return Value
mt:ok if successful.
mt:notok if not successful.
If the field is not found then the Error property is set to
mt:FieldNotFound and the
ErrorTrap
method will be called. The current value of the field will be
unchanged.
If the pTable parameter is blank then the Error property will be set
to
mt:MissingTableParameter and the
ErrorTrap
method will be called. The current value of the field will be
unchanged.
Example
SetNotes Procedure(*File pTable,
String pNotes)
mt MyTableClass
code
mt.SetValue(pTable,'notes',pNotes,mt:label)
See Also
GetBlob,
GetField,
SetField,
SetBlob
MyTableClass
ViewBlob
ViewBlob(*File
pTable, String pBlobName, Long pLabel)
Description
Send the contents of a Blob field to DebugView.
Parameters
Parameter |
Description |
pTable |
The table containing the blob. |
pBlobName |
The name of the blob in the table. This parameter is not
case sensitive. |
pLabel |
If set to mt:name then the
value in the External NAME is used when matching the BlobName
parameter. If set to mt:Label
(recommended) then the LABEL of the field is used instead of
the NAME. |
Return Value
Nothing
Example
mt MyTableClass
code
mt.ViewBlob(Customers,'notes',mt:label)
See Also
ParseBlob,
SaveBlob
This class requires
Cryptonite
This class allows table rows, or table fields, to be made secure.
Properties
This class is derived from the
MyTableClass,
so the
properties for that
class, and the
properties for
the
MyTableBaseClass also exist.
Property |
Description |
ClearTamperedFields |
If set to true (the default) then fields are cleared if they
fail the hash test, or the hash fails to decrypt.
Encrypted fields that themselves fail to decrypt are always
cleared. |
CustomerSecret
String(255) |
The secret for this customer (optional). Can be set via the
SetCustomerSecret method. |
DesiredEncryptionVersion
Long |
The version of the encryption desired. Currently set to one
of mt:NoEncryption or
mt:Aes256EncryptionWithSha256Hash. This property is
set in the Start method. It should not be changed by the
developer. |
ProgramSecret
String(255) |
The secret for this program. Set via the SetProgramSecret
method. |
SaltFieldName
String(255) |
The name of the unique field in the table. This is typically
the GUID field (and this property defaults to GUID).
The Salt Field is used by derived classes, typically to bind
encrypted fields to a specific row. |
Table
&File |
The table which is attached to the object, via the Init
method. |
TableSecret |
The secret for this table (optional). Can be set via
SetTableSecret method. |
TamperingDetected |
Set by the DecryptRecord method if any of the fields fail
the hash test. |
TamperingFieldList |
A list of the fields protected by a hash that failed the
hash test. (Note, all the fields protected by one hash will
fail the test if that hash fails.) |
Methods
This class is derived from the MyTableClass, so
the
methods for that class, and
the
methods for the
MyTableBaseClass also exist.
SecureMyTableClass
AddField
AddField(String
pFieldName, Long pFieldEncrypted, <String pHashFieldName>)
Description
Adds a field to the list of fields that must be encrypted.
Parameters
Parameter |
Description |
pFieldName |
The name of the Field, Memo or Blob to encrypt. You do not
need to include the prefix in the field name. |
pFieldEncrypted |
One (or more) of;
mt:encrypt the field will be
encrypted
mt:hash the (unencrypted) value of
the field will be added to the rowhash value.
|
pHashFieldName |
If the field has a personal hash field then add the
name of the HashField here. The hash field should be a string
type of at least 48 bytes long. If using a Ustring it should
be at least 96 bytes long. |
Notes
Combining multiple fields into one field for the Rowhash, is not
without risk. See the section on
RowHashing
for more infomation.
Return Value
None
Example
smt SecureMyTableClass
code
smt.Init(Customers,ProgramSecret)
smt.SetSaltFieldName('id')
smt.AddField('PhoneNumber')
smt.AddField('Notes','NotesHash')
See Also
EncryptRecord,
DecryptRecord,
Init,
ParseTable
SecureMyTableClass
DecryptRecord
DecryptRecord()
Description
Decrypt a record after it has been loaded. All the fields, and blobs,
that have been added via the AddField method, will be decrypted.
This method is "safe" meaning that it can be called multiple times on
the same record. If the record is already decrypted (or was never
encrypted) then nothing will happen.
Parameters
None
Return Value
mt:ok if successful,
mt:notok
if not successful.
Example
smt SecureMyTableClass
code
smt.Init(Customers,ProgramSecret)
smt.SetSaltFieldName('id')
smt.AddField('PhoneNumber')
Get(Customers)
smt.DecryptRecord()
See Also
EncryptRecord,
Init,
AddField
SecureMyTableClass
EncryptRecord
EncryptRecord()
Description
Encrypt a record before it is saved. All the fields, and blobs, that
have been added via the
AddField
method, will be encrypted.
This method is "safe" meaning that it can be called multiple times on
the same record. If the record is already encrypted (or was never
decrypted) then nothing will happen.
Parameters
None
Return Value
mt:ok if successful,
mt:notok
if not successful.
Example
smt SecureMyTableClass
code
smt.Init(Customers,ProgramSecret,TableSecret,CustomerSecret)
smt.SetSaltFieldName('id')
smt.AddField('PhoneNumber')
Cus:PhoneNumber = '011 1234 567'
smt.EncryptRecord()
Add(Customers)
See Also
DecryptRecord,
Init,
AddField
SecureMyTableClass
Init
Init(*File
pTable, String pProgramSecret, <String pTableSecret>,
<String pCustomerSecret>)
Description
Attaches a specific SecureMyTableClass object to a specific database
table. Before changing from one table to another (for the same object)
call the Start method. This method makes an implicit call to
ParseTable.
Parameters
Parameter |
Description |
pTable |
The table that this class will be working on. |
pProgramSecret |
The secret key, provided by the developer of the program. |
pTableSecret |
Optional. The secret key for this table, provided by the
developer of the program. Using this prevents data from being
taken from one table, and placed in another table, where the
rows have the same row Id. |
pCustomerSecret |
Optional. The secret key as entered by the customer. This
prevents the customer data from being exposed to the
developers. It also ensures the data for one site is encrypted
to differnet values than another site. Be warned though, if
the customer forgets this secret then all encrypted data is
lost. So use this feature with care. |
Return Value
mt:ok if successful.
If the pTable parameter is null then
ErrorTrap is called, and
mt:notok
is returned.
Example
smt SecureMyTableClass
code
if smt.Init(Customers,ProgramSecret) = mt:ok
smt.SetSaltFieldName('id')
end
See Also
EncryptRecord,
DecryptRecord,
AddField,
SetSaltFieldName,
ParseTable
SecureMyTableClass
MakeHash
MakeHash(StringTheory
pStr, Long pAlgorithm=cs:CALG_SHA_256)
Description
Hashes the contents of a StringTheory object, using the desired
hashing algorithm. The default algorithm is SHA256.
Parameters
Parameter |
Description |
pStr |
the StringTheory object to hash. The contents of the object
are changed so only the hash is inside the object when it is
done. |
pAlgorithm |
the algorithm to use. Can be one of cs:CALG_MD5,
cs:CALG_SHA, cs:CALG_SHA_256, cs:CALG_SHA_384,
cs:CALG_SHA_512 and others. See the Cryptonite
documentation for a full list. If omitted the default is cs:CALG_SHA_256. |
Return Value
Returns
mt:ok if successful, and
mt:notok if not successful.
If successful then the contents of the pStr object are changed.
Example
str StringTheory
smt SecureMyTableClass
code
str.SetValue('My Table is wonderful')
smt.MakeHash(str)
See Also
MakePasswordHash (1)
SecureMyTableClass
MakePasswordHash (1)
MakePasswordHash(StringTheory
pStr, String pSalt, String pPassword)
Description
Takes in a Salt and Password, and returns a StringTheory object
containing the Salted-Hashed-Password.
Parameters
Parameter |
Description |
pStr |
A StringTheory object to hold the calculated Salted Hash. |
pSalt |
The Salt value. |
pPassword |
The Password value |
Return Value
Returns
mt:ok if successful, and
mt:notok if not successful.
If successful then the contents of the pStr object are changed.
Example
str StringTheory
smt SecureMyTableClass
code
smt.MakePasswordHash(loc:password,loc:salt,str)
See Also
MakeHash,
MakePasswordHash
(2)
SecureMyTableClass
MakePasswordHash (2)
MakePasswordHash(String
pSalt, String pPassword)
MakePasswordHash(String pPassword)
Description
Takes in a Salt and Password, and returns a String containing the
Salted-Hashed-Password.
Parameters
Parameter |
Description |
pSalt |
The Salt value. If omitted the table salt field is used. |
pPassword |
The Password value |
Return Value
Returns a String containing the hash, if the operation is successful.
A blank string if not successful.
Example
newPassword String(255)
smt SecureMyTableClass
code
cus:passwordhash = smt.MakePasswordHash(cus:guid,newPassword)
See Also
MakeHash,
MakePasswordHash
(1)
SecureMyTableClass
ParseTable
ParseTable()
Description
Processes the table structure of the current table, searching for
extended attributes, and making the appropriate call to AddField. In
other words transforms the dictionary extended attributes into the
necessary AddField commands.
This method is called from the Init method, and does not need to be
called manually.
Return Value
Nothing
See Also
Init,
Extended
Name Attributes,
AddField,
SetSaltFieldName
SecureMyTableClass
SetSaltFieldName
SetSaltFieldName(String
pSaltFieldName)
Description
Sets the name of the salt field. This should be the unique field for
the row. The contents of this field are used as part of the encryption
key, so effectively this "binds" the data in the row to this specific
ID. If the contents of this field are changed, while the row is still
encrypted, then the encrypted data will be lost.
If this method is not called then the fieldname, as set by an extended
attribute in the table declaration (ie the dictionary) is used. If no
extended attribute is set then the default Salt Field Name (GUID) will
be used. So if your table contains an unchanging field called GUID
then you don't need to call this method.
Parameters
Parameter |
Description |
pSaltFieldName |
The name of the salt field. |
Return Value
None
Example
smt SecureMyTableClass
code
smt.Init(Customers,ProgramSecret)
smt.SetSaltFieldName('id')
smt.AddField('PhoneNumber')
Cus:PhoneNumber = '011 1234 567'
smt.EncryptRecord()
Add(Customers)
See Also
Init,
Extended
Name Attributes
SecureMyTableClass
Start
Start()
Description
Sets the object back to a virgin state ready for reuse
Parameters
Parameter |
Description |
pField |
The field number of the field to alert. |
Return Value
None
Example
See Also
SecureMyTableClass
UpgradeRecords
UpgradeRecords(Long
pProgressControl=0)
Description
This method loops through all the records in the table, and if the
EncryptionVersion field is not the version in the DesiredEncryption
property, then it decrypts the record (with the old version), encrypts
the record (with the new version) and saves the record.
For each record (that has the wrong version number) the ValidateRecord
method will be called after the record has been decrypted. If the
ValidateRecord method returns mt:RecordFiltered then the record will
not be encrypted, and saved. If the ValidateRecord returns
mt:OutOfRange then the method
Parameters
Parameter |
Description |
pProgressControl |
If this field is set, then the prop:progress of this control
is updated in the range 0 to 100. In other words the progress
control will be updated as the method iterates through the
records. |
Return Value
None
Example
smt SecureMyTableClass
code
smt.Init(Customers,'secret','secret','secret')
smt.Upgraderecords(?progress1)
See Also
Init, ValidateRecord
SecureMyTableClass
ValidateRecord
ValidateRecord()
Description
Sets the object back to a virgin state ready for reuse
Parameters
Parameter |
Description |
pField |
The field number of the field to alert. |
Return Value
None
Example
See Also