Skip to content

Commit

Permalink
rename db_type() to dbType() so it matches the style of MeekroDB
Browse files Browse the repository at this point in the history
this function will be documented now
  • Loading branch information
SergeyTsalkov committed Dec 7, 2024
1 parent 3810465 commit ec43009
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions db.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function sync_config() {
}
}

public function db_type() {
public function dbType() {
// $this->db_type var is only set after we connect, so we have to
// make sure we've connected before returning the info
$this->get();
Expand All @@ -200,7 +200,8 @@ public function get() {
}

list($this->db_type) = explode(':', $this->dsn);
if (!$this->db_type) {
$this->db_type = strtolower($this->db_type);
if (!in_array($this->db_type, ['mysql', 'sqlite', 'pgsql'])) {
throw new MeekroDBException("Invalid DSN: " . $this->dsn);
}

Expand Down Expand Up @@ -229,17 +230,16 @@ public function lastQuery() { return $this->last_query; }

public function setDB() { return $this->useDB(...func_get_args()); }
public function useDB($dbName) {
$db_type = $this->db_type();
if (in_array($db_type, array('pgsql', 'sqlite'))) {
throw new MeekroDBException("Database switching not supported by {$db_type}.");
if (in_array($this->dbType(), array('pgsql', 'sqlite'))) {
throw new MeekroDBException(sprintf('Database switching not supported by %s', $this->dbType()));
}

$this->_query('useDB', "USE :c", $dbName);
}

public function startTransaction() {
$start_transaction = 'START TRANSACTION';
if ($this->db_type() == 'sqlite') {
if ($this->dbType() == 'sqlite') {
$start_transaction = 'BEGIN TRANSACTION';
}

Expand Down Expand Up @@ -377,7 +377,7 @@ public function delete() {
}

protected function insertOrReplace($mode, $table, $datas, $options=array()) {
$db_type = $this->db_type();
$db_type = $this->dbType();
$fn_name = 'insert';

if ($mode == 'insert') {
Expand Down Expand Up @@ -496,7 +496,7 @@ public function sqleval() {
}

public function columnList($table) {
$db_type = $this->db_type();
$db_type = $this->dbType();

if ($db_type == 'sqlite') {
$query = 'PRAGMA table_info(:b)';
Expand Down Expand Up @@ -529,14 +529,14 @@ public function columnList($table) {
}

public function tableList($db = null) {
if ($this->db_type() == 'sqlite') {
if ($this->dbType() == 'sqlite') {
if ($db) $tbl = "{$db}.sqlite_master";
else $tbl = "sqlite_master";

$result = $this->_query('tableList', "SELECT name FROM :b
WHERE type='table' AND name NOT LIKE 'sqlite_%'", $tbl);
}
else if ($this->db_type() == 'pgsql') {
else if ($this->dbType() == 'pgsql') {
$result = $this->_query('tableList', "SELECT table_name
FROM information_schema.tables
WHERE table_schema='public'
Expand Down Expand Up @@ -733,7 +733,7 @@ protected function formatName($name, $can_join=false) {
throw new MeekroDBException("Invalid column/table name");
}
$char = '`';
if ($this->db_type() == 'pgsql') $char = '"';
if ($this->dbType() == 'pgsql') $char = '"';
return $char . str_replace($char, $char . $char, $name) . $char;
}

Expand Down Expand Up @@ -984,7 +984,7 @@ protected function queryHelper($opts, $args) {
$pdo = $this->get();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$db_type = $this->db_type();
$db_type = $this->dbType();
if ($db_type == 'mysql') {
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $is_buffered);
}
Expand Down
2 changes: 1 addition & 1 deletion orm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ function query(...$args) {
}

protected function table_struct() {
$db_type = $this->mdb()->db_type();
$db_type = $this->mdb()->dbType();
$data = $this->mdb()->columnList($this->table_name);

if ($db_type == 'mysql') return $this->table_struct_mysql($data);
Expand Down
2 changes: 1 addition & 1 deletion simpletest/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function microtime_float()
require_once sprintf('%s/%s.php', __DIR__, $class);

$object = new $class();
$object->db_type = DB::db_type();
$object->db_type = DB::dbType();
foreach ($data as $key => $value) {
$object->$key = $value;
}
Expand Down

0 comments on commit ec43009

Please sign in to comment.