[Bast-commits] r3743 - in
DBIx-Class/0.08/branches/versioned_enhancements: . lib/DBIx
lib/DBIx/Class lib/DBIx/Class/Manual
lib/DBIx/Class/ResultClass lib/DBIx/Class/ResultSourceProxy
lib/DBIx/Class/Storage lib/DBIx/Class/Storage/DBI
lib/DBIx/Class/Storage/DBI/ODBC
lib/DBIx/Class/Storage/DBI/Oracle t t/cdbi-t t/lib
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Fri Sep 14 21:56:27 GMT 2007
Author: matthewt
Date: 2007-09-14 21:56:27 +0100 (Fri, 14 Sep 2007)
New Revision: 3743
Added:
DBIx-Class/0.08/branches/versioned_enhancements/t/73oracle_inflate.t
DBIx-Class/0.08/branches/versioned_enhancements/t/92storage_on_connect_do.t
Modified:
DBIx-Class/0.08/branches/versioned_enhancements/
DBIx-Class/0.08/branches/versioned_enhancements/Changes
DBIx-Class/0.08/branches/versioned_enhancements/Makefile.PL
DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class.pm
DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Manual/FAQ.pod
DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/PK.pm
DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Relationship.pm
DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultClass/HashRefInflator.pm
DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultSet.pm
DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultSource.pm
DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultSourceProxy/Table.pm
DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Schema.pm
DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI.pm
DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI/ODBC.pm
DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI/ODBC/DB2_400_SQL.pm
DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm
DBIx-Class/0.08/branches/versioned_enhancements/t/60core.t
DBIx-Class/0.08/branches/versioned_enhancements/t/cdbi-t/11-triggers.t
DBIx-Class/0.08/branches/versioned_enhancements/t/lib/DBICTest.pm
Log:
r11158 at jules (orig r3684): jnapiorkowski | 2007-08-16 16:23:18 +0100
-- added some documentation to ->populate to warn people about the side effects of using wantarray versus void context.
-- added some additional documentation to resultset->create
r11194 at jules (orig r3695): matthewt | 2007-08-21 19:24:53 +0100
r10460 at jules (orig r3640): tomboh | 2007-08-01 12:27:38 +0100
Add an 'on_disconnect_do' argument to
DBIx::Class::Storage::DBI::connect_info that, on disconnection, do what
'on_connect_do' does on connection. Currently, this only works if the
code explicitly calls disconnect() on the Storage object.
While I'm here, make both 'on_connect_do' and 'on_disconnect_do' accept
code references as well as strings containing SQL statements.
Finally, remove code to call compose_connection() from DBICTest.pm that
never gets called any more.
r11195 at jules (orig r3696): matthewt | 2007-08-21 19:24:57 +0100
r11152 at jules (orig r3678): tomboh | 2007-08-15 09:24:32 +0100
Restore code that I removed in revision 3640 that tests still need
r11196 at jules (orig r3697): matthewt | 2007-08-21 19:25:00 +0100
r11153 at jules (orig r3679): tomboh | 2007-08-15 09:25:47 +0100
Let on_connect_do() and on_disconnect_do() take code references.
Provide tests and documentation for this.
r11197 at jules (orig r3698): matthewt | 2007-08-21 19:25:33 +0100
r11199 at jules (orig r3700): matthewt | 2007-08-21 19:50:00 +0100
arrayrefs for on_connect_do
r11200 at jules (orig r3701): matthewt | 2007-08-21 19:53:44 +0100
note on_connect_do changes
r11201 at jules (orig r3702): matthewt | 2007-08-21 20:17:22 +0100
oracle datetime inflator patch
r11202 at jules (orig r3703): matthewt | 2007-08-21 20:52:09 +0100
force CDBICompat deps for developers, fix tests to work with latest Class::Trigger
r11217 at jules (orig r3705): tomboh | 2007-08-22 11:28:58 +0100
Fix the behaviour of code refs within array refs for on_(dis)?connect_do
and enhance tests to spot the previous mistake.
r11218 at jules (orig r3706): tomboh | 2007-08-22 11:57:14 +0100
Add myself to the list of contributors
r11232 at jules (orig r3709): gphat | 2007-08-24 18:11:46 +0100
Fix typos.
r14025 at jules (orig r3720): ilmari | 2007-09-04 17:44:41 +0100
Fix return value for DBIC::ResultSource::Table->table($table)
r14026 at jules (orig r3721): ash | 2007-09-04 20:14:02 +0100
Bump for New relase
r14027 at jules (orig r3722): semifor | 2007-09-05 04:49:46 +0100
r1185 at titanic: mjm | 2007-09-04 20:11:07 -0700
Updated email address
r14029 at jules (orig r3723): castaway | 2007-09-06 21:07:52 +0100
Doc patch from wreis
r14030 at jules (orig r3724): castaway | 2007-09-06 22:35:49 +0100
Add more about accessors to doc
r14031 at jules (orig r3725): tomboh | 2007-09-07 17:54:00 +0100
Small POD fix
r14032 at jules (orig r3726): semifor | 2007-09-08 17:58:56 +0100
r1191 at titanic: mjm | 2007-09-08 09:20:32 -0700
discard_changes is also "refresh from storage"
r14035 at jules (orig r3729): castaway | 2007-09-12 00:23:20 +0100
Much doch shuffling and more argument explanations (due to initself ;)
Property changes on: DBIx-Class/0.08/branches/versioned_enhancements
___________________________________________________________________
Name: svk:merge
- 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-current:2222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
+ 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/on_disconnect_do:3694
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/trunk:3729
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-current:2222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
Modified: DBIx-Class/0.08/branches/versioned_enhancements/Changes
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/Changes 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/Changes 2007-09-14 20:56:27 UTC (rev 3743)
@@ -1,5 +1,10 @@
Revision history for DBIx::Class
+0.08007 2007-09-04 19:36:00
+ - patch for Oracle datetime inflation (abram at arin.net)
+ - added on_disconnect_do
+ - on_connect_do and on_disconnect_do take coderefs and arrayrefs
+
0.08006 2007-08-12 15:12:00
- Move to using Class::C3::Componentised
- Remove warn statement from DBIx::Class::Row
Modified: DBIx-Class/0.08/branches/versioned_enhancements/Makefile.PL
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/Makefile.PL 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/Makefile.PL 2007-09-14 20:56:27 UTC (rev 3743)
@@ -29,9 +29,11 @@
tests "t/*.t t/*/*.t";
-# re-build README if we're in an svk checkout
-if( -e 'MANIFEST.SKIP' ) {
- system('pod2text lib/DBIx/Class.pm > README');
+# re-build README and require CDBI modules for testing if we're in a checkout
+if( -e 'inc/.author' ) {
+ build_requires 'DBIx::ContextualFetch';
+ build_requires 'Class::Trigger';
+ system('pod2text lib/DBIx/Class.pm > README');
}
auto_provides;
Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Manual/FAQ.pod
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Manual/FAQ.pod 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Manual/FAQ.pod 2007-09-14 20:56:27 UTC (rev 3743)
@@ -285,6 +285,18 @@
If supported by the database, slice will use LIMIT/OFFSET to hint to the database that we
really only need one row. This can result in a significant speed improvement.
+=item .. refresh a row from storage?
+
+Use L<DBIx::Class::PK/discard_changes>.
+
+ $row->discard_changes
+
+Discarding changes and refreshing from storage are two sides fo the same coin. When you
+want to discard your local changes, just re-fetch the row from storage. When you want
+to get a new, fresh copy of the row, just re-fetch the row from storage.
+L<DBIx::Class::PK/discard_changes> does just that by re-fetching the row from storage
+using the row's primary key.
+
=back
=head2 Inserting and updating data
@@ -398,6 +410,6 @@
particular column or group of columns (a-la cdbi Stringfy column
group, or stringify_self method) ?
-See L<Cookbook/Stringification>
+See L<DBIx::Class::Manual::Cookbook/Stringification>
=back
Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/PK.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/PK.pm 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/PK.pm 2007-09-14 20:56:27 UTC (rev 3743)
@@ -30,6 +30,9 @@
Re-selects the row from the database, losing any changes that had
been made.
+This method can also be used to refresh from storage, retrieving any
+changes made since the row was last read from storage.
+
=cut
sub discard_changes {
Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Relationship.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Relationship.pm 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Relationship.pm 2007-09-14 20:56:27 UTC (rev 3743)
@@ -115,6 +115,44 @@
=back
+Creates a relationship where the calling class stores the foreign class's
+primary key in one (or more) of its columns. This relationship defaults to
+using C<$accessor_name> as the foreign key in C<$related_class> to resolve the
+join, unless C<$foreign_key_column> specifies the foreign key column in
+C<$related_class> or C<$cond> specifies a reference to a join condition hash.
+
+=over
+
+=item accessor_name
+
+This argument is the name of the method you can call on a
+L<DBIx::Class::Row> object to retrieve the instance of the foreign
+class matching this relationship.
+
+Use this accessor_name (relation name) in L<DBIx::Class::ResultSet/join>
+or L<DBIx::Class::ResultSet/prefetch> to join to the foreign table
+indicated by this relationship.
+
+=item related_class
+
+This is the class name of the table referenced by the foreign key in
+this class.
+
+=item foreign_key_column
+
+The column name on this class that contains the foreign key.
+
+OR
+
+=item cond
+
+A hashref where the keys are C<foreign.$column_on_related_table> and
+the values are C<self.$foreign_key_column>. This is useful for
+relations that are across multiple columns.
+
+=back
+
+
# in a Book class (where Author has many Books)
My::DBIC::Schema::Book->belongs_to( author => 'My::DBIC::Schema::Author' );
@@ -127,12 +165,6 @@
'My::DBIC::Schema::Author',
{ 'foreign.author' => 'self.author' } );
-Creates a relationship where the calling class stores the foreign class's
-primary key in one (or more) of its columns. This relationship defaults to
-using C<$accessor_name> as the foreign key in C<$related_class> to resolve the
-join, unless C<$foreign_key_column> specifies the foreign key column in
-C<$related_class> or C<$cond> specifies a reference to a join condition hash.
-
If the relationship is optional -- i.e. the column containing the foreign key
can be NULL -- then the belongs_to relationship does the right thing. Thus, in
the example above C<$obj-E<gt>author> would return C<undef>. However in this
@@ -163,6 +195,45 @@
=back
+Creates a one-to-many relationship, where the corresponding elements of the
+foreign class store the calling class's primary key in one (or more) of its
+columns. This relationship defaults to using C<$accessor_name> as the foreign
+key in C<$related_class> to resolve the join, unless C<$foreign_key_column>
+specifies the foreign key column in C<$related_class> or C<$cond> specifies a
+reference to a join condition hash.
+
+=over
+
+=item accessor_name
+
+This argument is the name of the method you can call on a
+L<DBIx::Class::Row> object to retrieve a resultset of the related
+class restricted to the ones related to the row object. In list
+context it returns the row objects.
+
+Use this accessor_name (relation name) in L<DBIx::Class::ResultSet/join>
+or L<DBIx::Class::ResultSet/prefetch> to join to the foreign table
+indicated by this relationship.
+
+=item related_class
+
+This is the class name of the table which contains a foreign key
+column containing PK values of this class.
+
+=item foreign_key_column
+
+The column name on the related class that contains the foreign key.
+
+OR
+
+=item cond
+
+A hashref where the keys are C<foreign.$column_on_related_table> and
+the values are C<self.$foreign_key_column>. This is useful for
+relations that are across multiple columns.
+
+=back
+
# in an Author class (where Author has_many Books)
My::DBIC::Schema::Author->has_many(books => 'My::DBIC::Schema::Book', 'author');
@@ -184,13 +255,6 @@
'foreign.author' => 'self.author',
});
-Creates a one-to-many relationship, where the corresponding elements of the
-foreign class store the calling class's primary key in one (or more) of its
-columns. This relationship defaults to using C<$accessor_name> as the foreign
-key in C<$related_class> to resolve the join, unless C<$foreign_key_column>
-specifies the foreign key column in C<$related_class> or C<$cond> specifies a
-reference to a join condition hash.
-
Three methods are created when you create a has_many relationship. The first
method is the expected accessor method, C<$accessor_name()>. The second is
almost exactly the same as the accessor method but "_rs" is added to the end of
@@ -217,6 +281,43 @@
=back
+Creates an optional one-to-one relationship with a class. This relationship
+defaults to using C<$accessor_name> as the foreign key in C<$related_class> to
+resolve the join, unless C<$foreign_key_column> specifies the foreign key
+column in C<$related_class> or C<$cond> specifies a reference to a join
+condition hash.
+
+=over
+
+=item accessor_name
+
+This argument is the name of the method you can call on a
+L<DBIx::Class::Row> object to retrieve the instance of the foreign
+class matching this relationship.
+
+Use this accessor_name (relation name) in L<DBIx::Class::ResultSet/join>
+or L<DBIx::Class::ResultSet/prefetch> to join to the foreign table
+indicated by this relationship.
+
+=item related_class
+
+This is the class name of the table which contains a foreign key
+column containing PK values of this class.
+
+=item foreign_key_column
+
+The column name on the related class that contains the foreign key.
+
+OR
+
+=item cond
+
+A hashref where the keys are C<foreign.$column_on_related_table> and
+the values are C<self.$foreign_key_column>. This is useful for
+relations that are across multiple columns.
+
+=back
+
My::DBIC::Schema::Author->might_have( pseudonym =>
'My::DBIC::Schema::Pseudonym' );
@@ -234,14 +335,6 @@
'My::DBIC::Schema::Pseudonym',
{ 'foreign.author' => 'self.author' } );
-Assuming the Pseudonym table has
-
-Creates an optional one-to-one relationship with a class. This relationship
-defaults to using C<$accessor_name> as the foreign key in C<$related_class> to
-resolve the join, unless C<$foreign_key_column> specifies the foreign key
-column in C<$related_class> or C<$cond> specifies a reference to a join
-condition hash.
-
If you update or delete an object in a class with a C<might_have>
relationship, the related object will be updated or deleted as well. To
turn off this behavior, add C<< cascade_delete => 0 >> to the C<$attr>
@@ -287,6 +380,37 @@
=back
+C<many_to_many> is not strictly a relationship in its own right. Instead, it is
+a bridge between two resultsets which provide the same kind of convenience
+accessors as true relationships provide. Although the accessor will return a
+resultset or collection of objects just like has_many does, you cannot call
+C<related_resultset> and similar methods which operate on true relationships.
+
+=over
+
+=item accessor_name
+
+This argument is the name of the method you can call on a
+L<DBIx::Class::Row> object to retrieve the rows matching this
+relationship.
+
+On a many_to_many, unlike other relationships, this cannot be used in
+L<DBIx::Class::ResultSet/search> to join tables. Use the relations
+bridged across instead.
+
+=item link_rel_name
+
+This is the accessor_name from the has_many relationship we are
+bridging from.
+
+=item foreign_rel_name
+
+This is the accessor_name of the belongs_to relationship in the link
+table that we are bridging across (which gives us the table we are
+bridging to).
+
+=back
+
To create a many_to_many relationship from Actor to Role:
My::DBIC::Schema::Actor->has_many( actor_roles =>
@@ -313,12 +437,6 @@
$actor->add_to_roles($role, { year => 1995 });
-Many_to_many is not strictly a relationship in its own right. Instead, it is
-a bridge between two resultsets which provide the same kind of convenience
-accessors as true relationships provide. Although the accessor will return a
-resultset or collection of objects just like has_many does, you cannot call
-C<$related_resultset> and similar methods which operate on true relationships.
-
In the above example, ActorRoles is the link table class, and Role is the
foreign class. The C<$link_rel_name> parameter is the name of the accessor for
the has_many relationship from this table to the link table, and the
Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultClass/HashRefInflator.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultClass/HashRefInflator.pm 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultClass/HashRefInflator.pm 2007-09-14 20:56:27 UTC (rev 3743)
@@ -23,13 +23,13 @@
=item *
Specify C<< $rs->result_class >> on a specific resultset to affect only that
-resultser (and any chained off of it); or
+resultset (and any chained off of it); or
=item *
Specify C<< __PACKAGE__->result_class >> on your source object to force all
uses of that result source to be inflated to hash-refs - this approach is not
-recomended
+recommended.
=back
Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultSet.pm 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultSet.pm 2007-09-14 20:56:27 UTC (rev 3743)
@@ -1251,7 +1251,7 @@
submitting to a $resultset->create(...) method.
In void context, C<insert_bulk> in L<DBIx::Class::Storage::DBI> is used
-to insert the data, as this is a faster method.
+to insert the data, as this is a faster method.
Otherwise, each set of data is inserted into the database using
L<DBIx::Class::ResultSet/create>, and a arrayref of the resulting row
@@ -1288,6 +1288,14 @@
print $ArtistOne->name; ## response is 'Artist One'
print $ArtistThree->cds->count ## reponse is '2'
+
+Please note an important effect on your data when choosing between void and
+wantarray context. Since void context goes straight to C<insert_bulk> in
+L<DBIx::Class::Storage::DBI> this will skip any component that is overriding
+c<insert>. So if you are using something like L<DBIx-Class-UUIDColumns> to
+create primary keys for you, you will find that your PKs are empty. In this
+case you will have to use the wantarray context in order to create those
+values.
=cut
@@ -1569,6 +1577,16 @@
Effectively a shortcut for C<< ->new_result(\%vals)->insert >>.
+Example of creating a new row.
+
+ $person_rs->create({
+ name=>"Some Person",
+ email=>"somebody at someplace.com"
+ });
+
+Example of creating a new row and also creating rows in a related C<has_many>
+or C<has_one> resultset. Note Arrayref.
+
$artist_rs->create(
{ artistid => 4, name => 'Manufactured Crap', cds => [
{ title => 'My First CD', year => 2006 },
@@ -1577,6 +1595,17 @@
},
);
+Example of creating a new row and also creating a row in a related
+C<belongs_to>resultset. Note Hashref.
+
+ $cd_rs->create({
+ title=>"Music for Silly Walks",
+ year=>2000,
+ artist => {
+ name=>"Silly Musician",
+ }
+ });
+
=cut
sub create {
@@ -2180,11 +2209,10 @@
=back
-Indicates column names for object inflation. That is, c< as >
+Indicates column names for object inflation. That is, C<as>
indicates the name that the column can be accessed as via the
C<get_column> method (or via the object accessor, B<if one already
-exists>). It has nothing to do with the SQL code C< SELECT foo AS bar
->.
+exists>). It has nothing to do with the SQL code C<SELECT foo AS bar>.
The C<as> attribute is used in conjunction with C<select>,
usually when C<select> contains one or more function or stored
Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultSource.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultSource.pm 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultSource.pm 2007-09-14 20:56:27 UTC (rev 3743)
@@ -81,6 +81,10 @@
the hashref as the column_info for that column. Repeated calls of this
method will add more columns, not replace them.
+The column names given will be created as accessor methods on your
+L<DBIx::Class::Row> objects, you can change the name of the accessor
+by supplying an L</accessor> in the column_info hash.
+
The contents of the column_info are not set in stone. The following
keys are currently recognised/used by DBIx::Class:
@@ -88,7 +92,7 @@
=item accessor
-Use this to set the name of the accessor for this column. If unset,
+Use this to set the name of the accessor method for this column. If unset,
the name of the column will be used.
=item data_type
Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultSourceProxy/Table.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultSourceProxy/Table.pm 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/ResultSourceProxy/Table.pm 2007-09-14 20:56:27 UTC (rev 3743)
@@ -63,6 +63,7 @@
$class =~ m/([^:]+)$/;
$class->schema_instance->register_class($class, $class);
}
+ return $class->result_source_instance->name;
}
=head2 has_column
Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Schema.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Schema.pm 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Schema.pm 2007-09-14 20:56:27 UTC (rev 3743)
@@ -836,7 +836,19 @@
[ 2, 'Indie Band' ],
...
]);
+
+Since wantarray context is basically the same as looping over $rs->create(...)
+you won't see any performance benefits and in this case the method is more for
+convenience. Void context sends the column information directly to storage
+using <DBI>s bulk insert method. So the performance will be much better for
+storages that support this method.
+Because of this difference in the way void context inserts rows into your
+database you need to note how this will effect any loaded components that
+override or augment insert. For example if you are using a component such
+as L<DBIx::Class::UUIDColumns> to populate your primary keys you MUST use
+wantarray context if you want the PKs automatically created.
+
=cut
sub populate {
Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI/ODBC/DB2_400_SQL.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI/ODBC/DB2_400_SQL.pm 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI/ODBC/DB2_400_SQL.pm 2007-09-14 20:56:27 UTC (rev 3743)
@@ -56,7 +56,7 @@
=head1 AUTHORS
-Marc Mims C<< <marc at sssonline.com> >>
+Marc Mims C<< <marc at questright.com> >>
Based on DBIx::Class::Storage::DBI::DB2 by Jess Robinson.
Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI/ODBC.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI/ODBC.pm 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI/ODBC.pm 2007-09-14 20:56:27 UTC (rev 3743)
@@ -39,7 +39,7 @@
=head1 AUTHORS
-Marc Mims C<< <marc at sssonline.com> >>
+Marc Mims C<< <marc at questright.com> >>
=head1 LICENSE
Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm 2007-09-14 20:56:27 UTC (rev 3743)
@@ -84,6 +84,15 @@
$self->next::method(uc($table));
}
+=head2 datetime_parser_type
+
+This sets the proper DateTime::Format module for use with
+L<DBIx::Class::InflateColumn::DateTime>.
+
+=cut
+
+sub datetime_parser_type { return "DateTime::Format::Oracle"; }
+
=head1 AUTHORS
Andy Grundman <andy at hybridized.org>
Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI.pm 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Storage/DBI.pm 2007-09-14 20:56:27 UTC (rev 3743)
@@ -14,7 +14,7 @@
__PACKAGE__->mk_group_accessors('simple' =>
qw/_connect_info _dbi_connect_info _dbh _sql_maker _sql_maker_opts
_conn_pid _conn_tid disable_sth_caching on_connect_do
- transaction_depth unsafe _dbh_autocommit/
+ on_disconnect_do transaction_depth unsafe _dbh_autocommit/
);
__PACKAGE__->cursor_class('DBIx::Class::Storage::DBI::Cursor');
@@ -347,10 +347,31 @@
=item on_connect_do
-This can be set to an arrayref of literal sql statements, which will
-be executed immediately after making the connection to the database
-every time we [re-]connect.
+Specifies things to do immediately after connecting or re-connecting to
+the database. Its value may contain:
+=over
+
+=item an array reference
+
+This contains SQL statements to execute in order. Each element contains
+a string or a code reference that returns a string.
+
+=item a code reference
+
+This contains some code to execute. Unlike code references within an
+array reference, its return value is ignored.
+
+=back
+
+=item on_disconnect_do
+
+Takes arguments in the same form as L<on_connect_do> and executes them
+immediately before disconnecting from the database.
+
+Note, this only runs if you explicitly call L<disconnect> on the
+storage object.
+
=item disable_sth_caching
If set to a true value, this option will disable the caching of
@@ -481,9 +502,10 @@
my $last_info = $dbi_info->[-1];
if(ref $last_info eq 'HASH') {
$last_info = { %$last_info }; # so delete is non-destructive
- for my $storage_opt (
- qw/on_connect_do disable_sth_caching unsafe cursor_class/
- ) {
+ my @storage_option = qw(
+ on_connect_do on_disconnect_do disable_sth_caching unsafe cursor_class
+ );
+ for my $storage_opt (@storage_option) {
if(my $value = delete $last_info->{$storage_opt}) {
$self->$storage_opt($value);
}
@@ -650,6 +672,9 @@
my ($self) = @_;
if( $self->connected ) {
+ my $connection_do = $self->on_disconnect_do;
+ $self->_do_connection_actions($connection_do) if ref($connection_do);
+
$self->_dbh->rollback unless $self->_dbh_autocommit;
$self->_dbh->disconnect;
$self->_dbh(undef);
@@ -742,17 +767,44 @@
}
}
- # if on-connect sql statements are given execute them
- foreach my $sql_statement (@{$self->on_connect_do || []}) {
- $self->_query_start($sql_statement);
- $self->_dbh->do($sql_statement);
- $self->_query_end($sql_statement);
- }
+ my $connection_do = $self->on_connect_do;
+ $self->_do_connection_actions($connection_do) if ref($connection_do);
$self->_conn_pid($$);
$self->_conn_tid(threads->tid) if $INC{'threads.pm'};
}
+sub _do_connection_actions {
+ my $self = shift;
+ my $connection_do = shift;
+
+ if (ref $connection_do eq 'ARRAY') {
+ $self->_do_query($_) foreach @$connection_do;
+ }
+ elsif (ref $connection_do eq 'CODE') {
+ $connection_do->();
+ }
+
+ return $self;
+}
+
+sub _do_query {
+ my ($self, $action) = @_;
+
+ if (ref $action eq 'CODE') {
+ $action = $action->($self);
+ $self->_do_query($_) foreach @$action;
+ }
+ else {
+ my @to_run = (ref $action eq 'ARRAY') ? (@$action) : ($action);
+ $self->_query_start(@to_run);
+ $self->_dbh->do(@to_run);
+ $self->_query_end(@to_run);
+ }
+
+ return $self;
+}
+
sub _connect {
my ($self, @info) = @_;
Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class.pm 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class.pm 2007-09-14 20:56:27 UTC (rev 3743)
@@ -23,7 +23,7 @@
# i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports
# brain damage and presumably various other packaging systems too
-$VERSION = '0.08006';
+$VERSION = '0.08007';
sub MODIFY_CODE_ATTRIBUTES {
my ($class,$code, at attrs) = @_;
@@ -265,6 +265,8 @@
Todd Lipcon
+Tom Hukins
+
typester: Daisuke Murase <typester at cpan.org>
victori: Victor Igumnov <victori at cpan.org>
Modified: DBIx-Class/0.08/branches/versioned_enhancements/t/60core.t
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/t/60core.t 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/t/60core.t 2007-09-14 20:56:27 UTC (rev 3743)
@@ -7,7 +7,7 @@
my $schema = DBICTest->init_schema();
-plan tests => 77;
+plan tests => 78;
eval { require DateTime::Format::MySQL };
my $NO_DTFM = $@ ? 1 : 0;
@@ -337,3 +337,10 @@
is($edata{'created_on'}, $event->created_on, 'got created date');
}
+# test resultsource->table return value when setting
+{
+ my $class = $schema->class('Event');
+ diag $class;
+ my $table = $class->table($class->table);
+ is($table, $class->table, '->table($table) returns $table');
+}
Added: DBIx-Class/0.08/branches/versioned_enhancements/t/73oracle_inflate.t
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/t/73oracle_inflate.t (rev 0)
+++ DBIx-Class/0.08/branches/versioned_enhancements/t/73oracle_inflate.t 2007-09-14 20:56:27 UTC (rev 3743)
@@ -0,0 +1,64 @@
+use strict;
+use warnings;
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+
+my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
+
+eval "use DateTime; use DateTime::Format::Oracle;";
+if ($@) {
+ plan skip_all => 'needs DateTime and DateTime::Format::Oracle for testing';
+}
+elsif (not ($dsn && $user && $pass)) {
+ plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' .
+ 'Warning: This test drops and creates a table called \'track\'';
+}
+else {
+ plan tests => 4;
+}
+
+# DateTime::Format::Oracle needs this set
+$ENV{NLS_DATE_FORMAT} = 'DD-MON-YY';
+
+my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
+
+# Need to redefine the last_updated_on column
+my $col_metadata = $schema->class('Track')->column_info('last_updated_on');
+$schema->class('Track')->add_column( 'last_updated_on' => {
+ data_type => 'date' });
+
+my $dbh = $schema->storage->dbh;
+
+eval {
+ $dbh->do("DROP TABLE track");
+};
+$dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255), last_updated_on DATE)");
+
+# insert a row to play with
+my $new = $schema->resultset('Track')->create({ trackid => 1, cd => 1, position => 1, title => 'Track1', last_updated_on => '06-MAY-07' });
+is($new->trackid, 1, "insert sucessful");
+
+my $track = $schema->resultset('Track')->find( 1 );
+
+is( ref($track->last_updated_on), 'DateTime', "last_updated_on inflated ok");
+
+is( $track->last_updated_on->month, 5, "DateTime methods work on inflated column");
+
+my $dt = DateTime->now();
+$track->last_updated_on($dt);
+$track->update;
+
+is( $track->last_updated_on->month, $dt->month, "deflate ok");
+
+# clean up our mess
+END {
+ # Set the metadata back for the last_updated_on column
+ $schema->class('Track')->add_column( 'last_updated_on' => $col_metadata );
+
+ if($dbh) {
+ $dbh->do("DROP TABLE track");
+ }
+}
+
Added: DBIx-Class/0.08/branches/versioned_enhancements/t/92storage_on_connect_do.t
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/t/92storage_on_connect_do.t (rev 0)
+++ DBIx-Class/0.08/branches/versioned_enhancements/t/92storage_on_connect_do.t 2007-09-14 20:56:27 UTC (rev 3743)
@@ -0,0 +1,70 @@
+use strict;
+use warnings;
+
+use Test::More tests => 9;
+
+use lib qw(t/lib);
+use base 'DBICTest';
+
+
+my $schema = DBICTest->init_schema(
+ no_connect => 1,
+ no_deploy => 1,
+);
+ok $schema->connection(
+ DBICTest->_database,
+ {
+ on_connect_do => [
+ 'CREATE TABLE TEST_empty (id INTEGER)',
+ [ 'INSERT INTO TEST_empty VALUES (?)', {}, 2 ],
+ \&insert_from_subref,
+ ],
+ on_disconnect_do =>
+ [\&check_exists, 'DROP TABLE TEST_empty', \&check_dropped],
+ },
+), 'connection()';
+
+is_deeply
+ $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
+ [ [ 2 ], [ 3 ], [ 7 ] ],
+ 'on_connect_do() worked';
+eval { $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent'); };
+ok $@, 'Searching for nonexistent table dies';
+
+$schema->storage->disconnect();
+
+my($connected, $disconnected);
+ok $schema->connection(
+ DBICTest->_database,
+ {
+ on_connect_do => sub { $connected = 1 },
+ on_disconnect_do => sub { $disconnected = 1 },
+ },
+), 'second connection()';
+$schema->storage->dbh->do('SELECT 1');
+ok $connected, 'on_connect_do() called after connect()';
+ok ! $disconnected, 'on_disconnect_do() not called after connect()';
+$schema->storage->disconnect();
+ok $disconnected, 'on_disconnect_do() called after disconnect()';
+
+
+sub check_exists {
+ my $storage = shift;
+ ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists';
+ return;
+}
+
+sub check_dropped {
+ my $storage = shift;
+ eval { $storage->dbh->do('SELECT 1 FROM TEST_empty'); };
+ ok $@, 'Reading from dropped table fails';
+ return;
+}
+
+sub insert_from_subref {
+ my $storage = shift;
+ return [
+ [ 'INSERT INTO TEST_empty VALUES (?)', {}, 3 ],
+ 'INSERT INTO TEST_empty VALUES (7)',
+ ];
+}
Modified: DBIx-Class/0.08/branches/versioned_enhancements/t/cdbi-t/11-triggers.t
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/t/cdbi-t/11-triggers.t 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/t/cdbi-t/11-triggers.t 2007-09-14 20:56:27 UTC (rev 3743)
@@ -25,13 +25,11 @@
sub default_rating { $_[0]->Rating(15); }
-Film->add_trigger(
- before_create => \&default_rating,
- after_create => \&create_trigger2,
- after_delete => \&delete_trigger,
- before_update => \&pre_up_trigger,
- after_update => \&pst_up_trigger,
-);
+Film->add_trigger(before_create => \&default_rating);
+Film->add_trigger(after_create => \&create_trigger2);
+Film->add_trigger(after_delete => \&delete_trigger);
+Film->add_trigger(before_update => \&pre_up_trigger);
+Film->add_trigger(after_update => \&pst_up_trigger);
ok(
my $ver = Film->create({
Modified: DBIx-Class/0.08/branches/versioned_enhancements/t/lib/DBICTest.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/t/lib/DBICTest.pm 2007-09-14 20:56:15 UTC (rev 3742)
+++ DBIx-Class/0.08/branches/versioned_enhancements/t/lib/DBICTest.pm 2007-09-14 20:56:27 UTC (rev 3743)
@@ -42,9 +42,8 @@
=cut
-sub init_schema {
+sub _database {
my $self = shift;
- my %args = @_;
my $db_file = "t/var/DBIxClass.db";
unlink($db_file) if -e $db_file;
@@ -55,19 +54,28 @@
my $dbuser = $ENV{"DBICTEST_DBUSER"} || '';
my $dbpass = $ENV{"DBICTEST_DBPASS"} || '';
+ my @connect_info = ($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
+
+ return @connect_info;
+}
+
+sub init_schema {
+ my $self = shift;
+ my %args = @_;
+
my $schema;
- my @connect_info = ($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
-
if ($args{compose_connection}) {
$schema = DBICTest::Schema->compose_connection(
- 'DBICTest', @connect_info
+ 'DBICTest', $self->_database
);
} else {
- $schema = DBICTest::Schema->compose_namespace('DBICTest')
- ->connect(@connect_info);
+ $schema = DBICTest::Schema->compose_namespace('DBICTest');
}
- $schema->storage->on_connect_do(['PRAGMA synchronous = OFF']);
+ if ( !$args{no_connect} ) {
+ $schema = $schema->connect($self->_database);
+ $schema->storage->on_connect_do(['PRAGMA synchronous = OFF']);
+ }
if ( !$args{no_deploy} ) {
__PACKAGE__->deploy_schema( $schema );
__PACKAGE__->populate_schema( $schema ) if( !$args{no_populate} );
More information about the Bast-commits
mailing list