quarta-feira, 22 de dezembro de 2010

Usando SQL no Magik

At the Smallworld Users Conference yesterday, I heard someone ask when GE would provide an interface to write SQL from Magik against VMDS tables. It turns out that the functionality already exists. Here are some examples.

1. You can get a SQL prompt directly at the Magik prompt...

MagikSF> sql(gis_program_manager.cached_dataset(:gis))
$
SQL> SELECT name, address1 FROM hotel ORDER BY address1
$
Name Address 1

Acorn Guest House 154 Chesterton Road
Hamilton Lodge 156 Chesterton Road
De Freville House 166 Chesterton Road
Rosswill 17 Chesterton Road
Cam Guest House 17 Elizabeth Way
Kirkwood House 172 Chesterton Road
All Seasons 219 Chesterton Road
Lyngamore 35 Chesterton Road
Suffolk House 69 Milton Road
Southampton House 7 Elizabeth Way
Ashley Hotel 74 Chesterton Road
Arundel House Chesterton Road
Gonville Hotel Gonville Place
Garden House Granta Place
University Arms Regent Street

15 record(s) selected
SQL> SQL> select count(*) from min_road
$
COUNT(*)

833

1 record(s) selected
SQL> SQL>

NOTE: the sql() procedure is defined in module :sql2. You can load that module if your image doesn't have the sql() procedure loaded.

2. You can also use the sql2_parser object directly in your Magik code.
You can find out more by searching the Smallworld documentation for "SQL Support". To be clear, this is not the same as Smallworld's SQL Server image code. This is strictly related to writing SQL in Magik to query Smallworld tables.
I have never used this in code, but I suppose it could come in handy if you were more comfortable writing a SQL statement compared to writing a selection predicate. I'm curious to hear if anyone else uses this SQL functionality within Smallworld.

Nenhum comentário :

Postar um comentário

Related Posts Plugin for WordPress, Blogger...