-
Notifications
You must be signed in to change notification settings - Fork 117
/
db.php
114 lines (90 loc) · 3.14 KB
/
db.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/*
* A mess
*/
require_once "dbeng/db_sqlite3.php";
require_once "dbeng/db_mysql.php";
class db
{
private $_conn;
function __construct($db)
{
global $settings;
switch ($db['engine']) {
case 'sqlite3' : $this->_conn = new db_sqlite3($db['path']);
break;
case 'mysql' : $this->_conn = new db_mysql($db['host'],
$db['user'],
$db['pass'],
$db['dbname']);
break;
default : die("Unknown DB engine specified, please choose sqlite3 or mysql");
} # switch
} # ctor
function setMaxArticleId($server, $maxarticleid) {
return $this->_conn->exec("REPLACE INTO nntp(server, maxarticleid) VALUES('%s',%s)", Array($server, (int) $maxarticleid));
} # setMaxArticleId
function getMaxArticleId($server) {
$p = $this->_conn->singleQuery("SELECT maxarticleid FROM nntp WHERE server = '%s'", Array($server));
if ($p == null) {
$this->setMaxArticleId($server, 0);
$p = 0;
} # if
return $p;
} # getMaxArticleId
function getSpotCount() {
$p = $this->_conn->singleQuery("SELECT COUNT(1) FROM spots");
if ($p == null) {
return 0;
} else {
return $p;
} # if
} # getSpotCount
function getSpots($id, $limit, $sqlFilter) {
$results = array();
if (!empty($sqlFilter)) {
$sqlFilter = ' AND ' . $sqlFilter;
} # if
return $this->_conn->arrayQuery("SELECT * FROM spots WHERE id > " . (int) $id . $sqlFilter . " ORDER BY stamp DESC LIMIT " . (int) $limit);
} # getSpots
function getSpot($messageId) {
return $this->_conn->arrayQuery("SELECT * FROM spots WHERE messageid = '%s'", Array($messageId));
} # getSpot()
function beginTransaction() {
$this->_conn->exec('BEGIN;', array());
} # beginTransaction
function abortTransaction() {
$this->_conn->exec('ABORT;', array());
} # abortTransaction
function endTransaction() {
$this->_conn->exec('COMMIT;', array());
} # endTransaction
function safe($q) {
return $this->_conn->safe($q);
} # safe
function addCommentRef($messageid, $revid, $nntpref) {
return $this->_conn->exec("REPLACE INTO commentsxover(messageid, revid, nntpref)
VALUES('%s', %d, '%s')",
Array($messageid, (int) $revid, $nntpref));
} # addCommentRef
function getCommentRef($nntpref) {
return $this->_conn->arrayQuery("SELECT messageid, MAX(revid) FROM commentsxover WHERE nntpref = '<%s>' GROUP BY messageid", Array($nntpref));
} # getCommentRef
function addSpot($spot) {
return $this->_conn->exec("INSERT INTO spots(spotid, messageid, category, subcat, poster, groupname, subcata, subcatb, subcatc, subcatd, title, tag, stamp)
VALUES(%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
Array($spot['ID'],
$spot['MessageID'],
$spot['Category'],
$spot['SubCat'],
$spot['Poster'],
$spot['GroupName'],
$spot['SubCatA'],
$spot['SubCatB'],
$spot['SubCatC'],
$spot['SubCatD'],
$spot['Title'],
$spot['Tag'],
$spot['Stamp']));
} # addSpot()
}