Addons/data/sqlite/Examples

From J Wiki
Jump to navigation Jump to search
Overview | Basic Usage | Create | Definitions | zFns | Installation | Nulls | Examples | Quirks

There are two sample databases included with the addon in subdirectory db. Other sqlite example databases are readily available on the web.

  • sandp is the standard Suppliers and Parts database
  • chinook is an open source database that is an alternative to Northwind. A selection of tables are included with the addon.

sandp

sandp is available in the addon db directory, and also as a script which defines verb buildsandp. For example:

1. Using the distributed database:

   load 'data/sqlite'

   db=: sqlopen_psqlite_ '~addons/data/sqlite/db/sandp.db'

   sqlhead__db 'sp where qty=400'
β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”
β”‚sidβ”‚pidβ”‚qtyβ”‚
β”œβ”€β”€β”€β”Όβ”€β”€β”€β”Όβ”€β”€β”€β”€
β”‚s1 β”‚p3 β”‚400β”‚
β”‚s2 β”‚p2 β”‚400β”‚
β”‚s4 β”‚p5 β”‚400β”‚
β””β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”˜

2. Using the buildsandp verb:

   load 'data/sqlite/sandp'

   db=: buildsandp '~temp/t1.db'

   sqlhead__db 'sp left join s on sp.sid=s.sid where qty=400'
β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”
β”‚sidβ”‚pidβ”‚qtyβ”‚sidβ”‚name β”‚statusβ”‚city  β”‚
β”œβ”€β”€β”€β”Όβ”€β”€β”€β”Όβ”€β”€β”€β”Όβ”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€
β”‚s1 β”‚p3 β”‚400β”‚s1 β”‚smithβ”‚20    β”‚londonβ”‚
β”‚s2 β”‚p2 β”‚400β”‚s2 β”‚jonesβ”‚10    β”‚paris β”‚
β”‚s4 β”‚p5 β”‚400β”‚s4 β”‚clarkβ”‚20    β”‚londonβ”‚
β””β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜

chinook

For example, using the sqlite z-functions:

   load 'data/sqlite/sqlitez'
   
   dbopen '~addons/data/sqlite/db/chinook.db'

   dbtables''
β”Œβ”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”
β”‚albumsβ”‚artistsβ”‚customersβ”‚genresβ”‚media_typesβ”‚tracksβ”‚
β””β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜

   dbhead 'trackid,name,composer from tracks where name like "%snow%"'
β”Œβ”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚TrackIdβ”‚Name                   β”‚Composer                                                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   9   β”‚Snowballed             β”‚Angus Young, Malcolm Young, Brian Johnson               β”‚
β”‚ 145   β”‚Snowblind              β”‚                                                        β”‚
β”‚ 161   β”‚Snowblind              β”‚Tony Iommi, Bill Ward, Geezer Butler, Ozzy Osbourne     β”‚
β”‚2412   β”‚By-Tor And The Snow Dogβ”‚Geddy Lee And Alex Lifeson/Geddy Lee And Neil Peart/Rushβ”‚
β”‚3277   β”‚Snowblind              β”‚                                                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

   6 dbhead 'artists left join albums where artists.artistid=albums.artistid'
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ArtistIdβ”‚Name             β”‚AlbumIdβ”‚Title                                β”‚ArtistIdβ”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚1       β”‚AC/DC            β”‚1      β”‚For Those About To Rock We Salute Youβ”‚1       β”‚
β”‚1       β”‚AC/DC            β”‚4      β”‚Let There Be Rock                    β”‚1       β”‚
β”‚2       β”‚Accept           β”‚2      β”‚Balls to the Wall                    β”‚2       β”‚
β”‚2       β”‚Accept           β”‚3      β”‚Restless and Wild                    β”‚2       β”‚
β”‚3       β”‚Aerosmith        β”‚5      β”‚Big Ones                             β”‚3       β”‚
β”‚4       β”‚Alanis Morissetteβ”‚6      β”‚Jagged Little Pill                   β”‚4       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜