From: Jess Robinson Date: Mon, 12 Nov 2007 21:13:33 +0000 (+0000) Subject: Added cookbook recipe for using dual, thanks Richard X-Git-Tag: v0.08010~35 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=16cd5b282a77840ce684f48c5324cfd7418d17ca;p=dbsrgits%2FDBIx-Class.git Added cookbook recipe for using dual, thanks Richard --- diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 0552a03..f953b0d 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -920,6 +920,100 @@ of the schema, plus scripts to convert from version 0.1 to 0.2. This requires that the files for 0.1 as created above are available in the given directory to diff against. +=head2 select from dual + +Dummy tables are needed by some databases to allow calling functions +or expressions that aren't based on table content, for examples of how +this applies to various database types, see: +L. + +Note: If you're using Oracles dual table don't B do anything +other than a select, if you CRUD on your dual table you *will* break +your database. + +Make a table class as you would for any other table + + package MyAppDB::Dual; + use strict; + use warnings; + use base 'DBIx::Class'; + __PACKAGE__->load_components("Core"); + __PACKAGE__->table("Dual"); + __PACKAGE__->add_columns( + "dummy", + { data_type => "VARCHAR2", is_nullable => 0, size => 1 }, + ); + +Once you've loaded your table class select from it using C conditions to illustrate the different syntax +you could use for doing stuff like +C + + # get a sequence value + select => [ 'A_SEQ.nextval' ], + + # get create table sql + select => [ { 'dbms_metadata.get_ddl' => [ "'TABLE'", "'ARTIST'" ]} ], + + # get a random num between 0 and 100 + select => [ { "trunc" => [ { "dbms_random.value" => [0,100] } ]} ], + + # what year is it? + select => [ { 'extract' => [ \'year from sysdate' ] } ], + + # do some math + select => [ {'round' => [{'cos' => [ \'180 * 3.14159265359/180' ]}]}], + + # which day of the week were you born on? + select => [{'to_char' => [{'to_date' => [ "'25-DEC-1980'", "'dd-mon-yyyy'" +]}, "'day'"]}], + + # select 16 rows from dual + select => [ "'hello'" ], + as => [ 'world' ], + group_by => [ 'cube( 1, 2, 3, 4 )' ], + + + =head2 Adding Indexes And Functions To Your SQL Often you will want indexes on columns on your table to speed up searching. To