4D Blog

Home Product Query your database with an object-oriented approach

Query your database with an object-oriented approach

April 11, 2018

Product

After learning how you can create, update, and delete data, here is a new entry in the ORDA series. In this post, you will see how you can query your datastore in an object-oriented mode. With ORDA, queries are lighter, more readable, and you can navigate through the whole data model using object-oriented concepts !

On top of that, ORDA makes it possible to very easily query several related tables, manage recursive relations on the same table, and use several logical operators in a single query. Plus, you don’t have to worry about setting relations between tables … manually or automatically !

Query with DataStore example 

GET STARTED WITH ORDA QUERYING

As when you would run a query on a table, querying with ORDA is done on a dataclass (which corresponds to a table).

There are several ways to query a dataclass. The following provides a quick overview. For more in-depth information about the query() method, check out the documentation.

1- Provide the query as a single String

Here is a query to get all employees whose first name starts with ‘S’:

C_OBJECT($employees)
$employees:=ds.Employee.query("firstName='S@'") // Query on Employee table

2- Provide the query and values separately using placeholders

Now, let’s say you want to get all employees whose first name starts with ‘D’ or ‘E’. Please note that values to apply are offset in the query and they are referred to with :1, :2, … :n, as shown below:

C_OBJECT($employees)
$employees:=ds.Employee.query("firstName=:1 or firstName=:2";"D@";"E@") // Query on Employee table

Variation: You can also use placeholders through a collection to provide the values. As the example below demonstrates:

C_OBJECT($employees;$params)
// You can use a collection to provide values to apply in the query
$params:=New object
$params.parameters:=New collection("D@";"E@")
$employees:=ds.Employee.query("firstName=:1 or firstName=:2";$params) // Query on Employee table

some Perks of the new way of querying

EASILY USE A RECURSIVE LINK ON A SINGLE TABLE

Consider this recursive link on the “Employee” table:

Using the classic way

This code requests all employees whose first name starts with the letter ‘A’, with a manager having a last name that begins with the letter ‘S’:

ARRAY LONGINT(_managersIDs;0)
QUERY([Employee];[Employee]firstName;"=";"A@")
CREATE SET([Employee];"a")
QUERY([Employee];[Employee]lastName;"=";"S@")
SELECTION TO ARRAY([Employee]ID;_managersIDs)
QUERY WITH ARRAY([Employee]managerID;_managersIDs)
CREATE SET([Employee];"s")
INTERSECTION("a";"s";"result")
USE SET("result")
CLEAR SET("a")
CLEAR SET("s")

using orda

This query is much lighter…

C_OBJECT($entitySelection)
$entitySelection := ds.Employee.query("firstName=:1 and manager.lastName=:2";"A@";"S@")

Don’t wait … start using ORDA now for shorter, cleaner, and more readable code!

Discuss

Tags Database, Objects, ORDA, v17

Latest related posts

  • February 3, 2026

    4D Write Pro – Adding a margin automatically when bullets are set using standard actions

  • January 22, 2026

    Transform Static Documents into Actionable Knowledge with AIKit

  • January 22, 2026

    Deploy Fluent UI effortlessly in your 4D applications

Avatar
Marie-Sophie Landrieu-Yvert
- Product Owner - Marie-Sophie Landrieu-Yvert joined the 4D Product team as a Product Owner in 2017. In this role, she is responsible for writing user stories and translating them into functional specifications. She also ensures that the delivered feature implementation meets the customer's needs. Marie-Sophie graduated from the engineering school ESIGELEC and began her career as an engineer at IBM in 1995. She took part in various projects (maintenance and development projects) and worked as a COBOL developer. She then moved on to work as a UML designer and Java developer. More recently, her main responsibilities included analyzing and writing functional requirements, and coordinating business and development teams.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 21 R2 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 21 R2 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor
Subscribe to 4D Newsletter

© 2026 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy