. */ require_once("lib/db.php"); function data_check_table() { static $table_exists = FALSE; // already checked? skip... if ($table_exists == TRUE) { return; } // get db handle $db = get_db(); // already in db? skip and remember... $q = $db->query("select name from sqlite_master where type='table' and name='data'"); if ($q->fetchArray()) { $table_exists = TRUE; return; } // create the table and remember... $table_exists = $db->exec("create table data (data text unique on conflict replace, committime integer)"); } function data_get() { $results = array(); data_check_table(); $db = get_db(); $q = $db->query("select data from data where committime > strftime('%s','now') - ".DATA_TTL); if (!$q) return $results; while($row = $q->fetchArray(SQLITE3_ASSOC)) { $results[] = $row['data']; } return $results; } function data_add($data) { $db = get_db(); data_check_table(); $data = $db->escapeString($data); #echo "insert or replace into data values (\"$data\", strftime('%s','now'))\n"; $result = $db->exec("insert or replace into data values (\"$data\", strftime('%s','now'))"); if (!$result) echo "ERROR: ".$db->lastErrorMsg()."\n"; } function data_purge() { $db = get_db(); data_check_table(); return $db->exec("delete from data where committime <= strftime('%s','now') - ".DATA_TTL); }