Permalink
Browse files

start of work on ATOMIC

  • Loading branch information...
apocalypse committed Dec 11, 2008
1 parent 8be962d commit 1b37a83222600128ca985cb066d8bb617246cbe3
Showing with 85 additions and 8 deletions.
  1. +4 −0 Changes
  2. +2 −1 MANIFEST
  3. +76 −4 lib/POE/Component/SimpleDBI.pm
  4. +3 −3 lib/POE/Component/SimpleDBI/SubProcess.pm
View
@@ -1,5 +1,9 @@
Revision history for Perl extension POE::Component::SimpleDBI.
+* 1.23
+
+ Switched to Build.PL for the build system
+
* 1.22
Kwalitee-related fixes
View
@@ -1,4 +1,5 @@
-Makefile.PL
+Makefile.PL
+Build.PL
MANIFEST
MANIFEST.SKIP
README
@@ -2,9 +2,9 @@
package POE::Component::SimpleDBI;
use strict; use warnings;
-# Initialize our version $LastChangedRevision: 18 $
+# Initialize our version
use vars qw( $VERSION );
-$VERSION = '1.22';
+$VERSION = '1.23';
# Import what we need from the POE namespace
use POE; # For the constants
@@ -85,7 +85,8 @@ sub new {
'MULTIPLE' => \&DB_HANDLE,
'QUOTE' => \&DB_HANDLE,
'CONNECT' => \&DB_CONNECT,
- 'DISCONNECT' => \&DB_DISCONNECT,
+ 'DISCONNECT' => \&DB_DISCONNECT,
+ 'ATOMIC' => \&DB_ATOMIC,
# Queue stuff
'Check_Queue' => \&Check_Queue,
@@ -1566,7 +1567,78 @@ This is a simple boolean value, and if this argument does not exist, SimpleDBI w
'RESULT' => Array of hash of columns - similar to array of fetchrow_hashref's ( undef if no rows returned )
'PLACEHOLDERS' => Original placeholders ( may not exist if it was not provided )
'BAGGAGE' => whatever you set it to ( may not exist if it was not provided )
- }
+ }
+
+=head3 C<ATOMIC>
+
+ This query is specialized for those queries that you need to execute in a transaction. You supply an array of SQL queries,
+ and SimpleDBI will execute them all in a transaction block. No need to worry about AutoCommit, BEGIN, END TRANSACTION!
+
+ You are supposed to pass an array of queries that normally would be executed in a DO-style query. Again, you cannot execute
+ SELECT queries in this type of command! Currently there is no control over prepare_cached for individual queries. It may be
+ added in a future release.
+
+ Accepted arguments:
+ SESSION -> The session to send the results
+ EVENT -> The event to send the results
+ SQL -> The array of SQL queries
+ PLACEHOLDERS -> The array of placeholders ( if needed ) [ this is an AoA - array of arrays! ]
+ BAGGAGE -> Any extra data to keep associated with this query ( SimpleDBI will not touch it )
+ PREPARE_CACHED -> Boolean value ( if needed ) [ for all of the queries! ]
+
+ Internally, it does this:
+
+ eval {
+ $dbh->begin_work;
+ for my $idx ( 1 .. @#array ) {
+ if ( $global_prepare_cached ) {
+ $sth = $dbh->prepare_cached( $array[ $idx ] );
+ } else {
+ $sth = $dbh->prepare( $array[ $idx ] );
+ }
+ if ( defined $PLACEHOLDERS[ $idx ] ) {
+ $sth->execute( $PLACEHOLDERS[ $idx ] );
+ } else {
+ $sth->execute;
+ }
+ }
+ $dbh->commit;
+ };
+ if ( $@ ) {
+ eval { $dbh->rollback };
+ if ( $@ ) {
+ return ROLLBACK_FAILURE;
+ } else {
+ return COMMIT_FAILURE:
+ }
+ } else {
+ return SUCCESS;
+ }
+
+ Here's an example on how to trigger this event:
+ $_[KERNEL]->post( 'SimpleDBI', 'ATOMIC',
+ SQL => [
+ 'DELETE FROM FooTable WHERE ID = ?',
+ 'UPDATE FooTable SET baz = ? WHERE bar = ?',
+ ],
+ EVENT => 'atomic_handler',
+ PLACEHOLDERS => [ [ 53 ],
+ [ 5, 86 ]
+ ],
+ );
+
+ The Event handler will get a hash in ARG0:
+ {
+ 'ERROR' => exists only if an error occured
+ 'ACTION' => 'ATOMIC'
+ 'ID' => ID of the Query
+ 'EVENT' => The event the query will respond to
+ 'SESSION' => The session the query will respond to
+ 'SQL' => Original SQL inputted
+ 'RESULT' => Either: SUCCESS or ROLLBACK_FAILURE or COMMIT_FAILURE ( see above pseudocode )
+ 'PLACEHOLDERS' => Original placeholders ( may not exist if it was not provided )
+ 'BAGGAGE' => whatever you set it to ( may not exist if it was not provided )
+ }
=head3 C<Delete_Query>
@@ -3,8 +3,8 @@ package POE::Component::SimpleDBI::SubProcess;
use strict; use warnings;
# Initialize our version
-use vars qw( $VERSION );
-$VERSION = (qw$LastChangedRevision: 11 $)[1];
+use vars qw( $VERSION );
+$VERSION = '12';
# Use Error.pm's try/catch semantics
use Error qw( :try );
@@ -579,4 +579,4 @@ Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
-=cut
+=cut

0 comments on commit 1b37a83

Please sign in to comment.