# RHTableQuery

Inherits from: RHObject :: Paginator :: RHQuery


# Class Methods

# Inherited methods

ErrorAssoc OKAssoc

# GetByID

function Dynamic GetByID(Dynamic pk)

# New

function Frame New(Object prgCtx, String tableName, Object obj=Undefined)

# Overrides:

New in class RHQuery

# Instance Methods

# Property Methods

Property methods can be accessed with the valueForKey method.

bury classidentifier classname clone columnnames columnnameswithprefix count currentpagesize cursor distinct endindex errorassoc exists first hash hasnext hasotherpages hasprevious identityhashcode ispagingenabled issortpossible items iterator last methods modelinstance nextpagenumber okassoc pagecount pagenumber pagerange pagesize pagesizes pkdbaliasname pkdbfieldname pkfieldname precache previouspagenumber propertymethods queryvalues reset reverse serialize startindex string tablename tablenamealiased toexcel values_list

# Inherited methods

assert bury cacheMethod cacheValueForKey callSuper checkError class classIdentifier className clone count currentPageSize cursor deserialize dict endIndex endTrans exists extra filter filterIfDefined first fixdbfieldcase hash hasNext hasOtherPages hasPrevious identityHashCode isAccessorMethod isCached isInstanceOf isPagingEnabled isProperty isPropertyMethod isSortPossible iterator join keyToDBFieldnameNoPrefix last max methods min modelInstance nextPageNumber order_by pageCount pageNumber pageRange pageSize pageSizes pluck prepareForReuse previousPageNumber propertyMethods removeFromCache reset resetCache respondsTo reverse setCacheValueForKey setLimit setObject setOffset setOrderBy setPageNumber setPageSize setQueryOrderBy setQueryValues setSort setSQL setValueForKey setValueForKeyPath setValues sort sortCustom startIndex startTrans string sum super toCSV toExcel valueForKey valueForKeyPath values_list

# addColumnSubquery

function Frame addColumnSubquery(String columnName, String query, List queryValues={})

Adds a column subquery to the query. E.g, "select (subquery) as columnName, ...restof query"

# annotate

function Frame annotate(String alias, String aggregate, String fieldName)

For example... The values() method limits the fields, and the annotate() method inserts a groupby condition.

Dynamic items = $RHCore.RHNodeQuery.New(prgCtx) \
	.values({'ParentID'}) \
	.annotate('Total', 'Count', 'ParentID') \
	.items()

# chunk

function Assoc chunk(Integer chunkSize, String fieldName=.pkFieldName())

This interesting function will break the result set into a number of ranges, where each range contains the same number of items (determined by chunkSize) from the result set.

# Parameters
  • chunkSize - The size of each bucket.

  • fieldName - (Optional) The field name to chunk.

# columnNames

function List columnNames()

# Overrides:

columnNames in class RHQuery

# columnNamesWithPrefix

function List columnNamesWithPrefix()

# delete

function Assoc delete()

Bulk delete. Note this is a direct DB write and no callbacks are executed.

# distinct

function Dynamic distinct()

# filterGroupMembership

function Frame filterGroupMembership(String key, Dynamic userid=.fPrgCtx.USession().fUserID)

This filter can be used with a database column that represents a group ID. This will filter all rows where userid is a member of the group.

This is not a permission check. It only checks if the user is a member of the group represenented by key. The filter also returns true if key is that of the user itself.

# Parameters
  • key - The key of the database column to filter on.

  • userid - (Optional) The user to check whether they are a member of key.

# Returns
  • Returns self, the query object.

# filterPermissions

function Frame filterPermissions(Dynamic fieldNames={'PermID','DataID'}, Dynamic userid=.fPrgCtx.USession().fUserID, Integer perm=DAPI.PERM_SEECONTENTS)

This function assumes .fTableName has a DataID & PermID column.

  • DAPI.PERM_SEE
  • DAPI.PERM_SEECONTENTS
  • DAPI.PERM_WRITE
  • DAPI.PERM_DELETE

# filterSelectedFromRequest

function Frame filterSelectedFromRequest(Record request, String fieldName, String pkFieldName=.pKFieldName(), String selectAllFieldName=Str.Format("%1SelectAll", fieldName))

It's important to understand this function replaces the entire query when selectAllFieldName is defined, and appends conditions to the existing query when it is not defined.

# get

function Dynamic get(String field=Undefined, Dynamic operator=Undefined, Dynamic value=Undefined)

# items

function Dynamic items()

# Overrides:

items in class RHQuery

# keyToDBFieldname

function String keyToDBFieldname(String key, Boolean prefix=true)

# Overrides:

keyToDBFieldname in class RHQuery

# limit

function Frame limit(Integer limit)

# pkDBAliasName

function String pkDBAliasName()

# pkDBFieldName

function String pkDBFieldName(Boolean tablePrefix=true)

# pkFieldName

function Dynamic pKFieldName()

# precache

function Frame precache(String pkfieldname=.pkDBAliasName(), String keyTableName=.tableName(), Dynamic items = .items())

The precache() function is used to precache the raw values of a database query.

Cached values can be picked up with the $RHCore.RequestCache.PrecacheQueryset(<keyTableName>, <pk>) function.

# Overrides:

precache in class Paginator

# Parameters
  • pkfieldname - The primary key to index the cached items.

  • keyTableName - Cached items can be picked up using the keyTableName.

# Returns
  • The RHTableQuery.

# queryValues

function List queryValues()

# Overrides:

queryValues in class RHQuery

# resetSubclass

function Void resetSubclass()

# Overrides:

resetSubclass in class RHQuery

# selectForUpdate

function Frame selectForUpdate()

# serialize

function Dynamic serialize()

# Overrides:

serialize in class RHObject

# setAllowMassUpdate

function Frame setAllowMassUpdate(Boolean allowMassUpdate=true)

# setDBFieldNameForKey

function Frame setDBFieldNameForKey(String dbfieldName, String key)

# setEnableBulkUpdate

function Frame setEnableBulkUpdate(Boolean enableBulkUpdate=true)

# setFilterPermissions

function Frame setFilterPermissions(Dynamic fieldNames={'PermID','DataID'}, Dynamic userid=.fPrgCtx.USession().fUserID, Integer perm=DAPI.PERM_SEECONTENTS)

# setPaging

function Frame setPaging(Boolean enabled=true)

# Overrides:

setPaging in class Paginator

# setPKFieldName

function Frame setPKFieldName(Dynamic PKFieldName)

# setTableName

function Frame setTableName(String tableName)

# setUpdateValueForKey

function Dynamic setUpdateValueForKey(Dynamic value, String key)

# sql

function String sql(Dynamic queryField=.fQueryFields, Boolean includeOrderBy=true)

# Overrides:

sql in class RHQuery

# sqlsubquery

function String sqlsubquery(String fieldName=.pkFieldName(), Boolean distinct=false)

# tableName

function String tableName()

# tableNameAliased

function String tableNameAliased()

# union

function Frame union(Frame q)

This method merges the filter conditions (with an or) of two queries and returns a new query.

# update

function Assoc update()

# values

function Frame values(Dynamic fieldNames)

See the annotate() function for more details.

Last Updated: 11/15/2019, 4:24:30 PM