summaryrefslogtreecommitdiff
path: root/fml/lib/IO
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-08-05 12:07:22 +0000
committerfukachan <fukachan>2001-08-05 12:07:22 +0000
commit954837609d32b1441a7ac8042e8bf639bfe329ee (patch)
tree5f68f7ff35d2ecd07a34c455e4625fbcaa63c88f /fml/lib/IO
parent63e18eb96c1e4c77f2b578036d072db68f372359 (diff)
downloadfml8-954837609d32b1441a7ac8042e8bf639bfe329ee.tar.gz
fml8-954837609d32b1441a7ac8042e8bf639bfe329ee.tar.bz2
fml8-954837609d32b1441a7ac8042e8bf639bfe329ee.zip
move main functions to IO::Adapter::SQL::toymodel
define fetch_and_cache_address_list() to fetch and cache the array of address list. The main part of get_next_value().
Diffstat (limited to 'fml/lib/IO')
-rw-r--r--fml/lib/IO/Adapter/MySQL.pm67
-rw-r--r--fml/lib/IO/Adapter/SQL/toymodel.pm66
2 files changed, 62 insertions, 71 deletions
diff --git a/fml/lib/IO/Adapter/MySQL.pm b/fml/lib/IO/Adapter/MySQL.pm
index 9ac00c96..e425917f 100644
--- a/fml/lib/IO/Adapter/MySQL.pm
+++ b/fml/lib/IO/Adapter/MySQL.pm
@@ -3,7 +3,7 @@
# Copyright (C) 2000,2001 Ken'ichi Fukamachi
# All rights reserved.
#
-# $FML: MySQL.pm,v 1.13 2001/06/17 08:57:10 fukachan Exp $
+# $FML: MySQL.pm,v 1.14 2001/08/05 03:24:44 fukachan Exp $
#
@@ -95,9 +95,12 @@ sub configure
# $self->{ _driver } is the $config->{ driver } object.
unless ($@) {
- print STDERR "load $pkg\n" if $ENV{ 'debug' };
+ printf STDERR "%-20s %s\n", "loading", $pkg if $ENV{'debug'};
+
@ISA = ($pkg, @ISA);
$me->{ _driver } = $pkg;
+
+ printf STDERR "%-20s %s\n", "MySQL::ISA:", "@ISA" if $ENV{'debug'};
}
else {
error_set($self, $@);
@@ -131,14 +134,11 @@ sub get_next_value
# for the first time
unless ($self->{ _res }) {
# $self->{ _driver } is the $config->{ driver } object.
- if ( $self->{ _driver }->can('get_next_value') ) {
- $self->{ _driver }->get_next_value($args);
+ if ( $self->can('fetch_and_cache_address_list') ) {
+ $self->fetch_and_cache_address_list($args);
}
else {
- my $query = $self->build_sql_query({
- query => 'get_next_value',
- });
- $self->execute({ query => $query });
+ croak "cannot get next value\n";
}
}
@@ -153,57 +153,6 @@ sub get_next_value
}
-=head2 C<add($addr)>
-
-add C<$addr> to the sql server specified at new().
-IO::Adapter::SQL::$model provides model specific SQL query statement.
-If IO::Adapter::SQL::add() exists, IO::Adapter::SQL::add() is called.
-
-=head2 C<delete($addr)>
-
-delete C<$addr> from the sql server specified at new().
-IO::Adapter::SQL::$model provides model specific SQL query statement.
-If IO::Adapter::SQL::delete() exists, IO::Adapter::SQL::delete() is called.
-
-=cut
-
-
-sub add
-{
- my ($self, $addr) = @_;
-
- # $self->{ _driver } is the $config->{ driver } object.
- if ( $self->{ _driver }->can('add') ) {
- $self->{ _driver }->add($addr);
- }
- else {
- my $query = $self->build_sql_query({
- query => 'add',
- address => $addr,
- });
- $self->execute({ query => $query });
- }
-}
-
-
-sub delete
-{
- my ($self, $addr) = @_;
-
- # $self->{ _driver } is the $config->{ driver } object.
- if ( $self->{ _driver }->can('delete') ) {
- $self->{ _driver }->delete($addr);
- }
- else {
- my $query = $self->build_sql_query({
- query => 'delete',
- address => $addr,
- });
- $self->execute({ query => $query });
- }
-}
-
-
=head1 SEE ALSO
L<DBI>,
diff --git a/fml/lib/IO/Adapter/SQL/toymodel.pm b/fml/lib/IO/Adapter/SQL/toymodel.pm
index dc1e926b..8b4cc218 100644
--- a/fml/lib/IO/Adapter/SQL/toymodel.pm
+++ b/fml/lib/IO/Adapter/SQL/toymodel.pm
@@ -3,7 +3,7 @@
# Copyright (C) 2000,2001 Ken'ichi Fukamachi
# All rights reserved.
#
-# $FML: toymodel.pm,v 1.1.1.1 2001/08/05 01:55:17 fukachan Exp $
+# $FML: toymodel.pm,v 1.2 2001/08/05 03:24:45 fukachan Exp $
#
@@ -29,21 +29,63 @@ model.
=head1 METHODS
-=head2 C<build_sql_query($args)>
+=cut
+
+
+sub add
+{
+ my ($self, $addr) = @_;
+
+ print STDERR "add( $addr )\n" if $ENV{'debug'};
- $args = {
+ my $query = $self->_build_sql_query({
query => 'add',
- address => 'rudo@nuinui.net',
- _params => {
- ml_name => 'elena',
- file => 'actives',
- },
- }
+ address => $addr,
+ });
+ $self->execute({ query => $query });
+}
-=cut
+sub delete
+{
+ my ($self, $addr) = @_;
+
+ print STDERR "delete( $addr )\n" if $ENV{'debug'};
-sub build_sql_query
+ my $query = $self->_build_sql_query({
+ query => 'delete',
+ address => $addr,
+ });
+ $self->execute({ query => $query });
+}
+
+
+sub fetch_and_cache_address_list
+{
+ my ($self, $args) = @_;
+
+ my $query = $self->_build_sql_query({
+ query => 'get_next_value',
+ });
+ $self->execute({ query => $query });
+}
+
+
+# Descriptions:
+#
+# $args = {
+# query => 'add',
+# address => 'rudo@nuinui.net',
+# _params => {
+# ml_name => 'elena',
+# file => 'actives',
+# },
+# }
+#
+# Arguments: $self $args
+# Side Effects:
+# Return Value: none
+sub _build_sql_query
{
my ($self, $args) = @_;
my $query = $args->{ query };
@@ -54,7 +96,7 @@ sub build_sql_query
my $file = $self->{ _params }->{ file };
my $table = $self->{ _table };
- print STDERR "build_sql_query( query=$query )\n" if $ENV{'debug'};
+ print STDERR "_build_sql_query( query=$query )\n" if $ENV{'debug'};
if ($query eq 'add') {
"insert into $table values ('$ml_name', '$file', '$address', 0, 0)";