This commit is contained in:
2023-04-14 20:52:27 +02:00
parent 84e2b419c8
commit 5b56197aaa
14 changed files with 102 additions and 73 deletions

View File

@@ -351,12 +351,12 @@ class Dblayeroo
if ($this->sep === "") {
$this->DBException(dgettext("domframework", "Database not connected"));
}
$res = [];
switch (self::$instance[$this->dsn]->getAttribute(\PDO::ATTR_DRIVER_NAME)) {
case "sqlite":
$req = "SELECT name FROM sqlite_master WHERE type='table'";
$st = self::$instance[$this->dsn]->prepare($req);
$st->execute();
$res = [];
while ($d = $st->fetch(\PDO::FETCH_ASSOC)) {
if ($d["name"] !== "sqlite_sequence") {
$res[] = $d["name"];
@@ -369,7 +369,6 @@ class Dblayeroo
WHERE TABLE_SCHEMA='" . $this->databasename() . "'";
$st = self::$instance[$this->dsn]->prepare($req);
$st->execute();
$res = [];
while ($d = $st->fetch(\PDO::FETCH_ASSOC)) {
$res[] = $d["TABLE_NAME"];
}
@@ -380,7 +379,6 @@ class Dblayeroo
WHERE schemaname = 'public'";
$st = self::$instance[$this->dsn]->prepare($req);
$st->execute();
$res = [];
while ($d = $st->fetch(\PDO::FETCH_ASSOC)) {
$res[] = $d["tablename"];
}
@@ -430,6 +428,7 @@ class Dblayeroo
"No table name defined to create the table"
), 500);
}
$sql = "";
switch (self::$instance[$this->dsn]->getAttribute(\PDO::ATTR_DRIVER_NAME)) {
case "sqlite":
$sql = "CREATE TABLE IF NOT EXISTS " .
@@ -1684,7 +1683,7 @@ class Dblayeroo
}
@list($func, $param) = explode("(", $realType);
$func = trim($func);
$method = "checkRealType_" . $func;
$method = "checkRealType" . ucfirst($func);
if (! method_exists($this, $method)) {
$this->DBException("Invalid setRealType provided : " .
"field '$field' : unknown realType provided '$func'");
@@ -2008,10 +2007,10 @@ class Dblayeroo
}
$display = $name = trim($display);
$pos = strpos($display, "(");
$separator = "";
if ($pos !== false) {
$func = strtoupper(trim(substr($name, 0, $pos)));
$name = trim(substr($name, $pos + 1, -1));
$separator = "";
if (
in_array($func, ["AVG", "COUNT", "GROUP_CONCAT", "MAX",
"MIN","SUM"], true)
@@ -2848,6 +2847,7 @@ class Dblayeroo
"The unique configuration is not an array"
));
}
$sql = "";
switch ($this->command) {
case "SELECT":
$sql = "SELECT";
@@ -2980,7 +2980,7 @@ class Dblayeroo
try {
$st = self::$instance[$this->dsn]->prepare($sql);
} catch (\Exception $e) {
$this->DBException($e->getMessage());
throw $this->DBException($e->getMessage());
}
}
foreach ($this->whereGetValues() as $hash => $val) {
@@ -3053,7 +3053,7 @@ class Dblayeroo
$text .= "(date)\n";
} else {
$text .= "(UNKNOWN)\n";
$this->DBException("TO BE DEVELOPPED : " . $fields[$field][0]);
$this->DBException("TO BE DEVELOPPED : Unknown type : " . $type);
}
if (!$textForm) {
if ($value === null) {
@@ -3306,6 +3306,7 @@ class Dblayeroo
}
$setValues = $values;
$foundImpactedLines = 0;
$resUpdate = [];
foreach ($uniques as $k => $columns) {
if ($update) {
// Can not update multiple UNIQUE rows with the same value
@@ -3314,7 +3315,7 @@ class Dblayeroo
} elseif (is_array($columns)) {
$cols = $columns;
} else {
$this->DBException(dgettext(
throw $this->DBException(dgettext(
"domframework",
"Unique def is not a string or an array"
));
@@ -3592,7 +3593,7 @@ class Dblayeroo
$val = trim($values[$field]);
@list($func, $param) = explode("(", $this->realTypes[$field]);
$func = trim($func);
$method = "checkRealType_" . $func;
$method = "checkRealType" . ucfirst($func);
$res = $this->$method($val, $this->realTypes[$field]);
if (is_string($res)) {
$errors[$field] = $res;
@@ -3796,7 +3797,7 @@ class Dblayeroo
break;
}
}
if ($autoInc !== null) {
if ($autoInc !== null && isset($col)) {
$autoInc = $this->table . "_{$col}_seq";
}
}
@@ -3912,7 +3913,7 @@ class Dblayeroo
* @param string $definition The definition of the type
* @return string or null
*/
private function checkRealType_integerPositive($val, $definition)
private function checkRealTypeIntegerPositive($val, $definition)
{
if (substr($val, 0, 1) === "-") {
return dgettext("domframework", "Invalid positive integer : " .
@@ -3935,7 +3936,7 @@ class Dblayeroo
* @param string $definition The definition of the type
* @return string or null
*/
private function checkRealType_integer($val, $definition)
private function checkRealTypeInteger($val, $definition)
{
if (strspn($val, "0123456789-") !== strlen($val)) {
return dgettext("domframework", "Invalid integer : " .
@@ -3959,7 +3960,7 @@ class Dblayeroo
* @param string $definition The definition of the type
* @return string or null
*/
private function checkRealType_allowedchars($val, $definition)
private function checkRealTypeAllowedchars($val, $definition)
{
list($func, $param) = explode("(", $definition);
if ($param === null) {
@@ -3988,7 +3989,7 @@ class Dblayeroo
* @param string $definition The definition of the type
* @return string or null
*/
private function checkRealType_array($val, $definition)
private function checkRealTypeArray($val, $definition)
{
list($func, $param) = explode("(", $definition);
if ($param === null) {
@@ -4018,7 +4019,7 @@ class Dblayeroo
* @param string $definition The definition of the type
* @return string or null
*/
private function checkRealType_regex($val, $definition)
private function checkRealTypeRegex($val, $definition)
{
list($func, $param) = explode("(", $definition);
if ($param === null) {
@@ -4047,7 +4048,7 @@ class Dblayeroo
* @param string $definition The definition of the type
* @return string or null
*/
private function checkRealType_mail($val, $definition)
private function checkRealTypeMail($val, $definition)
{
if (!! filter_var($val, FILTER_VALIDATE_EMAIL)) {
return;
@@ -4059,9 +4060,9 @@ class Dblayeroo
* Check the type "uuid"
* @param string $val The value to check
* @param string $definition The definition of the type
* @return string or null
* @return string|null
*/
private function checkRealType_uuid($val, $definition)
private function checkRealTypeUuid($val, $definition)
{
if (strlen($val) !== 36) {
return dgettext("domframework", "Invalid UUID provided : " .
@@ -4082,9 +4083,9 @@ class Dblayeroo
* Check the type "sqldate"
* @param string $val The value to check
* @param string $definition The definition of the type
* @return string or null
* @return string|null
*/
private function checkRealType_sqldate($val, $definition)
private function checkRealTypeSqldate($val, $definition)
{
if (strlen($val) !== 10) {
return dgettext("domframework", "Invalid date provided : " .
@@ -4117,9 +4118,9 @@ class Dblayeroo
* Check the type "sqltime"
* @param string $val The value to check
* @param string $definition The definition of the type
* @return string or null
* @return string|null
*/
private function checkRealType_sqltime($val, $definition)
private function checkRealTypeSqltime($val, $definition)
{
if (strlen($val) !== 8) {
return dgettext("domframework", "Invalid time provided : " .
@@ -4152,9 +4153,9 @@ class Dblayeroo
* Check the type "sqldatetime"
* @param string $val The value to check
* @param string $definition The definition of the type
* @return string or null
* @return string|null
*/
private function checkRealType_sqldatetime($val, $definition)
private function checkRealTypeSqldatetime($val, $definition)
{
if (strlen($val) !== 19) {
return dgettext("domframework", "Invalid date and time provided : " .