# Copyright (c) 2007-2010 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: PropertySupport.bunit,v 1.7 2010/11/08 22:53:01 nagler Exp $ Unit(); options({comparator => 'nested_contains'}); my($table) = 't_support_t'; my($sequence) = 't_support_s'; my($id) = 't_support_id'; my($min_id) = '100099'; my($_S) = SQL_Connection(); Bivio_Die()->eval( sub {$_S->execute("drop table $table")}); Bivio_Die()->eval( sub {$_S->execute("drop sequence $sequence")}); $_S->commit; $_S->execute(<<"EOF"); create table $table ( $id NUMERIC(18) primary key, name VARCHAR(30), line VARCHAR(100), text VARCHAR(500), amount NUMERIC(20,7), boolean NUMERIC(1) CHECK (boolean BETWEEN 0 AND 1) NOT NULL, date_time DATE, dt DATE, tm DATE, gender NUMERIC(1) CHECK (gender BETWEEN 0 AND 2) NOT NULL ) EOF $_S->execute(<<"EOF"); create sequence $sequence minvalue $min_id increment by 100000 EOF # Can't see table until commit in Oracle $_S->commit; my($support); my($values) = sub { my($gender, $boolean) = @_; return [{ gender => ref($gender) ? [map(Type_Gender($_), @$gender)] : Type_Gender($gender), boolean => $boolean, }]; }; [ [{ version => 1, table_name => $table, columns => { $id => [qw(PrimaryId PRIMARY_KEY)], name => [qw(Name NONE)], line => [qw(Line NONE)], text => [qw(Text NONE)], amount => [qw(Amount NONE)], boolean => [qw(Boolean NOT_NULL)], date_time => [qw(DateTime NONE)], dt => [qw(Date NONE)], tm => [qw(Time NONE)], gender => [qw(Gender NOT_NULL)], }, }] => [ unsafe_load => [ [{$id => $min_id}] => [undef], ], create => [ map( ($values->(@$_) => not_die()), [qw(FEMALE 0)], [qw(MALE 0)], [qw(FEMALE 1)], [qw(MALE 1)], ), ], unsafe_load => [ map( ($values->(@$_) => $values->(@$_)), [qw(FEMALE 0)], [qw(MALE 0)], [qw(FEMALE 1)], [qw(MALE 1)], ), ], delete_all => [ $values->([qw(FEMALE MALE)], 0) => not_die(), ], unsafe_load => [ map( ($values->(@$_) => $_->[1] ? $values->(@$_) : [undef]), [qw(FEMALE 0)], [qw(MALE 0)], [qw(FEMALE 1)], [qw(MALE 1)], ), ], delete_all => [ [{}] => not_die(), ], unsafe_load => [ [{}] => [undef], ], delete_all => [ inline_case(sub { config({'Bivio::IO::Config' => {is_production => 1}}); return; }), [{}] => DIE(), ], new => [ [{ version => 1, table => $table, columns => { name => ['Name', 'NONE'], }, }] => qr{you must declare table_name}, ], iterate_start => [ ['Bivio::Die', undef, undef] => not_die(), ['Bivio::Die', 'gender ASC', undef] => not_die(), ['Bivio::Die', 'gender ASC', {gender => Type_Gender('MALE')}] => not_die(), ], ], ];