function _insert_entry($_ip_hash, $_count) { $sql = "INSERT INTO {t_visitor}"; $sql .= " (ip_hash, counter, visit)"; $sql .= " VALUES ({ip_hash}, {counter}, {visit})"; $sql .= " ON DUPLICATE KEY UPDATE counter={counter}, visit={visit}"; $query = new FreechSqlQuery($sql); $query->set_string('ip_hash', $_ip_hash); $query->set_string('counter', $_count); $query->set_int('visit', time()); $this->db->_query($query->sql(), NULL) or die('VisitorDB:_insert_entry'); }
function save_forum(&$_forum) { if ($_forum->get_id()) { $sql = "UPDATE {t_forum} SET"; $sql .= " name={name},"; $sql .= " description={description},"; $sql .= " owner_id={owner_id},"; $sql .= " status={status}"; $sql .= " WHERE id={id}"; } else { $sql = "INSERT INTO {t_forum}"; $sql .= " (name, description, owner_id, status)"; $sql .= " VALUES"; $sql .= " ({name}, {description}, {owner_id}, {status})"; } $query = new FreechSqlQuery($sql); $query->set_int('id', $_forum->get_id()); $query->set_int('owner_id', $_forum->get_owner_id()); $query->set_string('name', $_forum->get_name()); $query->set_string('description', $_forum->get_description()); $query->set_int('status', $_forum->get_status()); $this->db->_Execute($query->sql()) or die('ForumDB::save_forum'); if (!$_forum->get_id()) { $_forum->set_id($this->db->Insert_Id()); } }
function util_get_attribute($_dbn, $_name, $_default = NULL) { if (empty($db_base)) { $db_base = cfg('db_tablebase'); } $caption = 'Get version number of the Freech installation'; // Connect to the database. $db = ADONewConnection($_dbn); if (!$db) { return new Result($caption, FALSE, 'Database connection failed. The table is possibly absent. ' . 'Check the installation by hand.'); } if ($_POST['adodb_debug']) { $db->debug = TRUE; } // Insert or update. $sql = 'SELECT value FROM ' . $db_base . 'info WHERE name={name}'; $query = new FreechSqlQuery($sql); $query->set_string('name', $_name); // Run,. $res = $db->execute($query->sql()); if (!$res) { return $_default; } $row = $res->FetchObj(); return $row->value; }
/** * Logs an item. * Returns: The id of the (maybe newly inserted) group. */ function log(&$_item) { if (!is_object($_item)) { die('ModLogDB::save_item(): Invalid arg.'); } $query = new FreechSqlQuery(); $query->set_int('moderator_id', $_item->get_moderator_id()); $query->set_string('moderator_name', $_item->get_moderator_name()); $query->set_string('moderator_group_name', $_item->get_moderator_group_name()); $query->set_string('moderator_icon', $_item->get_moderator_icon()); $query->set_string('action', $_item->get_action()); $query->set_string('reason', $_item->get_reason()); $sql = 'INSERT INTO {t_modlog}'; $sql .= ' ('; $sql .= ' moderator_id,'; $sql .= ' moderator_name,'; $sql .= ' moderator_group_name,'; $sql .= ' moderator_icon,'; $sql .= ' action,'; $sql .= ' reason,'; $sql .= ' created'; $sql .= ' )'; $sql .= ' VALUES ('; $sql .= ' {moderator_id},'; $sql .= ' {moderator_name},'; $sql .= ' {moderator_group_name},'; $sql .= ' {moderator_icon},'; $sql .= ' {action},'; $sql .= ' {reason},'; $sql .= ' NULL'; $sql .= ' )'; $query->set_sql($sql); $this->db->StartTrans(); $this->db->_Execute($query->sql()) or die('ModLogDB::save_item: Ins'); $newid = $this->db->Insert_ID(); $_item->set_id($newid); $this->_save_attributes($_item); $this->db->CompleteTrans(); return $newid; }
/** * Returns the number of all users whose name is similar to the * given one. * $_name: The name for which to find similar users. */ function count_similar_users_from_name($_name) { if (!$_name) { die('UserDB::count_similar_users_from_name(): Invalid name.'); } $user = new User(); $user->set_name($_name); $soundex = $user->get_soundexed_name(); $query = new FreechSqlQuery(); $sql = "SELECT COUNT(*) FROM {t_user}"; $sql .= " WHERE soundexname={soundexname}"; $query->set_sql($sql); $query->set_string('soundexname', $soundex); $n_users = $this->db->GetOne($query->sql()); if (!$n_users) { return 0; } return $n_users; }
function _save_poll_option(&$db, $poll_id, $option) { $sql = 'INSERT INTO {t_poll_option}'; $sql .= ' (poll_id, name)'; $sql .= ' VALUES ('; $sql .= ' {poll_id}, {name}'; $sql .= ')'; $query = new FreechSqlQuery($sql); $query->set_int('poll_id', $poll_id); $query->set_string('name', $option); $db->Execute($query->sql()) or die('_save_poll_option(): Insert'); return $db->Insert_Id(); }
/** * Insert a new group or save an existing one. * * $_group: The group to be saved. * Returns: The id of the (maybe newly inserted) group. */ function save_group(&$_group) { if (!is_object($_group)) { die('GroupDB::save_group(): Invalid arg.'); } $query = new FreechSqlQuery(); $query->set_int('id', $_group->get_id()); $query->set_string('name', $_group->get_name()); $query->set_bool('is_special', $_group->is_special()); $query->set_int('status', $_group->get_status()); if ($_group->get_id() < 1) { $sql = "INSERT INTO {t_group}"; $sql .= " ("; $sql .= " id, name, is_special, status, created"; $sql .= " )"; $sql .= " VALUES ("; $sql .= " {id}, {name}, {is_special}, {status}, NULL"; $sql .= " )"; $query->set_sql($sql); $this->db->StartTrans(); $this->db->_Execute($query->sql()) or die('GroupDB::save_group: Ins'); $newid = $this->db->Insert_ID(); $_group->set_id($newid); $this->_save_permissions($_group); $this->db->CompleteTrans(); return $newid; } $sql = "UPDATE {t_group} SET"; $sql .= " id={id},"; $sql .= " name={name},"; $sql .= " is_special={is_special},"; $sql .= " status={status}"; $sql .= " WHERE id={id}"; $query->set_sql($sql); $this->db->StartTrans(); $this->db->_Execute($query->sql()) or die('GroupDB::save_group(): Upd'); $this->_save_permissions($_group); $this->db->CompleteTrans(); return $_group->get_id(); }