Add deleted to edit_group/user decl, add assoc only return for fetchrow

DB IO Fetchrow has assoc only true/false
Currently only tested with PgSQL

default returns both,
if set true only returns assoc
This commit is contained in:
Clemens Schwaighofer
2019-08-28 18:49:23 +09:00
parent 54b7af348b
commit a27e4603a8
4 changed files with 28 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ CREATE TABLE edit_group (
edit_group_id SERIAL PRIMARY KEY, edit_group_id SERIAL PRIMARY KEY,
name VARCHAR, name VARCHAR,
enabled SMALLINT NOT NULL DEFAULT 0, enabled SMALLINT NOT NULL DEFAULT 0,
deleted SMALLINT DEFAULT 0,
edit_scheme_id INT, edit_scheme_id INT,
edit_access_right_id INT NOT NULL, edit_access_right_id INT NOT NULL,
alternative_acl JSONB, alternative_acl JSONB,

View File

@@ -16,6 +16,7 @@ CREATE TABLE edit_user (
first_name_furigana VARCHAR, first_name_furigana VARCHAR,
last_name_furigana VARCHAR, last_name_furigana VARCHAR,
enabled SMALLINT NOT NULL DEFAULT 0, enabled SMALLINT NOT NULL DEFAULT 0,
deleted SMALLINT NOT NULL DEFAULT 0,
debug SMALLINT NOT NULL DEFAULT 0, debug SMALLINT NOT NULL DEFAULT 0,
db_debug SMALLINT NOT NULL DEFAULT 0, db_debug SMALLINT NOT NULL DEFAULT 0,
email VARCHAR, email VARCHAR,

View File

@@ -1259,9 +1259,10 @@ class IO extends \CoreLibs\Basic
// WAS : db_fetch_array // WAS : db_fetch_array
// PARAMS: cusors -> the cursor from db_exec or pg_query/pg_exec/mysql_query // PARAMS: cusors -> the cursor from db_exec or pg_query/pg_exec/mysql_query
// if not set will use internal cursor, if not found, stops with 0 (error) // if not set will use internal cursor, if not found, stops with 0 (error)
// assoc_only -> false is default, if true only assoc rows
// RETURN: a mixed row // RETURN: a mixed row
// DESC : executes a cursor and returns the data, if no more data 0 will be returned // DESC : executes a cursor and returns the data, if no more data 0 will be returned
public function dbFetchArray($cursor = 0) public function dbFetchArray($cursor = 0, $assoc_only = false)
{ {
// return false if no query or cursor set ... // return false if no query or cursor set ...
if (!$cursor) { if (!$cursor) {
@@ -1272,15 +1273,21 @@ class IO extends \CoreLibs\Basic
$this->__dbError(); $this->__dbError();
return false; return false;
} }
return $this->__dbConvertEncoding($this->db_functions->__dbFetchArray($cursor)); return $this->__dbConvertEncoding(
$this->db_functions->__dbFetchArray(
$cursor,
$this->db_functions->__dbResultType($assoc_only)
)
);
} }
// METHOD: dbReturnRow // METHOD: dbReturnRow
// WAS : db_return_row // WAS : db_return_row
// PARAMS: query -> the query to be executed // PARAMS: query -> the query to be executed
// assoc_only -> if true, only return assoc entry, else both (pgsql)
// RETURN: mixed db result // RETURN: mixed db result
// DESC : returns the FIRST row of the given query // DESC : returns the FIRST row of the given query
public function dbReturnRow($query) public function dbReturnRow($query, $assoc_only = false)
{ {
if (!$query) { if (!$query) {
$this->error_id = 11; $this->error_id = 11;
@@ -1294,7 +1301,7 @@ class IO extends \CoreLibs\Basic
return false; return false;
} }
$cursor = $this->dbExec($query); $cursor = $this->dbExec($query);
$result = $this->dbFetchArray($cursor); $result = $this->dbFetchArray($cursor, $assoc_only);
return $result; return $result;
} }

View File

@@ -190,6 +190,9 @@ class PgSQL
// DESC : wrapper for pg_fetch_array // DESC : wrapper for pg_fetch_array
public function __dbFetchArray($cursor, $result_type = '') public function __dbFetchArray($cursor, $result_type = '')
{ {
if ($result_type == true) {
$result_type = PGSQL_ASSOC;
}
// result type is passed on as is [should be checked] // result type is passed on as is [should be checked]
if ($result_type) { if ($result_type) {
return pg_fetch_array($cursor, null, $result_type); return pg_fetch_array($cursor, null, $result_type);
@@ -198,6 +201,18 @@ class PgSQL
} }
} }
// METHOD: __dbResultType
// PARAMS: true/false for ASSOC only or BOTH
// RETURN: PGSQL assoc type
// DESC : simple match up between assoc true/false
public function __dbResultType($assoc_type)
{
if ($assoc_type == true) {
return PGSQL_ASSOC;
}
return ''; // fallback to default
}
// METHOD: __dbFetchAll // METHOD: __dbFetchAll
// WAS : _db_fetch_all // WAS : _db_fetch_all
// PARAMS: cursor // PARAMS: cursor