7. Searching Databases
Searching databases with WebDNA and conclusion
Now that you have seen how to build a database, the next logical step is searching and retrieving data. There are two different ways to query the database: the ultrafast (but limiting) [lookup], and the more robust [search].
Imagine we want to pick out the user name of the guy who uses "violet":
[/!]¬Found=not found, sorry!]
which would translate to "look inside the database database1.db, search for value "violet" in the field (column) "colour" and get the associated value for the field "name". Optionally, you could add: if the value does not exist, then show "not found, sorry!"
This kind of search is ultrafast but only gives one value. Now, we want to get all the names for people older than 30:
How does it work? With geagedata=30 we mean find all records where "age" is "greater than or equal to" 30.
There are two records (Peter and John), and we want to get both.
The [founditems][/founditems] is a loop: each time it finds a record that matches, it fills in the value for [name], then continues searching.
Let's imagine we write
The result will be "PeterJohn" with no separation. Adding </br>, as in
allows the user list to show as
Now, let's search using two criteria: older than 30 AND whose colour is yellow:
Note the "rq" at the end of both criteria, which would be a logical "AND".
The result will be "Peter", alone.
Now, let's use a logical "OR": younger than 30 OR whose colour is yellow:
We use ls for "less than" "age" "data" = "30"
But because we have not added "rq" we have the equivalent of a logical "OR".
The result will be "Peter" and "Scott".
All this is too simple? Consider you now know 80% of WebDNA. Of course, there are many more sophisticated tags to round out the language. The purpose of this to show you how easy it is to build an application with WebDNA. On my side, with more than 10 years of WebDNA programming, I have been able to build outrageously complicated applications, administration systems for invoicing, export, salaries, interactive printers, stock and I have never found a limit to WebDNA. There is always a way to do exactly what you want!
This is the source for a summary of all WebDNA contexts. We hope you will enjoy it as much as we do!