Skip to content

Commit

Permalink
refactor(sqlite): db session implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow243 committed Dec 7, 2024
1 parent 82b1cb8 commit 5f024a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions lib/session_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ private function acquire_lock($key) {
$params = [':hash_key' => crc32($lock_name)];
break;
case 'sqlite':
$query = 'UPDATE hm_user_session SET lock=1 WHERE hm_id=? AND lock=0';
$params = [$key];
$query = 'UPDATE hm_user_session SET lock=1 WHERE hm_id=:hm_id AND lock=0';
$params = [':hm_id' => $key];
break;
default:
Hm_Debug::add('DB SESSION: Unsupported db_driver for locking: ' . $this->db_driver);
return false;
}
$result = Hm_DB::execute($this->dbh, $query, $params);
}
$result = Hm_DB::execute($this->dbh, $query, $params, ($this->db_driver == 'sqlite') ? 'modify' : false);
if ($this->db_driver == 'mysql') {
if (isset($result['GET_LOCK(?, ?)']) && $result['GET_LOCK(?, ?)'] == 1) {
return true;
Expand All @@ -249,7 +249,7 @@ private function acquire_lock($key) {
}
}
if ($this->db_driver == 'sqlite') {
if (isset($result[0]) && $result[0] == 1) {
if ($result >= 1) {
return true;
}
}
Expand Down Expand Up @@ -281,8 +281,8 @@ private function release_lock($key) {
$params = [':hash_key' => crc32($lock_name)];
break;
case 'sqlite':
$query = 'UPDATE hm_user_session SET lock=0 WHERE hm_id=?';
$params = [$key];
$query = 'UPDATE hm_user_session SET lock=0 WHERE hm_id=:hm_id';
$params = [':hm_id' => $key];
break;
default:
Hm_Debug::add('DB SESSION: Unsupported db_driver for unlocking: ' . $this->db_driver);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/data/schema_postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ DROP TABLE IF EXISTS hm_user_settings;

CREATE TABLE IF NOT EXISTS hm_user (username varchar(255), hash varchar(255), primary key (username));

CREATE TABLE IF NOT EXISTS hm_user_session (hm_id varchar(255), data longblob, date timestamp, hm_version int default 1, primary key (hm_id));
CREATE TABLE IF NOT EXISTS hm_user_session (hm_id varchar(255), data bytea, date timestamp, hm_version int default 1, primary key (hm_id));

CREATE TABLE IF NOT EXISTS hm_user_settings(username varchar(255), settings longblob, primary key (username));
CREATE TABLE IF NOT EXISTS hm_user_settings(username varchar(255), settings bytea, primary key (username));

0 comments on commit 5f024a8

Please sign in to comment.