This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
collection.query( )
|
collection.query ( queryString {; value}{; value2 ; ... ; valueN}{; querySettings}) -> Function result | ||||||||
Parameter | Type | Description | ||||||
queryString | Text |
![]() |
Search criteria | |||||
value | Mixed |
![]() |
Value(s) to compare when using placeholder(s) | |||||
querySettings | Object |
![]() |
Query options: parameters, attributes | |||||
Function result | Collection |
![]() |
Element(s) matching queryString in the collection | |||||
The collection.query( ) method returns all elements of a collection of objects that match the search conditions defined by queryString and (optionally) value and querySettings. If the original collection is a shared collection, the returned collection is also a shared collection.
Note: This method does not modify the original collection.
The queryString parameter uses the following syntax:
propertyPath comparator value {logicalOperator propertyPath comparator value}
For detailed information on how to build a query using queryString, value and querySettings parameters, please refer to the dataClass.query( ) method description.
C_COLLECTION($c)
$c:=New collection
$c.push(New object("name";"Cleveland";"zc";35049))
$c.push(New object("name";"Blountsville";"zc";35031))
$c.push(New object("name";"Adger";"zc";35006))
$c.push(New object("name";"Clanton";"zc";35046))
$c.push(New object("name";"Clanton";"zc";35045))
$c2:=$c.query("name = :1";"Cleveland") //$c2=[{name:Cleveland,zc:35049}]
$c3:=$c.query("zc > 35040") //$c3=[{name:Cleveland,zc:35049},{name:Clanton,zc:35046},{name:Clanton,zc:35045}]
C_COLLECTION($c)
$c:=New collection
$c.push(New object("name";"Smith";"dateHired";!22-05-2002!;"age";45))
$c.push(New object("name";"Wesson";"dateHired";!30-11-2017!))
$c.push(New object("name";"Winch";"dateHired";!16-05-2018!;"age";36))
$c.push(New object("name";"Sterling";"dateHired";!10-5-1999!;"age";Null))
$c.push(New object("name";"Mark";"dateHired";!01-01-2002!))
This example returns persons whose name contains "in":
$col:=$c.query("name = :1";"@in@")
//$col=[{name:Winch...},{name:Sterling...}]
This example returns persons whose name does not begin with a string from a variable (entered by the user, for example):
$col:=$c.query("name # :1";$aString+"@")
//if $astring="W"
//$col=[{name:Smith...},{name:Sterling...},{name:Mark...}]
This example returns persons whose age is not known (property set to null or undefined):
$col:=$c.query("age=null") //placeholders not allowed with "null"
//$col=[{name:Wesson...},{name:Sterling...},{name:Mark...}]
This example returns persons hired more than 90 days ago:
$col:=$c.query("dateHired < :1";(Current date-90))
//$col=[{name:Smith...},{name:Sterling...},{name:Mark...}] if today is 01/10/2018
Note: This last example requires that the "Use date type instead of ISO date format in objects" compatibility option is checked (see Compatibility page).
More examples of queries can be found in the dataClass.query( ) page.
collection.indices( )
dataClass.query( )
entitySelection.query( )
Product: 4D
Theme: Collections
Number:
805267
Created: 4D v16 R6
Modified: 4D v17 R5
4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)