]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/PearDB.php
Fix the fix: fun with regexps. (minor).
[SourceForge/phpwiki.git] / lib / WikiDB / backend / PearDB.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PearDB.php,v 1.6 2001-09-21 14:41:33 dairiki Exp $');
3
4 //require_once('DB.php');
5 require_once('lib/WikiDB/backend.php');
6 require_once('lib/FileFinder.php');
7 require_once('lib/ErrorManager.php');
8
9 class WikiDB_backend_PearDB
10 extends WikiDB_backend
11 {
12     function WikiDB_backend_PearDB ($dbparams) {
13         // Find and include PEAR's DB.php.
14         $pearFinder = new PearFileFinder;
15         $pearFinder->includeOnce('DB.php');
16
17         // Install filter to handle bogus error notices from buggy DB.php's.
18         global $ErrorManager;
19         $ErrorManager->pushErrorHandler(array($this, '_pear_notice_filter'));
20         
21         // Open connection to database
22         $dsn = $dbparams['dsn'];
23         $this->_dbh = DB::connect($dsn, true); //FIXME: true -> persistent connection
24         $dbh = &$this->_dbh;
25         if (DB::isError($dbh)) {
26             trigger_error("Can't connect to database: "
27                           . $this->_pear_error_message($dbh),
28                           E_USER_ERROR);
29         }
30         $dbh->setErrorHandling(PEAR_ERROR_CALLBACK,
31                                array($this, '_pear_error_callback'));
32         $dbh->setFetchMode(DB_FETCHMODE_ASSOC);
33
34         $prefix = isset($dbparams['prefix']) ? $dbparams['prefix'] : '';
35
36         $this->_table_names
37             = array('page_tbl'     => $prefix . 'page',
38                     'version_tbl'  => $prefix . 'version',
39                     'link_tbl'     => $prefix . 'link',
40                     'recent_tbl'   => $prefix . 'recent',
41                     'nonempty_tbl' => $prefix . 'nonempty');
42
43         $this->_lock_count = 0;
44     }
45     
46     /**
47      * Close database connection.
48      */
49     function close () {
50         if (!$this->_dbh)
51             return;
52         if ($this->_lock_count) {
53             trigger_error("WARNING: database still locked"
54                           . " (lock_count = $this->_lock_count)\n<br>",
55                           E_USER_WARNING);
56         }
57         $this->_dbh->setErrorHandling(PEAR_ERROR_PRINT);        // prevent recursive loops.
58         $this->unlock('force');
59
60         $this->_dbh->disconnect();
61         $this->_dbh = false;
62     }
63
64
65     /*
66      * Test fast wikipage.
67      */
68     function is_wiki_page($pagename) {
69         $dbh = &$this->_dbh;
70         extract($this->_table_names);
71         return $dbh->getOne(sprintf("SELECT $page_tbl.id"
72                                     . " FROM $nonempty_tbl INNER JOIN $page_tbl USING(id)"
73                                     . " WHERE pagename='%s'",
74                                     $dbh->quoteString($pagename)));
75     }
76         
77     function get_all_pagenames() {
78         $dbh = &$this->_dbh;
79         extract($this->_table_names);
80         return $dbh->getCol("SELECT pagename"
81                             . " FROM $nonempty_tbl INNER JOIN $page_tbl USING(id)");
82     }
83             
84     /**
85      * Read page information from database.
86      */
87     function get_pagedata($pagename) {
88         $dbh = &$this->_dbh;
89         $page_tbl = $this->_table_names['page_tbl'];
90
91         //trigger_error("GET_PAGEDATA $pagename", E_USER_NOTICE);
92
93         $result = $dbh->getRow(sprintf("SELECT * FROM $page_tbl WHERE pagename='%s'",
94                                        $dbh->quoteString($pagename)),
95                                DB_FETCHMODE_ASSOC);
96         if (!$result)
97             return false;
98         return $this->_extract_page_data($result);
99     }
100
101     function  _extract_page_data(&$query_result) {
102         extract($query_result);
103         $data = empty($pagedata) ? array() : unserialize($pagedata);
104         $data['hits'] = $hits;
105         return $data;
106     }
107
108     function update_pagedata($pagename, $newdata) {
109         $dbh = &$this->_dbh;
110         $page_tbl = $this->_table_names['page_tbl'];
111
112         // Hits is the only thing we can update in a fast manner.
113         if (count($newdata) == 1 && isset($newdata['hits'])) {
114             // Note that this will fail silently if the page does not
115             // have a record in the page table.  Since it's just the
116             // hit count, who cares?
117             $dbh->query(sprintf("UPDATE $page_tbl SET hits=%d WHERE pagename='%s'",
118                                 $newdata['hits'], $dbh->quoteString($pagename)));
119             return;
120         }
121
122         $this->lock();
123         $data = $this->get_pagedata($pagename);
124         if (!$data) {
125             $data = array();
126             $this->_get_pageid($pagename, true); // Creates page record
127         }
128         
129         @$hits = (int)$data['hits'];
130         unset($data['hits']);
131
132         foreach ($newdata as $key => $val) {
133             if ($key == 'hits')
134                 $hits = (int)$val;
135             else if (empty($val))
136                 unset($data[$key]);
137             else
138                 $data[$key] = $val;
139         }
140
141         $dbh->query(sprintf("UPDATE $page_tbl"
142                             . " SET hits=%d, pagedata='%s'"
143                             . " WHERE pagename='%s'",
144                             $hits,
145                             $dbh->quoteString(serialize($data)),
146                             $dbh->quoteString($pagename)));
147
148         $this->unlock();
149     }
150
151     function _get_pageid($pagename, $create_if_missing = false) {
152         
153         $dbh = &$this->_dbh;
154         $page_tbl = $this->_table_names['page_tbl'];
155         
156         $query = sprintf("SELECT id FROM $page_tbl WHERE pagename='%s'",
157                          $dbh->quoteString($pagename));
158
159         if (!$create_if_missing)
160             return $dbh->getOne($query);
161
162         $this->lock();
163         $id = $dbh->getOne($query);
164         if (empty($id)) {
165             $max_id = $dbh->getOne("SELECT MAX(id) FROM $page_tbl");
166             $id = $max_id + 1;
167             $dbh->query(sprintf("INSERT INTO $page_tbl"
168                                 . " (id,pagename,hits)"
169                                 . " VALUES (%d,'%s',0)",
170                                 $id, $dbh->quoteString($pagename)));
171         }
172         $this->unlock();
173         return $id;
174     }
175
176     function get_latest_version($pagename) {
177         $dbh = &$this->_dbh;
178         extract($this->_table_names);
179         return
180             (int)$dbh->getOne(sprintf("SELECT latestversion"
181                                       . " FROM $page_tbl"
182                                       . "  INNER JOIN $recent_tbl USING(id)"
183                                       . " WHERE pagename='%s'",
184                                       $dbh->quoteString($pagename)));
185     }
186
187     function get_previous_version($pagename, $version) {
188         $dbh = &$this->_dbh;
189         extract($this->_table_names);
190         
191         return
192             (int)$dbh->getOne(sprintf("SELECT version"
193                                       . " FROM $version_tbl"
194                                       . "  INNER JOIN $page_tbl USING(id)"
195                                       . " WHERE pagename='%s'"
196                                       . "  AND version < %d"
197                                       . " ORDER BY version DESC"
198                                       . " LIMIT 1",
199                                       $dbh->quoteString($pagename),
200                                       $version));
201     }
202     
203     /**
204      * Get version data.
205      *
206      * @param $version int Which version to get.
207      *
208      * @return hash The version data, or false if specified version does not
209      *              exist.
210      */
211     function get_versiondata($pagename, $version, $want_content = false) {
212         $dbh = &$this->_dbh;
213         extract($this->_table_names);
214                 
215         assert(!empty($pagename));
216         assert($version > 0);
217         
218         //trigger_error("GET_REVISION $pagename $version $want_content", E_USER_NOTICE);
219         // FIXME: optimization: sometimes don't get page data?
220
221         if ($want_content) {
222             $fields = "*";
223         }
224         else {
225             $fields = ("$page_tbl.*,"
226                        . "mtime,minor_edit,versiondata,"
227                        . "content<>'' AS have_content");
228         }
229
230         $result = $dbh->getRow(sprintf("SELECT $fields"
231                                        . " FROM $page_tbl"
232                                        . "  INNER JOIN $version_tbl USING(id)"
233                                        . " WHERE pagename='%s' AND version=%d",
234                                        $dbh->quoteString($pagename), $version),
235                                DB_FETCHMODE_ASSOC);
236
237         return $this->_extract_version_data($result);
238     }
239
240     function _extract_version_data(&$query_result) {
241         if (!$query_result)
242             return false;
243
244         extract($query_result);
245         $data = empty($versiondata) ? array() : unserialize($versiondata);
246
247         $data['mtime'] = $mtime;
248         $data['is_minor_edit'] = !empty($minor_edit);
249         
250         if (isset($content))
251             $data['%content'] = $content;
252         elseif ($have_content)
253             $data['%content'] = true;
254         else
255             $data['%content'] = '';
256
257         // FIXME: this is ugly.
258         if (isset($pagename)) {
259             // Query also includes page data.
260             // We might as well send that back too...
261             $data['%pagedata'] = $this->_extract_page_data($query_result);
262         }
263
264         return $data;
265     }
266
267
268     /**
269      * Create a new revision of a page.
270      */
271     function set_versiondata($pagename, $version, $data) {
272         $dbh = &$this->_dbh;
273         $version_tbl = $this->_table_names['version_tbl'];
274         
275         $minor_edit = (int) !empty($data['is_minor_edit']);
276         unset($data['is_minor_edit']);
277         
278         $mtime = (int)$data['mtime'];
279         unset($data['mtime']);
280         assert(!empty($mtime));
281
282         @$content = (string) $data['%content'];
283         unset($data['%content']);
284
285         unset($data['%pagedata']);
286         
287         $this->lock();
288         $id = $this->_get_pageid($pagename, true);
289
290         // FIXME: optimize: mysql can do this with one REPLACE INTO (I think).
291         $dbh->query(sprintf("DELETE FROM $version_tbl"
292                             . " WHERE id=%d AND version=%d",
293                             $id, $version));
294
295         $dbh->query(sprintf("INSERT INTO $version_tbl"
296                             . " (id,version,mtime,minor_edit,content,versiondata)"
297                             . " VALUES(%d,%d,%d,%d,'%s','%s')",
298                             $id, $version, $mtime, $minor_edit,
299                             $dbh->quoteString($content),
300                             $dbh->quoteString(serialize($data))));
301
302         $this->_update_recent_table($id);
303         $this->_update_nonempty_table($id);
304         
305         $this->unlock();
306     }
307     
308     /**
309      * Delete an old revision of a page.
310      */
311     function delete_versiondata($pagename, $version) {
312         $dbh = &$this->_dbh;
313         extract($this->_table_names);
314
315         $this->lock();
316         if ( ($id = $this->_get_pageid($pagename)) ) {
317             $dbh->query("DELETE FROM $version_tbl"
318                         . " WHERE id=$id AND version=$version");
319             $this->_update_recent_table($id);
320             // This shouldn't be needed (as long as the latestversion
321             // never gets deleted.)  But, let's be safe.
322             $this->_update_nonempty_table($id);
323         }
324         $this->unlock();
325     }
326
327     /**
328      * Delete page from the database.
329      */
330     function delete_page($pagename) {
331         $dbh = &$this->_dbh;
332         extract($this->_table_names);
333         
334         $this->lock();
335         if ( ($id = $this->_get_pageid($pagename, 'id')) ) {
336             $dbh->query("DELETE FROM $version_tbl  WHERE id=$id");
337             $dbh->query("DELETE FROM $recent_tbl   WHERE id=$id");
338             $dbh->query("DELETE FROM $nonempty_tbl WHERE id=$id");
339             $dbh->query("DELETE FROM $link_tbl     WHERE linkfrom=$id");
340             $nlinks = $dbh->getOne("SELECT COUNT(*) FROM $link_tbl WHERE linkto=$id");
341             if ($nlinks) {
342                 // We're still in the link table (dangling link) so we can't delete this
343                 // altogether.
344                 $dbh->query("UPDATE $page_tbl SET hits=0, pagedata='' WHERE id=$id");
345             }
346             else {
347                 $dbh->query("DELETE FROM $page_tbl WHERE id=$id");
348             }
349             $this->_update_recent_table();
350             $this->_update_nonempty_table();
351         }
352         $this->unlock();
353     }
354             
355
356     // The only thing we might be interested in updating which we can
357     // do fast in the flags (minor_edit).   I think the default
358     // update_versiondata will work fine...
359     //function update_versiondata($pagename, $version, $data) {
360     //}
361
362     function set_links($pagename, $links) {
363         // Update link table.
364         // FIXME: optimize: mysql can do this all in one big INSERT.
365
366         $dbh = &$this->_dbh;
367         extract($this->_table_names);
368
369         $this->lock();
370         $pageid = $this->_get_pageid($pagename, true);
371
372         $dbh->query("DELETE FROM $link_tbl WHERE linkfrom=$pageid");
373
374         foreach($links as $link) {
375             if (isset($linkseen[$link]))
376                 continue;
377             $linkseen[$link] = true;
378             $linkid = $this->_get_pageid($link, true);
379             $dbh->query("INSERT INTO $link_tbl (linkfrom, linkto)"
380                         . " VALUES ($pageid, $linkid)");
381         }
382         $this->unlock();
383     }
384     
385     /**
386      * Find pages which link to or are linked from a page.
387      */
388     function get_links($pagename, $reversed = true) {
389         $dbh = &$this->_dbh;
390         extract($this->_table_names);
391
392         if ($reversed)
393             list($have,$want) = array('linkee', 'linker');
394         else
395             list($have,$want) = array('linker', 'linkee');
396
397         $qpagename = $dbh->quoteString($pagename);
398         
399         $result = $dbh->query("SELECT $want.*"
400                               . " FROM $link_tbl"
401                               . "  INNER JOIN $page_tbl AS linker ON linkfrom=linker.id"
402                               . "  INNER JOIN $page_tbl AS linkee ON linkto=linkee.id"
403                               . " WHERE $have.pagename='$qpagename'"
404                               //. " GROUP BY $want.id"
405                               . " ORDER BY $want.pagename",
406                               DB_FETCHMODE_ASSOC);
407         
408         return new WikiDB_backend_PearDB_iter($this, $result);
409     }
410
411     function get_all_pages($include_deleted) {
412         $dbh = &$this->_dbh;
413         extract($this->_table_names);
414
415         if ($include_deleted) {
416             $result = $dbh->query("SELECT * FROM $page_tbl ORDER BY pagename");
417         }
418         else {
419             $result = $dbh->query("SELECT $page_tbl.*"
420                                   . " FROM $nonempty_tbl INNER JOIN $page_tbl USING(id)"
421                                   . " ORDER BY pagename");
422         }
423
424         return new WikiDB_backend_PearDB_iter($this, $result);
425     }
426         
427     /**
428      * Title search.
429      */
430     function text_search($search = '', $fullsearch = false) {
431         $dbh = &$this->_dbh;
432         extract($this->_table_names);
433         
434         $table = "$nonempty_tbl INNER JOIN $page_tbl USING(id)";
435         $fields = "$page_tbl.*";
436         $callback = '_sql_match_clause';
437         
438         if ($fullsearch) {
439             $table .= (" INNER JOIN $recent_tbl ON $page_tbl.id=$recent_tbl.id"
440                        . " INNER JOIN $version_tbl"
441                        . "   ON $page_tbl.id=$version_tbl.id"
442                        . "   AND latestversion=version" );
443             $fields .= ",$version_tbl.*";
444             $callback = '_fullsearch_sql_match_clause';
445         }
446
447         
448         $search_clause = $search->makeSqlClause(array($this, $callback));
449         
450         $result = $dbh->query("SELECT $fields FROM $table"
451                               . " WHERE $search_clause"
452                               . " ORDER BY pagename");
453         
454         return new WikiDB_backend_PearDB_iter($this, $result);
455     }
456
457     function _sql_match_clause($word) {
458         $word = $this->_dbh->quoteString($word);
459         return "LOWER(pagename) LIKE '%$word%'";
460     }
461
462     function _fullsearch_sql_match_clause($word) {
463         $word = $this->_dbh->quoteString($word);
464         return "LOWER(pagename) LIKE '%$word%' OR content LIKE '%$word%'";
465     }
466
467     /**
468      * Find highest hit counts.
469      */
470     function most_popular($limit) {
471         $dbh = &$this->_dbh;
472         extract($this->_table_names);
473
474         $limitclause = $limit ? " LIMIT $limit" : '';
475         $result = $dbh->query("SELECT $page_tbl.*"
476                               . " FROM $nonempty_tbl INNER JOIN $page_tbl USING(id)"
477                               . " ORDER BY hits DESC"
478                               . " $limitclause");
479
480         return new WikiDB_backend_PearDB_iter($this, $result);
481     }
482
483     /**
484      * Find recent changes.
485      */
486     function most_recent($params) {
487         $limit = 0;
488         $since = 0;
489         $include_minor_revisions = false;
490         $exclude_major_revisions = false;
491         $include_all_revisions = false;
492         extract($params);
493
494         $dbh = &$this->_dbh;
495         extract($this->_table_names);
496
497         $pick = array();
498         if ($since)
499             $pick[] = "mtime >= $since";
500         
501         if ($include_all_revisions) {
502             // Include all revisions of each page.
503             $table = "$page_tbl INNER JOIN $version_tbl USING(id)";
504
505             if ($exclude_major_revisions) {
506                 // Include only minor revisions
507                 $pick[] = "minor_edit <> 0";
508             }
509             elseif (!$include_minor_revisions) {
510                 // Include only major revisions
511                 $pick[] = "minor_edit = 0";
512             }
513         }
514         else {
515             $table = ( "$page_tbl INNER JOIN $recent_tbl USING(id)"
516                        . " INNER JOIN $version_tbl ON $version_tbl.id=$page_tbl.id");
517                 
518             if ($exclude_major_revisions) {
519                 // Include only most recent minor revision
520                 $pick[] = 'version=latestminor';
521             }
522             elseif (!$include_minor_revisions) {
523                 // Include only most recent major revision
524                 $pick[] = 'version=latestmajor';
525             }
526             else {
527                 // Include only the latest revision (whether major or minor).
528                 $pick[] ='version=latestversion';
529             }
530         }
531
532         $limitclause = $limit ? " LIMIT $limit" : '';
533         $whereclause = $pick ? " WHERE " . join(" AND ", $pick) : '';
534
535         // FIXME: use SQL_BUFFER_RESULT for mysql?
536         $result = $dbh->query("SELECT $page_tbl.*,$version_tbl.*"
537                               . " FROM $table"
538                               . $whereclause
539                               . " ORDER BY mtime DESC"
540                               . $limitclause);
541
542         return new WikiDB_backend_PearDB_iter($this, $result);
543     }
544
545     function _update_recent_table($pageid = false) {
546         $dbh = &$this->_dbh;
547         extract($this->_table_names);
548
549         $maxmajor = "MAX(CASE WHEN minor_edit=0 THEN version END)";
550         $maxminor = "MAX(CASE WHEN minor_edit<>0 THEN version END)";
551         $maxversion = "MAX(version)";
552
553         $pageid = (int)$pageid;
554
555         $this->lock();
556
557         $dbh->query("DELETE FROM $recent_tbl"
558                     . ( $pageid ? " WHERE id=$pageid" : ""));
559         
560         $dbh->query( "INSERT INTO $recent_tbl"
561                      . " (id, latestversion, latestmajor, latestminor)"
562                      . " SELECT id, $maxversion, $maxmajor, $maxminor"
563                      . " FROM $version_tbl"
564                      . ( $pageid ? " WHERE id=$pageid" : "")
565                      . " GROUP BY id" );
566         $this->unlock();
567     }
568
569     function _update_nonempty_table($pageid = false) {
570         $dbh = &$this->_dbh;
571         extract($this->_table_names);
572
573         $pageid = (int)$pageid;
574
575         $this->lock();
576
577         $dbh->query("DELETE FROM $nonempty_tbl"
578                     . ( $pageid ? " WHERE id=$pageid" : ""));
579
580         $dbh->query("INSERT INTO $nonempty_tbl (id)"
581                     . " SELECT $recent_tbl.id"
582                     . " FROM $recent_tbl INNER JOIN $version_tbl"
583                     . "               ON $recent_tbl.id=$version_tbl.id"
584                     . "                  AND version=latestversion"
585                     . "  WHERE content<>''"
586                     . ( $pageid ? " AND $recent_tbl.id=$pageid" : ""));
587
588         $this->unlock();
589     }
590
591
592     /**
593      * Grab a write lock on the tables in the SQL database.
594      *
595      * Calls can be nested.  The tables won't be unlocked until
596      * _unlock_database() is called as many times as _lock_database().
597      *
598      * @access protected
599      */
600     function lock($write_lock = true) {
601         if ($this->_lock_count++ == 0)
602             $this->_lock_tables($write_lock);
603     }
604
605     /**
606      * Actually lock the required tables.
607      */
608     function _lock_tables($write_lock) {
609         trigger_error("virtual", E_USER_ERROR);
610     }
611     
612     /**
613      * Release a write lock on the tables in the SQL database.
614      *
615      * @access protected
616      *
617      * @param $force boolean Unlock even if not every call to lock() has been matched
618      * by a call to unlock().
619      *
620      * @see _lock_database
621      */
622     function unlock($force = false) {
623         if ($this->_lock_count == 0)
624             return;
625         if (--$this->_lock_count <= 0 || $force) {
626             $this->_unlock_tables();
627             $this->_lock_count = 0;
628         }
629     }
630
631     /**
632      * Actually unlock the required tables.
633      */
634     function _unlock_tables($write_lock) {
635         trigger_error("virtual", E_USER_ERROR);
636     }
637     
638     /**
639      * Callback for PEAR (DB) errors.
640      *
641      * @access protected
642      *
643      * @param A PEAR_error object.
644      */
645     function _pear_error_callback($error) {
646         if ($this->_is_false_error($error))
647             return;
648         
649         $this->_dbh->setErrorHandling(PEAR_ERROR_PRINT);        // prevent recursive loops.
650         $this->close();
651         trigger_error($this->_pear_error_message($error), E_USER_ERROR);
652     }
653
654     /**
655      * Detect false errors messages from PEAR DB.
656      *
657      * The version of PEAR DB which ships with PHP 4.0.6 has a bug in that
658      * it doesn't recognize "LOCK" and "UNLOCK" as SQL commands which don't
659      * return any data.  (So when a "LOCK" command doesn't return any data,
660      * DB reports it as an error, when in fact, it's not.)
661      *
662      * @access private
663      * @return bool True iff error is not really an error.
664      */
665     function _is_false_error($error) {
666         $code = $error->getCode();
667         $query = $this->_dbh->last_query;
668         return ($code == DB_ERROR
669                 && ! DB::isManip($query)
670                 && preg_match('/^\s*"?(LOCK|UNLOCK)\s/', $query));
671     }
672
673     function _pear_error_message($error) {
674         $class = get_class($this);
675         $message = "$class: fatal database error\n"
676              . "\t" . $error->getMessage() . "\n"
677              . "\t(" . $error->getDebugInfo() . ")\n";
678
679         return $message;
680     }
681
682     /**
683      * Filter PHP errors notices from PEAR DB code.
684      *
685      * The PEAR DB code which ships with PHP 4.0.6 produces spurious
686      * errors and notices.  This is an error callback (for use with
687      * ErrorManager which will filter out those spurious messages.)
688      * @see _is_false_error, ErrorManager
689      * @access private
690      */
691     function _pear_notice_filter($err) {
692         return ( $err->isNotice()
693                  && preg_match('|DB[/\\\\]common.php$|', $err->errfile)
694                  && $err->errline == 126
695                  && preg_match('/Undefined offset: +0\b/', $err->errstr) );
696     }
697 };
698
699 class WikiDB_backend_PearDB_iter
700 extends WikiDB_backend_iterator
701 {
702     function WikiDB_backend_PearDB_iter(&$backend, &$query_result) {
703         if (DB::isError($query_result)) {
704             // This shouldn't happen, I thought.
705             $backend->_pear_error_callback($query_result);
706         }
707         
708         $this->_backend = &$backend;
709         $this->_result = $query_result;
710     }
711     
712     function next() {
713         $backend = &$this->_backend;
714         if (!$this->_result)
715             return false;
716
717         $record = $this->_result->fetchRow(DB_FETCHMODE_ASSOC);
718         if (!$record) {
719             $this->free();
720             return false;
721         }
722         
723         $pagedata = $backend->_extract_page_data($record);
724         $rec = array('pagename' => $record['pagename'],
725                      'pagedata' => $pagedata);
726
727         if (!empty($record['version'])) {
728             $rec['versiondata'] = $backend->_extract_version_data($record);
729             $rec['version'] = $record['version'];
730         }
731         
732         return $rec;
733     }
734
735     function free () {
736         if ($this->_result) {
737             $this->_result->free();
738             $this->_result = false;
739         }
740     }
741 }
742
743 // (c-file-style: "gnu")
744 // Local Variables:
745 // mode: php
746 // tab-width: 8
747 // c-basic-offset: 4
748 // c-hanging-comment-ender-p: nil
749 // indent-tabs-mode: nil
750 // End:   
751 ?>