]>
jfr.im git - irc/SurrealServices/srsv.git/blob - branches/erry-devel/SrSv/MySQL/KeyValStub.pm
1 # This file is part of SurrealServices.
3 # SurrealServices is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # SurrealServices is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with SurrealServices; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 package SrSv
::MySQL
::KeyValStub
;
21 use Symbol
'delete_package';
23 use SrSv
::MySQL
'$dbh';
24 use SrSv
::Process
::Init
;
27 my ($get_sql, $set_sql) = @_;
32 $get = $dbh->prepare($get_sql);
33 $set = $dbh->prepare($set_sql);
40 $set->execute($v, $k); $set->finish;
43 $v = $get->fetchrow_array;
51 sub create_readonly_stub
($) {
57 $get = $dbh->prepare($get_sql);
64 my $v = $get->fetchrow_array;
72 my (undef, $stubs) = @_;
74 my $callpkg = caller();
76 while(my ($name, $sql) = each %$stubs) {
82 $stub = create_stub
($sql->[0], $sql->[1]);
85 $stub = create_readonly_stub
($sql->[0]);
88 my ($package, $filename, $line) = caller();
89 die "Invalid use of ".__PACKAGE__
." at $filename line $line\n";
92 *{"$callpkg\::$name"} = $stub;
97 delete_package
(__PACKAGE__
);