php-cs-fixer for all the code
This commit is contained in:
@@ -117,7 +117,7 @@ class Dblayeroo
|
||||
$this->dsn = $dsn;
|
||||
switch ($driver[0]) {
|
||||
case "sqlite":
|
||||
// Look at the right to write in database and in the directory
|
||||
// Look at the right to write in database and in the directory
|
||||
$file = substr($dsn, 7);
|
||||
if (! is_writeable(dirname($file))) {
|
||||
$this->DBException(dgettext(
|
||||
@@ -138,8 +138,8 @@ class Dblayeroo
|
||||
) {
|
||||
chmod($file, 0666);
|
||||
}
|
||||
// Print the instances of PDO objects stored :
|
||||
// var_dump (self::$instance);
|
||||
// Print the instances of PDO objects stored :
|
||||
// var_dump (self::$instance);
|
||||
if (! array_key_exists($this->dsn, self::$instance)) {
|
||||
$this->debugLog("CONNECT TO SQLite DATABASE", 2);
|
||||
try {
|
||||
@@ -157,7 +157,7 @@ class Dblayeroo
|
||||
$this->DBException("PDO error : " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
// Force ForeignKeys support (disabled by default)
|
||||
// Force ForeignKeys support (disabled by default)
|
||||
self::$instance[$this->dsn]->exec("PRAGMA foreign_keys = ON");
|
||||
$this->sep = "`";
|
||||
if ($this->databasename() === null) {
|
||||
@@ -168,29 +168,29 @@ class Dblayeroo
|
||||
if (! array_key_exists($this->dsn, self::$instance)) {
|
||||
$this->debugLog("CONNECT TO MySQL DATABASE", 2);
|
||||
try {
|
||||
$driver_options[\PDO::MYSQL_ATTR_FOUND_ROWS] = 1;
|
||||
self::$instance[$this->dsn] = new \PDO(
|
||||
$dsn,
|
||||
$username,
|
||||
$password,
|
||||
$driver_options
|
||||
);
|
||||
self::$instance[$this->dsn]->setAttribute(
|
||||
\PDO::ATTR_ERRMODE,
|
||||
\PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
$driver_options[\PDO::MYSQL_ATTR_FOUND_ROWS] = 1;
|
||||
self::$instance[$this->dsn] = new \PDO(
|
||||
$dsn,
|
||||
$username,
|
||||
$password,
|
||||
$driver_options
|
||||
);
|
||||
self::$instance[$this->dsn]->setAttribute(
|
||||
\PDO::ATTR_ERRMODE,
|
||||
\PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$this->DBException("PDO error : " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Set the coding to UTF8
|
||||
// Set the coding to UTF8
|
||||
self::$instance[$this->dsn]->exec("SET CHARACTER SET utf8");
|
||||
$this->sep = "`";
|
||||
if ($this->databasename() === null) {
|
||||
$this->DBException("No Database provided in DSN");
|
||||
}
|
||||
// Force the GROUP_CONCAT value max to the max allowed from the server
|
||||
// Force the GROUP_CONCAT value max to the max allowed from the server
|
||||
$st = self::$instance[$this->dsn]->query(
|
||||
"SHOW VARIABLES LIKE 'max_allowed_packet'",
|
||||
\PDO::FETCH_COLUMN,
|
||||
@@ -212,22 +212,22 @@ class Dblayeroo
|
||||
if (! array_key_exists($this->dsn, self::$instance)) {
|
||||
$this->debugLog("CONNECT TO PGSQL DATABASE", 2);
|
||||
try {
|
||||
self::$instance[$this->dsn] = new \PDO(
|
||||
$dsn,
|
||||
$username,
|
||||
$password,
|
||||
$driver_options
|
||||
);
|
||||
self::$instance[$this->dsn]->setAttribute(
|
||||
\PDO::ATTR_ERRMODE,
|
||||
\PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
self::$instance[$this->dsn] = new \PDO(
|
||||
$dsn,
|
||||
$username,
|
||||
$password,
|
||||
$driver_options
|
||||
);
|
||||
self::$instance[$this->dsn]->setAttribute(
|
||||
\PDO::ATTR_ERRMODE,
|
||||
\PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$this->DBException("PDO error : " . $e->getMessage());
|
||||
$this->DBException("PDO error : " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Set the coding to UTF8
|
||||
// Set the coding to UTF8
|
||||
self::$instance[$this->dsn]->exec("SET NAMES 'utf8'");
|
||||
$this->sep = "\"";
|
||||
if ($this->databasename() === null) {
|
||||
@@ -335,7 +335,7 @@ class Dblayeroo
|
||||
$res = array();
|
||||
while ($d = $st->fetch(\PDO::FETCH_ASSOC)) {
|
||||
if ($d["name"] !== "sqlite_sequence") {
|
||||
$res[] = $d["name"];
|
||||
$res[] = $d["name"];
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -413,9 +413,9 @@ class Dblayeroo
|
||||
$i = 0;
|
||||
foreach ($this->fields as $field => $params) {
|
||||
if ($i > 0) {
|
||||
$sql .= ",\n";
|
||||
$sql .= ",\n";
|
||||
}
|
||||
// Name of field
|
||||
// Name of field
|
||||
$sql .= "$this->sep$field$this->sep ";
|
||||
switch ($this->fieldTypeLight($field)) {
|
||||
case "blob":
|
||||
@@ -431,8 +431,8 @@ class Dblayeroo
|
||||
$params = array_slice($params, 1);
|
||||
break;
|
||||
case "float":
|
||||
$sql .= "FLOAT";
|
||||
$params = array_slice($params, 1);
|
||||
$sql .= "FLOAT";
|
||||
$params = array_slice($params, 1);
|
||||
break;
|
||||
case "integer":
|
||||
$sql .= "INTEGER";
|
||||
@@ -453,18 +453,18 @@ class Dblayeroo
|
||||
$field
|
||||
), 500);
|
||||
}
|
||||
// Primary key
|
||||
// Primary key
|
||||
if ($this->primary === $field) {
|
||||
$sql .= " PRIMARY KEY";
|
||||
$sql .= " PRIMARY KEY";
|
||||
}
|
||||
// Others parameters for field
|
||||
// Sort to put the autoincrement field in front of params, if it is
|
||||
// present
|
||||
// Others parameters for field
|
||||
// Sort to put the autoincrement field in front of params, if it is
|
||||
// present
|
||||
sort($params);
|
||||
foreach ($params as $p) {
|
||||
switch ($p) {
|
||||
case "not null":
|
||||
$sql .= " NOT NULL";
|
||||
$sql .= " NOT NULL";
|
||||
break;
|
||||
case "autoincrement":
|
||||
if ($this->primary !== $field) {
|
||||
@@ -491,19 +491,19 @@ class Dblayeroo
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
// Unique fields
|
||||
// Unique fields
|
||||
if ($this->unique !== null) {
|
||||
if (!is_array($this->unique)) {
|
||||
$this->DBException(
|
||||
dgettext(
|
||||
"domframework",
|
||||
"The Unique field definition is not an array"
|
||||
),
|
||||
500
|
||||
);
|
||||
$this->DBException(
|
||||
dgettext(
|
||||
"domframework",
|
||||
"The Unique field definition is not an array"
|
||||
),
|
||||
500
|
||||
);
|
||||
}
|
||||
foreach ($this->unique as $u) {
|
||||
$sql .= ",\n UNIQUE ($this->sep";
|
||||
$sql .= ",\n UNIQUE ($this->sep";
|
||||
if (is_array($u)) {
|
||||
$sql .= implode("$this->sep,$this->sep", $u);
|
||||
} else {
|
||||
@@ -512,7 +512,7 @@ class Dblayeroo
|
||||
$sql .= "$this->sep)";
|
||||
}
|
||||
}
|
||||
// Foreign keys
|
||||
// Foreign keys
|
||||
$i = 0;
|
||||
foreach ($this->foreign as $field => $k) {
|
||||
$field = explode(",", $field);
|
||||
@@ -539,9 +539,9 @@ class Dblayeroo
|
||||
$i = 0;
|
||||
foreach ($this->fields as $field => $params) {
|
||||
if ($i > 0) {
|
||||
$sql .= ",\n";
|
||||
$sql .= ",\n";
|
||||
}
|
||||
// Name of field
|
||||
// Name of field
|
||||
$sql .= "$this->sep$field$this->sep ";
|
||||
switch ($this->fieldTypeLight($field)) {
|
||||
case "blob":
|
||||
@@ -558,8 +558,8 @@ class Dblayeroo
|
||||
$params = array_slice($params, 1);
|
||||
break;
|
||||
case "float":
|
||||
$sql .= "FLOAT";
|
||||
$params = array_slice($params, 1);
|
||||
$sql .= "FLOAT";
|
||||
$params = array_slice($params, 1);
|
||||
break;
|
||||
case "datetime":
|
||||
$sql .= "DATETIME";
|
||||
@@ -578,18 +578,18 @@ class Dblayeroo
|
||||
$field
|
||||
), 500);
|
||||
}
|
||||
// Primary key
|
||||
// Primary key
|
||||
if ($this->primary === $field) {
|
||||
$sql .= " PRIMARY KEY";
|
||||
$sql .= " PRIMARY KEY";
|
||||
}
|
||||
// Others parameters for field
|
||||
// Sort to put the autoincrement field in front of params, if it is
|
||||
// present
|
||||
// Others parameters for field
|
||||
// Sort to put the autoincrement field in front of params, if it is
|
||||
// present
|
||||
sort($params);
|
||||
foreach ($params as $p) {
|
||||
switch ($p) {
|
||||
case "not null":
|
||||
$sql .= " NOT NULL";
|
||||
$sql .= " NOT NULL";
|
||||
break;
|
||||
case "autoincrement":
|
||||
if ($this->primary !== $field) {
|
||||
@@ -616,10 +616,10 @@ class Dblayeroo
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
// Unique fields
|
||||
// Unique fields
|
||||
if ($this->unique !== null) {
|
||||
foreach ($this->unique as $u) {
|
||||
$sql .= ",\n UNIQUE ($this->sep";
|
||||
$sql .= ",\n UNIQUE ($this->sep";
|
||||
if (is_array($u)) {
|
||||
$sql .= implode("$this->sep,$this->sep", $u);
|
||||
} else {
|
||||
@@ -628,7 +628,7 @@ class Dblayeroo
|
||||
$sql .= "$this->sep)";
|
||||
}
|
||||
}
|
||||
// Foreign keys
|
||||
// Foreign keys
|
||||
$i = 0;
|
||||
foreach ($this->foreign as $field => $k) {
|
||||
$field = explode(",", $field);
|
||||
@@ -654,9 +654,9 @@ class Dblayeroo
|
||||
$i = 0;
|
||||
foreach ($this->fields as $field => $params) {
|
||||
if ($i > 0) {
|
||||
$sql .= ",\n";
|
||||
$sql .= ",\n";
|
||||
}
|
||||
// Name of field
|
||||
// Name of field
|
||||
$sql .= "\"$field\" ";
|
||||
if (in_array("autoincrement", $params)) {
|
||||
if ($this->primary !== $field) {
|
||||
@@ -668,25 +668,25 @@ class Dblayeroo
|
||||
$field
|
||||
), 500);
|
||||
}
|
||||
$sql .= "SERIAL";
|
||||
$sql .= "SERIAL";
|
||||
} else {
|
||||
switch ($this->fieldTypeLight($field)) {
|
||||
case "blob":
|
||||
$sql .= "BLOB";
|
||||
$params = array_slice($params, 1);
|
||||
$sql .= "BLOB";
|
||||
$params = array_slice($params, 1);
|
||||
break;
|
||||
case "integer":
|
||||
$sql .= "INTEGER";
|
||||
$params = array_slice($params, 1);
|
||||
$sql .= "INTEGER";
|
||||
$params = array_slice($params, 1);
|
||||
break;
|
||||
case "varchar":
|
||||
$length = $this->fieldLength($field);
|
||||
$sql .= "VARCHAR($length)";
|
||||
$params = array_slice($params, 1);
|
||||
$length = $this->fieldLength($field);
|
||||
$sql .= "VARCHAR($length)";
|
||||
$params = array_slice($params, 1);
|
||||
break;
|
||||
case "float":
|
||||
$sql .= "FLOAT";
|
||||
$params = array_slice($params, 1);
|
||||
$sql .= "FLOAT";
|
||||
$params = array_slice($params, 1);
|
||||
break;
|
||||
case "datetime":
|
||||
$sql .= "timestamp with time zone";
|
||||
@@ -705,13 +705,13 @@ class Dblayeroo
|
||||
$field
|
||||
), 500);
|
||||
}
|
||||
// Primary key
|
||||
// Primary key
|
||||
if ($this->primary === $field) {
|
||||
$sql .= " PRIMARY KEY";
|
||||
}
|
||||
// Others parameters for field
|
||||
// Sort to put the autoincrement field in front of params, if it is
|
||||
// present
|
||||
// Others parameters for field
|
||||
// Sort to put the autoincrement field in front of params, if it is
|
||||
// present
|
||||
sort($params);
|
||||
foreach ($params as $p) {
|
||||
switch ($p) {
|
||||
@@ -732,10 +732,10 @@ class Dblayeroo
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
// Unique fields
|
||||
// Unique fields
|
||||
if ($this->unique !== null) {
|
||||
foreach ($this->unique as $u) {
|
||||
$sql .= ",\n UNIQUE (\"";
|
||||
$sql .= ",\n UNIQUE (\"";
|
||||
if (is_array($u)) {
|
||||
$sql .= implode("\",\"", $u);
|
||||
} else {
|
||||
@@ -744,7 +744,7 @@ class Dblayeroo
|
||||
$sql .= "\")";
|
||||
}
|
||||
}
|
||||
// Foreign keys
|
||||
// Foreign keys
|
||||
$i = 0;
|
||||
foreach ($this->foreign as $field => $k) {
|
||||
$field = explode(",", $field);
|
||||
@@ -830,14 +830,14 @@ class Dblayeroo
|
||||
$st = self::$instance[$this->dsn]->prepare(
|
||||
"PRAGMA index_info(" . $c["name"] . ")"
|
||||
);
|
||||
$st->execute();
|
||||
$content2 = $st->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$st->execute();
|
||||
$content2 = $st->fetchAll(\PDO::FETCH_ASSOC);
|
||||
if (count($content2) > 1) {
|
||||
$index = array();
|
||||
$index = array();
|
||||
foreach ($content2 as $c2) {
|
||||
$index[] = $c2["name"];
|
||||
}
|
||||
$unique[$content2[0]["cid"] - 1] = $index;
|
||||
$unique[$content2[0]["cid"] - 1] = $index;
|
||||
} elseif (count($content2) === 1 && $content2[0]["cid"] >= 1) {
|
||||
$index = $content2[0]["name"];
|
||||
$unique[$content2[0]["cid"] - 1] = $index;
|
||||
@@ -855,10 +855,10 @@ class Dblayeroo
|
||||
$st->execute();
|
||||
$content = $st->fetchAll(\PDO::FETCH_ASSOC);
|
||||
if (count($content) > 0 && $primary !== "") {
|
||||
$fields[$primary][] = "autoincrement";
|
||||
$fields[$primary][] = "autoincrement";
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// If no autoincrement key, the sqlite_sequence table doesn't exists
|
||||
// If no autoincrement key, the sqlite_sequence table doesn't exists
|
||||
}
|
||||
|
||||
$st = self::$instance[$this->dsn]->prepare(
|
||||
@@ -876,7 +876,7 @@ class Dblayeroo
|
||||
$cascade .= "ON DELETE " . $for["on_delete"];
|
||||
}
|
||||
if ($cascade !== "") {
|
||||
$tmp[] = $cascade;
|
||||
$tmp[] = $cascade;
|
||||
}
|
||||
$foreign[$for["from"]] = $tmp;
|
||||
}
|
||||
@@ -903,7 +903,7 @@ class Dblayeroo
|
||||
"unique" => $unique,
|
||||
"foreign" => $foreign,
|
||||
"foreignUsed" => $foreignUsed);
|
||||
break;
|
||||
break;
|
||||
case "mysql":
|
||||
$st = self::$instance[$this->dsn]->prepare(
|
||||
"SHOW COLUMNS FROM `$tableName`"
|
||||
@@ -922,10 +922,10 @@ class Dblayeroo
|
||||
$tmp[] = $col["Type"];
|
||||
}
|
||||
if ($col["Null"] === "NO") {
|
||||
$tmp[] = "not null";
|
||||
$tmp[] = "not null";
|
||||
}
|
||||
if ($col["Extra"] === "auto_increment") {
|
||||
$tmp[] = "autoincrement";
|
||||
$tmp[] = "autoincrement";
|
||||
}
|
||||
$fields[$col["Field"]] = $tmp;
|
||||
}
|
||||
@@ -985,7 +985,7 @@ class Dblayeroo
|
||||
$tmp[2] .= "ON DELETE " . $f["DELETE_RULE"];
|
||||
}
|
||||
if ($tmp[2] !== "") {
|
||||
$tmp[2] = trim($tmp[2]);
|
||||
$tmp[2] = trim($tmp[2]);
|
||||
} else {
|
||||
unset($tmp[2]);
|
||||
}
|
||||
@@ -1015,13 +1015,13 @@ class Dblayeroo
|
||||
"unique" => $unique,
|
||||
"foreign" => $foreign,
|
||||
"foreignUsed" => $foreignUsed);
|
||||
break;
|
||||
break;
|
||||
case "pgsql":
|
||||
$fields = array();
|
||||
$unique = array();
|
||||
$foreign = array();
|
||||
$primary = "";
|
||||
// Get the defined primary key if not autoincrement
|
||||
// Get the defined primary key if not autoincrement
|
||||
$st = self::$instance[$this->dsn]->prepare("
|
||||
SELECT a.attname, format_type(a.atttypid, a.atttypmod) AS data_type
|
||||
FROM pg_index i
|
||||
@@ -1035,7 +1035,7 @@ class Dblayeroo
|
||||
if (key_exists(0, $content)) {
|
||||
$primary = $content[0]["attname"];
|
||||
}
|
||||
// Get the primary key if autoincrement
|
||||
// Get the primary key if autoincrement
|
||||
$st = self::$instance[$this->dsn]->prepare(
|
||||
"SELECT *
|
||||
FROM information_schema.columns
|
||||
@@ -1051,11 +1051,11 @@ class Dblayeroo
|
||||
$tmp[] = $col["data_type"];
|
||||
}
|
||||
if ($col["is_nullable"] === "NO") {
|
||||
$tmp[] = "not null";
|
||||
$tmp[] = "not null";
|
||||
}
|
||||
if (is_string($col["column_default"]) && substr($col["column_default"], 0, 7) === "nextval") {
|
||||
$tmp[] = "autoincrement";
|
||||
$primary = $col["column_name"];
|
||||
$tmp[] = "autoincrement";
|
||||
$primary = $col["column_name"];
|
||||
}
|
||||
$fields[$col["column_name"]] = $tmp;
|
||||
}
|
||||
@@ -1116,7 +1116,7 @@ class Dblayeroo
|
||||
$tmp[2] .= "ON DELETE " . $f["delete_rule"];
|
||||
}
|
||||
if ($tmp[2] !== "") {
|
||||
$tmp[2] = trim($tmp[2]);
|
||||
$tmp[2] = trim($tmp[2]);
|
||||
} else {
|
||||
unset($tmp[2]);
|
||||
}
|
||||
@@ -1158,7 +1158,7 @@ class Dblayeroo
|
||||
"unique" => $unique,
|
||||
"foreign" => $foreign,
|
||||
"foreignUsed" => $foreignUsed);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
$this->DBException(dgettext(
|
||||
"domframework",
|
||||
@@ -1172,7 +1172,7 @@ class Dblayeroo
|
||||
*/
|
||||
private function fieldTypeComplete($field)
|
||||
{
|
||||
// $this->debugLog ("Entering fieldTypeComplete (",$field,")", 2);
|
||||
// $this->debugLog ("Entering fieldTypeComplete (",$field,")", 2);
|
||||
if (! array_key_exists($field, $this->fields)) {
|
||||
$this->DBException(sprintf(
|
||||
"fieldType : can't find the definition for field '%s'",
|
||||
@@ -1335,7 +1335,7 @@ class Dblayeroo
|
||||
}
|
||||
if (
|
||||
$params[0] !== "integer" && (
|
||||
isset($params[1]) && $params[1] === "autoincrement" ||
|
||||
isset($params[1]) && $params[1] === "autoincrement" ||
|
||||
isset($params[2]) && $params[2] === "autoincrement"
|
||||
)
|
||||
) {
|
||||
@@ -2794,7 +2794,7 @@ class Dblayeroo
|
||||
if (! empty($this->limitExpression)) {
|
||||
$sql .= "\n LIMIT $this->limitExpression";
|
||||
}
|
||||
// No set Values for SELECT
|
||||
// No set Values for SELECT
|
||||
$this->setValues = array();
|
||||
break;
|
||||
case "INSERT":
|
||||
@@ -2805,7 +2805,7 @@ class Dblayeroo
|
||||
$i = 0;
|
||||
foreach ($this->setValues as $key => $val) {
|
||||
if ($i > 0) {
|
||||
$sql .= ",";
|
||||
$sql .= ",";
|
||||
}
|
||||
$sql .= $this->sep . $key . $this->sep;
|
||||
$i++;
|
||||
@@ -2820,7 +2820,7 @@ class Dblayeroo
|
||||
$i++;
|
||||
}
|
||||
$sql .= ")";
|
||||
// No WHERE in INSERT : remove the WHERE parameters
|
||||
// No WHERE in INSERT : remove the WHERE parameters
|
||||
$this->whereExpression = array();
|
||||
$this->whereValues = array();
|
||||
break;
|
||||
@@ -2836,7 +2836,7 @@ class Dblayeroo
|
||||
if (! empty($this->limitExpression)) {
|
||||
$sql .= " LIMIT $this->limitExpression";
|
||||
}
|
||||
// No set Values for DELETE
|
||||
// No set Values for DELETE
|
||||
$this->setValues = array();
|
||||
break;
|
||||
case "UPDATE":
|
||||
@@ -2848,7 +2848,7 @@ class Dblayeroo
|
||||
$i = 0;
|
||||
foreach ($this->setValues as $key => $val) {
|
||||
if ($i > 0) {
|
||||
$sql .= ",";
|
||||
$sql .= ",";
|
||||
}
|
||||
$hash = md5("$key, $val");
|
||||
$sql .= $this->sep . $key . $this->sep . "=:" . $hash;
|
||||
@@ -3127,7 +3127,7 @@ class Dblayeroo
|
||||
}
|
||||
switch ($this->fieldTypeLight($field)) {
|
||||
case "blob":
|
||||
// Blob can be anything. Do not test
|
||||
// Blob can be anything. Do not test
|
||||
break;
|
||||
case "integer":
|
||||
if (strspn($values[$field], "0123456789") !== strlen($values[$field])) {
|
||||
@@ -3551,13 +3551,13 @@ class Dblayeroo
|
||||
switch ($this->command) {
|
||||
case "SELECT":
|
||||
$result = $st->fetchAll(\PDO::FETCH_NUM);
|
||||
// There is no fetchAll corresponding to the columnName->value. Assign the
|
||||
// name to the value by index.
|
||||
// FETCH_ASSOC doesn't work in empty left join (return NULL instead of
|
||||
// the filled value)
|
||||
// There is no fetchAll corresponding to the columnName->value. Assign the
|
||||
// name to the value by index.
|
||||
// FETCH_ASSOC doesn't work in empty left join (return NULL instead of
|
||||
// the filled value)
|
||||
$fieldsAll = $this->fieldsAll(true);
|
||||
// If the displayed fields are all in the same table, remove the table
|
||||
// name in the columns
|
||||
// If the displayed fields are all in the same table, remove the table
|
||||
// name in the columns
|
||||
$cleanable = true;
|
||||
$cleanTable = "";
|
||||
foreach ($this->displayGet(true) as $display) {
|
||||
@@ -3567,26 +3567,26 @@ class Dblayeroo
|
||||
$matches
|
||||
);
|
||||
if ($cleanTable === "") {
|
||||
$cleanTable = $matches[1][0];
|
||||
$cleanTable = $matches[1][0];
|
||||
} elseif ($cleanTable !== $matches[1][0]) {
|
||||
$cleanable = false;
|
||||
break;
|
||||
$cleanable = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$columns = array_values($this->displayGet(true));
|
||||
// Get the columns names that will be displayed to user.
|
||||
// If the cleanable is possible, remove the table names
|
||||
// Get the columns names that will be displayed to user.
|
||||
// If the cleanable is possible, remove the table names
|
||||
$columnNames = array_combine($columns, $columns);
|
||||
//if ($this->joinObject === null && count ($this->displayGet (false)))
|
||||
//if ($this->joinObject === null && count ($this->displayGet (false)))
|
||||
if ($cleanable) {
|
||||
// Remove the table name as there is no collisions risk
|
||||
// In case of Alias, remove the $this->sep too
|
||||
// Remove the table name as there is no collisions risk
|
||||
// In case of Alias, remove the $this->sep too
|
||||
foreach ($columnNames as $key => $col) {
|
||||
// Remove the table and the separator if exists
|
||||
$col = preg_replace("#" . $this->sep . "[^" . $this->sep . "]+" .
|
||||
// Remove the table and the separator if exists
|
||||
$col = preg_replace("#" . $this->sep . "[^" . $this->sep . "]+" .
|
||||
$this->sep . "\.#U", "", $col);
|
||||
// Remove the separator if not table exists
|
||||
$col = str_replace($this->sep, "", $col);
|
||||
// Remove the separator if not table exists
|
||||
$col = str_replace($this->sep, "", $col);
|
||||
if ($col[0] === $this->sep) {
|
||||
$col = substr($col, 1);
|
||||
} elseif (strpos($col, "DISTINCT " . $this->sep) === 0) {
|
||||
@@ -3607,42 +3607,42 @@ class Dblayeroo
|
||||
}
|
||||
} else {
|
||||
foreach ($columnNames as $key => $col) {
|
||||
$columnNames[$key] = str_replace($this->sep, "", $col);
|
||||
$columnNames[$key] = str_replace($this->sep, "", $col);
|
||||
}
|
||||
}
|
||||
foreach ($result as $rownb => $row) {
|
||||
foreach ($row as $colNb => $val) {
|
||||
// Harmonize the fetchAll result between all the databases drivers
|
||||
// Harmonize the fetchAll result between all the databases drivers
|
||||
$pos = strpos($columns[$colNb], "(");
|
||||
if ($pos) {
|
||||
// Function. The function that return an int must be added in this
|
||||
// list, to cast correctely the value
|
||||
$func = strtoupper(trim(substr($columns[$colNb], 0, $pos)));
|
||||
// Function. The function that return an int must be added in this
|
||||
// list, to cast correctely the value
|
||||
$func = strtoupper(trim(substr($columns[$colNb], 0, $pos)));
|
||||
if (in_array($func, array("AVG", "COUNT", "MAX", "MIN", "SUM"))) {
|
||||
$val = intval($val);
|
||||
}
|
||||
} else {
|
||||
$name = $columns[$colNb];
|
||||
$pos = strpos($columns[$colNb], " AS ");
|
||||
$name = $columns[$colNb];
|
||||
$pos = strpos($columns[$colNb], " AS ");
|
||||
if ($pos) {
|
||||
$name = substr($columns[$colNb], 0, $pos);
|
||||
}
|
||||
$name = str_replace("DISTINCT ", "", $name);
|
||||
/*if ($cleanable)
|
||||
$name = str_replace ($this->sep.$this->tableprefix.$this->table.
|
||||
$this->sep.".", "", $name);*/
|
||||
$name = str_replace("DISTINCT ", "", $name);
|
||||
/*if ($cleanable)
|
||||
$name = str_replace ($this->sep.$this->tableprefix.$this->table.
|
||||
$this->sep.".", "", $name);*/
|
||||
if (
|
||||
strtolower($fieldsAll[$name][0]) === "integer" &&
|
||||
$val !== null
|
||||
strtolower($fieldsAll[$name][0]) === "integer" &&
|
||||
$val !== null
|
||||
) {
|
||||
$val = intval($val);
|
||||
}
|
||||
}
|
||||
if (($pos = strpos($columns[$colNb], " AS " . $this->sep)) !== false) {
|
||||
$pos += strlen(" AS " . $this->sep);
|
||||
$colName = substr($columns[$colNb], $pos, -1);
|
||||
$pos += strlen(" AS " . $this->sep);
|
||||
$colName = substr($columns[$colNb], $pos, -1);
|
||||
} else {
|
||||
$colName = $columnNames[$columns[$colNb]];
|
||||
$colName = $columnNames[$columns[$colNb]];
|
||||
}
|
||||
$result[$rownb][$colName] = $val;
|
||||
unset($result[$rownb][$colNb]);
|
||||
@@ -3664,8 +3664,8 @@ class Dblayeroo
|
||||
"displayQuery" => $this->getDisplayQuery(),
|
||||
"nbrows" => $st->rowCount(),
|
||||
);
|
||||
// If the primary key is not autoincrement, return the provided value if
|
||||
// exists
|
||||
// If the primary key is not autoincrement, return the provided value if
|
||||
// exists
|
||||
if (
|
||||
! in_array("autoincrement", $this->fields[$this->primary]) &&
|
||||
key_exists($this->primary, $this->setValues)
|
||||
@@ -3673,8 +3673,8 @@ class Dblayeroo
|
||||
return $this->setValues[$this->primary];
|
||||
}
|
||||
|
||||
// If the primary key is autoincrement and the provided value is not null
|
||||
// Return it
|
||||
// If the primary key is autoincrement and the provided value is not null
|
||||
// Return it
|
||||
if (
|
||||
in_array("autoincrement", $this->fields[$this->primary]) &&
|
||||
key_exists($this->primary, $this->setValues) &&
|
||||
@@ -3683,9 +3683,9 @@ class Dblayeroo
|
||||
return $this->setValues[$this->primary];
|
||||
}
|
||||
|
||||
// If the primary key is autoincrement and the provided value is null or
|
||||
// not provided, return the autoincremented value
|
||||
// PostGres need the name of the column autoincrement to return something
|
||||
// If the primary key is autoincrement and the provided value is null or
|
||||
// not provided, return the autoincremented value
|
||||
// PostGres need the name of the column autoincrement to return something
|
||||
$autoInc = null;
|
||||
if ($this->driver === "pgsql") {
|
||||
foreach ($this->fields as $col => $params) {
|
||||
|
||||
Reference in New Issue
Block a user