Upgrade to sqlite3

This commit is contained in:
sandbender 2010-11-14 00:15:26 +01:00
parent 5098db94eb
commit 95d8ede9ac
5 changed files with 17 additions and 19 deletions

View File

@ -1,4 +1,6 @@
<html xmlns="http://www.w3.org/1999/xhtml"> <?php
require_once("config.php");
?><html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<title>Pamela</title> <title>Pamela</title>
<script src="js/jquery-1.3.2.js" type="text/javascript"></script> <script src="js/jquery-1.3.2.js" type="text/javascript"></script>

View File

@ -4,7 +4,7 @@ require_once("config.php");
function get_db() { function get_db() {
static $db = NULL; static $db = NULL;
if ($db == NULL) { if ($db == NULL) {
$db = sqlite_open(SQLITE_DB); $db = new SQLite3(SQLITE_DB);
} }
return $db; return $db;
} }

View File

@ -4,10 +4,9 @@ require_once("lib/db.php");
function macs_get() { function macs_get() {
$results = array(); $results = array();
$db = get_db(); $db = get_db();
$q = sqlite_query($db, "select mac from macs where committime > strftime('%s','now') - ".MACFILE_TTL); $q = $db->query("select mac from macs where committime > strftime('%s','now') - ".MACFILE_TTL);
if (!$q) return $results; if (!$q) return $results;
while(sqlite_has_more($q)) { while($row = $q->fetch_array(SQLITE_ASSOC)) {
$row = sqlite_fetch_array($q, SQLITE_ASSOC);
$results[] = $row['mac']; $results[] = $row['mac'];
} }
return $results; return $results;
@ -15,11 +14,11 @@ function macs_get() {
function macs_add($mac) { function macs_add($mac) {
$db = get_db(); $db = get_db();
$mac = sqlite_escape_string($mac); $mac = $db->escape_string($mac);
return sqlite_exec($db, "insert or replace into macs values (\"$mac\", strftime('%s','now'))"); return $db->exec("insert or replace into macs values (\"$mac\", strftime('%s','now'))");
} }
function macs_purge() { function macs_purge() {
$db = get_db(); $db = get_db();
return sqlite_exec($db, "delete from macs where committime <= strftime('%s','now') - ".MACFILE_TTL); return $db->exec("delete from macs where committime <= strftime('%s','now') - ".MACFILE_TTL);
} }

View File

@ -4,10 +4,9 @@ require_once("lib/db.php");
function known_macs_get() { function known_macs_get() {
$results = array(); $results = array();
$db = get_db(); $db = get_db();
$q = sqlite_query($db, "select * from knownmacs"); $q = $db->query("select * from knownmacs");
if (!$q) return $results; if (!$q) return $results;
while(sqlite_has_more($q)) { while($row = $q->fetch_array(SQLITE_ASSOC)) {
$row = sqlite_fetch_array($q, SQLITE_ASSOC);
$results[$row['mac']] = $row['name']; $results[$row['mac']] = $row['name'];
} }
return $results; return $results;
@ -16,10 +15,9 @@ function known_macs_get() {
function known_macs_get_by_user($userid) { function known_macs_get_by_user($userid) {
$results = array(); $results = array();
$db = get_db(); $db = get_db();
$q = sqlite_query($db, "select * from knownmacs where userid = \"userid\""); $q = $db->query("select * from knownmacs where userid = \"userid\"");
if (!$q) return $results; if (!$q) return $results;
while(sqlite_has_more($q)) { while($row = $q->fetch_array(SQLITE_ASSOC)) {
$row = sqlite_fetch_array($q, SQLITE_ASSOC);
$results[$row['mac']] = $row['name']; $results[$row['mac']] = $row['name'];
} }
return $results; return $results;
@ -27,10 +25,10 @@ function known_macs_get_by_user($userid) {
function known_macs_upsert($mac, $name, $show) { function known_macs_upsert($mac, $name, $show) {
$db = get_db(); $db = get_db();
$mac = sqlite_escape_string($mac); $mac = $db->escape_string($mac);
$name = sqlite_escape_string($name); $name = $db->escape_string($name);
$show = sqlite_escape_string($show); $show = $db->escape_string($show);
return sqlite_exec($db, "insert into knownmacs or replace (mac, name, show) values (\"$mac\", \"$name\", \"$show\")"); return $db->exec("insert into knownmacs or replace (mac, name, show) values (\"$mac\", \"$name\", \"$show\")");
} }
function known_macs_translate($macs) { function known_macs_translate($macs) {

View File

@ -37,7 +37,6 @@ function multiply() {
} }
} }
} }
$macs = macs_get(); $macs = macs_get();
$macs = known_macs_translate($macs); $macs = known_macs_translate($macs);
if (count($macs) > 0) { if (count($macs) > 0) {