chiark / gitweb /
wip
[nj-awaymsg.git] / mason / save
1 <%init>
2 use AwayMsg;
3 db_connect();
4 </%init>
5 <%args>
6 $textid
7 $save => 0
8 $cancel => 0
9 $textid => undef
10 </%args>
11 <%perl>
12 if ($save) {
13     my $ins;
14     $dbh->do('BEGIN');
15     if ($textid eq 'new') {
16         my $ntextq = $dbh->prepare("SELECT textid FROM texts".
17                                    " ORDER BY textid DESC LIMIT 1");
18         $ntextq->execute();
19         my $ntextrow = $ntextq->fetchrow_hashref();
20         if ($ntextrow) {
21             $textid = $ntextrow->{'textid'} + 1;
22         } else {
23             $textid = 1;
24         }
25     } else {
26         my $dtextq = $dbh->prepare("DELETE FROM texts WHERE textid = ?");
27         my $ndeleted = $dtextq->execute($textid);
28         if (!$ndeleted) {
29 </%perl>
30
31
32         $ins = $dbh->prepare("INSERT INTO texts VALUES (
33       $sth = $dbh->
34 }