|
Monday, December 8, 2003 |
I always find that if I ever have to do anything more than a simple
select/insert/update in SQL I shudder & long for a real language
rather than the various SQL dialects like PL/SQL.
As an experiment we can now use Groovy as a nice little scripting language for performing SQL operations. Here's a GroovyTestCase example that shows the kinds of things that are possible.
So you can do arbitrary SQL commands, passing in groovy variables into
the SQL with the embedded GString expressions and iterate over any
query results as POGOs (Plain Old Groovy Objects :).
Or you can ignore SQL all together and use DataSets which allow you to
perform queries on data sets using normal Groovy closure expressions
like the following
food = sql.dataSet('FOOD')
cheese = food.findAll { it.type == 'cheese' }
cheese.each { println("Eat ${it.name}") }
There's still some way to go before the functionality of GDO is
equivalent to MS's ADO but its a useful start. It might be useful to
integrate with the proposed SDO specification too.
Update: Cedric pointed out in a private mail that the above GroovyTestCase example is not really a proper unit test case, its more of a sample program. Well spotted Cedric :). So here's a better test case which actually tests that the right data comes back from the queries.
4:39:29 PM
|
|
© Copyright 2007 James Strachan.
|
|
|
|
|
|
December 2003 |
Sun |
Mon |
Tue |
Wed |
Thu |
Fri |
Sat |
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
|
|
|
Nov Jan |
|
|
|
|
|
|