Skip to content

Commit

Permalink
* 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecc-business-account committed Jul 22, 2022
1 parent 4441b3d commit a1b6e81
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 76 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,8 @@ In a nutshell:
>
> Every decimal version means that it patches/fixes/refactoring a previous functionality i.e. 1.5.0 -> 1.5.1 (fix)
* 3.8 2022-07-22
* [ORM] fixed a problem when where is used and more than two column (different tables) use the same name of column.
* 3.7 2022-07-16
* [ORM] fixed a problem with first
* [ORM] fixed a problem with insert and conversion of columns
Expand Down
4 changes: 4 additions & 0 deletions examples/clitest/test_complete.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
$pdo->logLevel=3;
$pdo->open();
$pdo->setCacheService(new CacheServicesmysql());
new \dBug\dBug(InvoiceRepo::recursive(['/_InvCustomer'])->first(227));

new \dBug\dBug(InvoiceRepo::recursive(['/_InvCustomer'])->where("invoices.flag='1'")->toList());
new \dBug\dBug(InvoiceRepo::recursive(['/_InvCustomer'])->where(["FlagAlias"=>'1'])->toList());
die(1);


$id=224;
Expand Down
38 changes: 24 additions & 14 deletions examples/clitest/testdb2.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"namespace": null,
"savegen": "yes",
"tables": null,
"tablescolumns": null,
"tablecommand": null,
"convertionselected": "",
"convertionnewvalue": "convert an human readable date to SQL",
"tablescolumns": "",
"tablecommand": "",
"convertionselected": null,
"convertionnewvalue": null,
"newclassname": null,
"overridegenerate": null,
"tablexclass": {
Expand Down Expand Up @@ -85,7 +85,8 @@
"Name": null,
"_City": "MANYTOONE",
"_customerxcategories": "MANYTOMANY",
"_invoices": "PARENT"
"_invoices": "PARENT",
"Flag": null
},
"customerxcategories": {
"Category": null,
Expand All @@ -99,7 +100,8 @@
"Product": null,
"Quantity": null,
"_Invoice": "PARENT",
"_Product": "MANYTOONE"
"_Product": "MANYTOONE",
"Flag": null
},
"invoices": {
"Customer": null,
Expand All @@ -108,15 +110,17 @@
"Total": null,
"_Customer": "MANYTOONE",
"_invoicedetails": "ONETOMANY",
"_invoicextypes": "MANYTOMANY"
"_invoicextypes": "MANYTOMANY",
"Flag": null
},
"products": {
"City": null,
"IdProducts": null,
"_City": "MANYTOONE",
"_invoicedetails": "PARENT",
"Name": null,
"unitPrice": null
"unitPrice": null,
"Flag": null
},
"cities": {
"IdCity": null,
Expand All @@ -133,7 +137,8 @@
"invoicetypes": {
"IdInvoiceType": null,
"NameType": null,
"_invoicextypes": "ONETOMANY"
"_invoicextypes": "ONETOMANY",
"Flag": null
},
"invoicextypes": {
"IdInvoice": null,
Expand Down Expand Up @@ -166,7 +171,8 @@
"Product": "Product",
"Quantity": "Quantity",
"_Invoice": "_Invoice",
"_Product": "_Product"
"_Product": "_Product",
"Flag": "Flag"
},
"invoices": {
"Customer": "Customer",
Expand All @@ -175,15 +181,17 @@
"Total": "Total",
"_Customer": "_InvCustomer",
"_invoicedetails": "_Details",
"_invoicextypes": "_Types"
"_invoicextypes": "_Types",
"Flag": "FlagAlias"
},
"products": {
"City": "Ciudad",
"IdProducts": "Numproduct",
"Name": "Name",
"unitPrice": "unitPrice",
"_City": "_CiudadRef",
"_invoicedetails": "_invoicedetails"
"_invoicedetails": "_invoicedetails",
"Flag": "Flag"
},
"customers": {
"City": "City",
Expand All @@ -192,7 +200,8 @@
"Name": "Name",
"_City": "_City",
"_customerxcategories": "_customerxcategories",
"_invoices": "_invoices"
"_invoices": "_invoices",
"Flag": "FlagAlias"
},
"users": {
"fullname": "fullname",
Expand All @@ -203,7 +212,8 @@
"invoicetypes": {
"IdInvoiceType": "NumInvoiceType",
"NameType": "NameType",
"_invoicextypes": "_invoicextypes"
"_invoicextypes": "_invoicextypes",
"Flag": "Flag"
},
"invoicextypes": {
"IdInvoice": "Col1X",
Expand Down
93 changes: 54 additions & 39 deletions lib/PdoOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
* @package eftec
* @author Jorge Castro Castillo
* @copyright (c) Jorge Castro C. Dual Licence: MIT and Commercial License https://github.com/EFTEC/PdoOne
* @version 3.7
* @version 3.8
*/
class PdoOne
{
public const VERSION = '3.7';
public const VERSION = '3.8';
/** @var int We need this value because null and false could be a valid value. */
public const NULL = PHP_INT_MAX;
/** @var string Prefix of the tables */
Expand Down Expand Up @@ -128,7 +128,7 @@ class PdoOne
public $customError = true;
/** @var string[] PHP classes excluded by the custom error log todo: quitar */
public $traceBlackList = []; //['PdoOne.php', 'PdoOneQuery.php', 'PdoOne_Mysql.php', 'PdoOne.Sqlsrv.php', 'PdoOne.Oci.php'
//, 'PdoOneTestMockup.php', '_BasePdoOneRepo.php'];
//, 'PdoOneTestMockup.php', '_BasePdoOneRepo.php'];
/** @var PDO */
public $conn1;
/** @var bool True if the transaction is open */
Expand Down Expand Up @@ -295,9 +295,11 @@ public static function newColFK($key, $refcol, $reftable, $extra = null, $name =
* @param string $sql
* @return array|string|string[]
*/
public static function cleanColumns(string $sql) {
return str_replace([chr(0),chr(8),chr(9),chr(13),"'",'"',chr(26),chr(92)],'',$sql);
public static function cleanColumns(string $sql)
{
return str_replace([chr(0), chr(8), chr(9), chr(13), "'", '"', chr(26), chr(92)], '', $sql);
}

public static function addParenthesis($txt, $start = '(', $end = ')')
{
if (self::hasParenthesis($txt, $start, $end) === false) {
Expand Down Expand Up @@ -1377,14 +1379,14 @@ public function custom_exception_handler($exception, ?string $customMessage = nu
} else {
$function = @$error['function'];
}
$r .= '<<<'.$file . ':' . @$error['line'] . ">>>\t" . $function . '('
$r .= '<<<' . $file . ':' . @$error['line'] . ">>>\t" . $function . '('
. @implode(' , ', $args) . ')' . "\n";
}
}
}
if (!$isCli) {
$r = str_replace(["\n", '[', ']','<<<','>>>', '{{', '}}', "\t"]
, ["<br>", "<b>[", "]</b>",'<span style="background-color:blue; color:white">','</span>', '<u>', '</u>', '&nbsp;&nbsp;&nbsp;&nbsp;']
$r = str_replace(["\n", '[', ']', '<<<', '>>>', '{{', '}}', "\t"]
, ["<br>", "<b>[", "]</b>", '<span style="background-color:blue; color:white">', '</span>', '<u>', '</u>', '&nbsp;&nbsp;&nbsp;&nbsp;']
, $r);
}
if (!$returnAsString) {
Expand Down Expand Up @@ -1458,11 +1460,17 @@ public function setMessages(MessageContainer $messageContainer): void
$this->messageContainer = $messageContainer;
}

public function debugFile($txt, $level = 'INFO'): void
/**
* @param mixed $txt the message to send. If it is an object or an array, then it is serialized.
* @param string $level The level of the message
* @return void
*/
public function debugFile($txt, string $level = 'INFO'): void
{
if (!$this->logFile) {
return; // debug file is disabled.
}
$maxl=200*1024*1024; // 200mb
if (is_object($txt) || is_array($txt)) {
$txtW = print_r($txt, true);
} else {
Expand All @@ -1471,8 +1479,24 @@ public function debugFile($txt, $level = 'INFO'): void
if ($this->logLevel === 2) {
$txtW .= ' param:' . json_encode($this->lastParam);
}
/** @noinspection ForgottenDebugOutputInspection */
error_log('[PdoOne]' . $level . "\t" . $txtW);
if($level==='INFO') {
$errorfile=ini_get('error_log');
if($errorfile) {
$infoFile=str_replace('.','_warning.',$errorfile);
if(@filesize($infoFile)>$maxl) {
$fp = @fopen($infoFile, 'wb');
@fclose($fp);
}
/** @noinspection ForgottenDebugOutputInspection */
error_log('['.date("M d H:i:s")."] [PdoOne]\t[$level]\t$txtW\n\n", 3,$infoFile);
} else {
/** @noinspection ForgottenDebugOutputInspection */
error_log("[PdoOne]\t[$level]\t" . $txtW);
}
} else {
/** @noinspection ForgottenDebugOutputInspection */
error_log("[PdoOne]\t[$level]\t" . $txtW);
}
}

//<editor-fold desc="transaction functions">
Expand Down Expand Up @@ -2398,14 +2422,15 @@ public static function varExport($input, $indent = "\t"): ?string
}

/**
* @param string $tableName
* @param string $tableName
* @param array|null $columnRelations
* @param $pkFirst
* @param array $aliasesAllTables
* @param $pkFirst
* @param array $aliasesAllTables
* @return array|string
* @throws Exception
*/
public function generateGetRelations(string $tableName,?array $columnRelations,$pkFirst,array $aliasesAllTables):array {
public function generateGetRelations(string $tableName, ?array $columnRelations, $pkFirst, array $aliasesAllTables): array
{
try {
$deps = $this->tableDependency(true);
} catch (Exception $e) {
Expand Down Expand Up @@ -2477,14 +2502,14 @@ public function generateGetRelations(string $tableName,?array $columnRelations,$
$defsFK = $this->service->getDefTableFK($relation[$k]['reftable'], false);
} catch (Exception $e) {
$this->endTry();
return ['Error: Unable read table dependencies ' . $e->getMessage(),null];
return ['Error: Unable read table dependencies ' . $e->getMessage(), null];
}
try {
$keys2 = $this->service->getDefTableKeys($defsFK[$refcol2]['reftable'], true,
'PRIMARY KEY');
} catch (Exception $e) {
$this->endTry();
return ['Error: Unable read table dependencies' . $e->getMessage(),null];
return ['Error: Unable read table dependencies' . $e->getMessage(), null];
}
$relation[$k]['refcol2'] = self::$prefixBase . $refcol2;
if (count($keys2) > 0) {
Expand All @@ -2503,16 +2528,13 @@ public function generateGetRelations(string $tableName,?array $columnRelations,$
$linked = '';
foreach ($relation as $k => $v) {
$ksimple = ltrim($k, '_'); // remove the _ from the beginner

$alias = ($aliases[$k] ?? $k);
$aliasCol = '_' . ($aliases[$ksimple] ?? $ksimple);
$col = ltrim($aliasCol, '_');
$refcol = ltrim($v['refcol'], '_');
$refcol2 = isset($v['refcol2']) ? ltrim($v['refcol2'], '_') : null;
$col2 = $v['col2'] ?? null;

$aliasRef = '_' . @$aliasesAllTables[$v['reftable']][$refcol] ?? $refcol;

$relation[$k]['alias'] = $alias;
if (isset($v['col'])) {
$relation[$k]['colalias'] = $aliases[$v['col']];
Expand Down Expand Up @@ -2556,8 +2578,9 @@ public function generateGetRelations(string $tableName,?array $columnRelations,$
);
}
}
return [$relation,$linked];
return [$relation, $linked];
}

/**
* It generates a class<br>
* <b>Example:</b><br>
Expand Down Expand Up @@ -2684,21 +2707,15 @@ public function generateAbstractRepo(
), $r);
$pk = $this->service->getPK($tableName, '??');
$pkFirst = (is_array($pk) && count($pk) > 0) ? $pk[0] : null;



[$relation,$linked]=$this->generateGetRelations($tableName,$columnRelations,$pkFirst,$aliasesAllTables);
if(!is_array($relation)) {
[$relation, $linked] = $this->generateGetRelations($tableName, $columnRelations, $pkFirst, $aliasesAllTables);
if (!is_array($relation)) {
$this->endTry();
return 'Error: Unable read fk of table ' . $relation;
}
/* } catch (Exception $e) {
$this->endTry();
return 'Error: Unable read fk of table ' . $e->getMessage();
}*/



/* } catch (Exception $e) {
$this->endTry();
return 'Error: Unable read fk of table ' . $e->getMessage();
}*/
//die(1);
$convertOutput = '';
$convertInput = '';
Expand Down Expand Up @@ -2838,7 +2855,6 @@ public function generateAbstractRepo(
$convertOutput .= "\t\t" . str_replace('%s', "\$row['$alias']", $tmp) . "\n";
}
}

//$convertOutput.=$linked;
$convertOutput = rtrim($convertOutput, "\n");
$convertInput = rtrim($convertInput, "\n");
Expand All @@ -2859,7 +2875,6 @@ public function generateAbstractRepo(
$noUpdate = array_merge($identities, $defNoUpdate);
} else {
$noUpdate = $identities;

}
/*$copy = $noInsert;
$noInsert = [];
Expand Down Expand Up @@ -2887,7 +2902,7 @@ public function generateAbstractRepo(
$relation2 = [];
foreach ($relation as $arr) {
if ($arr['key'] !== 'FOREIGN KEY' && $arr['key'] !== 'PARENT' && $arr['key'] !== 'NONE') {
@$relation2[$arr['key']][] = '/'.$arr['alias'];
@$relation2[$arr['key']][] = '/' . $arr['alias'];
}
//if($arr['key']==='MANYTOONE') {
// $relation2[]=$col;
Expand Down Expand Up @@ -3164,9 +3179,9 @@ public function rollback(bool $throw = true): bool
}
$this->transactionOpen = false;
try {
$r = @$this->conn1->rollback();
} catch(Exception $ex) {
$r=false;
$r = @$this->conn1->rollback();
} catch (Exception $ex) {
$r = false;
}
$this->endTry();
return $r;
Expand Down
4 changes: 2 additions & 2 deletions lib/PdoOneCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
* @package eftec
* @author Jorge Castro Castillo
* @copyright (c) Jorge Castro C. Dual Licence: MIT and Commercial License https://github.com/EFTEC/PdoOne
* @version 1.1
* @version 1.2
*/
class PdoOneCli
{
public const VERSION = '1.1';
public const VERSION = '1.2';
//</editor-fold>
/**
* @var array
Expand Down
4 changes: 2 additions & 2 deletions lib/PdoOneEncryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* This class is used for encryption. It could encrypt (two ways).
* Class PdoOneEncryption
* @version 2.22.1 2022-01-30
* @version 3.8
* @package eftec
* @author Jorge Castro Castillo
* @copyright (c) Jorge Castro C. Dual Licence: MIT and Commercial License https://github.com/EFTEC/PdoOne
Expand Down Expand Up @@ -145,7 +145,7 @@ public function encrypt($data)
* It generates a hash based in the hash type ($this->hashType), the data used and the SALT.
*
* @param mixed $data It could be any type of serializable data.
* @return false|string If the serialization is not set, then it returns the same value.
* @return string If the serialization is not set, then it returns the same value.
*/
public function hash($data)
{
Expand Down
Loading

0 comments on commit a1b6e81

Please sign in to comment.