Skip to content

Commit 3681661

Browse files
4.9.1
1 parent a185263 commit 3681661

File tree

4 files changed

+82
-52
lines changed

4 files changed

+82
-52
lines changed

README.md

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,22 +1876,27 @@ In a nutshell:
18761876
> Every minor version means that it adds a new functionality i.e. 1.5 -> 1.6 (new methods)
18771877
>
18781878
> Every decimal version means that it patches/fixes/refactoring a previous functionality i.e. 1.5.0 -> 1.5.1 (fix)
1879+
1880+
* 4.9.1 2024-08-20
1881+
* **[fix]** fixed a bug with where, where the value is null.
1882+
* 4.9: $this->...->where('col',null); // select * from table where col=null (invalid query)
1883+
* 4.9.1: $this->...->where('col',null); // select * from table where col is null (valid)
18791884
* 4.9 2024-08-02
1880-
* [update] camelize update to consider "-" and "\_" and not only "\_"
1881-
* [update] update dependencies.
1885+
* **[upd]** camelize update to consider "-" and "\_" and not only "\_"
1886+
* **[upd]** update dependencies.
18821887
* 4.8 2024-07-06
1883-
* [upd] added fetchMode for runRawQuery()
1884-
* [new] added setFetchMode()
1885-
* [new] PdoOneQuery added runRawQuery() which is a wrapper of PdoOne::runRawQuery()
1888+
* **[upd]** added fetchMode for runRawQuery()
1889+
* **[new]** added setFetchMode()
1890+
* **[new]** PdoOneQuery added runRawQuery() which is a wrapper of PdoOne::runRawQuery()
18861891
* 4.7.1 2024-06-07
1887-
* [fix] ixed a phpdoc in PdoOneQuery::where()
1892+
* **[fix]** Fixed a phpdoc in PdoOneQuery::where()
18881893
* 4.7 2024-06-07
1889-
* [upd] Update phpdoc using markdown without "php" because PHPStorm is not compatible with it.
1894+
* **[upd]** Update phpdoc using markdown without "php" because PHPStorm is not compatible with it.
18901895
* 4.6.2 2024-03-02
1891-
* [fix]PdoOne::$cacheService is now mixed.
1896+
* **[fix]** PdoOne::$cacheService is now mixed.
18921897
* 4.6.1 2024-03-02
1893-
* [fix]PdoOne::$instance is null by default (instead of undefined)
1894-
* [upd] updated CliOne dependency.
1898+
* **[fix]** PdoOne::$instance is null by default (instead of undefined)
1899+
* **[upd]** updated CliOne dependency.
18951900
* 4.6 2024-03-02
18961901
* Updating dependency to PHP 7.4. The extended support of PHP 7.2 ended 3 years ago.
18971902
* Added more type hinting in the code.
@@ -2032,41 +2037,41 @@ it as a PHP file.
20322037
class.**
20332038

20342039
* 2.26 2022-02-19
2035-
* **[core]** **[new]** added more type hiting for the arguments for safety and stability of the tool.
2040+
* **[core]** ****[new]**** added more type hiting for the arguments for safety and stability of the tool.
20362041
* **[cli]** now the CLI is located a different file called pdoonecli Also the CLI has more features than before,
20372042
including the generation of the OOP classes.
20382043

20392044
* 2.25 2022-02-01
2040-
* **[core]** **[new]** Key-Value functionalities:setKvDefaultTable(),kv(),createTableKV(),dropTableKV(),getKV()
2045+
* **[core]** ****[new]**** Key-Value functionalities:setKvDefaultTable(),kv(),createTableKV(),dropTableKV(),getKV()
20412046
,setKV(),garbageCollectorKV(),delKV(),flushKV(),existKV()
2042-
* **[core]** **[new]** createIndex()
2047+
* **[core]** ****[new]**** createIndex()
20432048

20442049
* 2.24.1 2022-02-06
20452050

2046-
* **[core]** **[fix]** Now, most generation of classes are defined in templates instead of the code. It will keep
2051+
* **[core]** ****[fix]**** Now, most generation of classes are defined in templates instead of the code. It will keep
20472052
the code clean while it will also save a few bits of memories (old: 6446 lines, current: 5963 lines).
20482053

20492054
* 2.24 2022-02-06
20502055

20512056
* **[repo]** Now the library allows multiple connections using different repository class bases.
20522057
* **[_BasePdoOne]** Updated to version 7. **You must rebuild the repository classes to rebuild the base class.**
2053-
* **[core]** **[new]** Now **MessageContainer** is injected automatically
2054-
* **[core]** **[new]** You can obtain an instance of PdoOne using the static method PdoOne::instance()
2055-
* **[core]** **[fix]** Method lastError() always returns a string (empty if not error) instead of a NULL.
2058+
* **[core]** ****[new]**** Now **MessageContainer** is injected automatically
2059+
* **[core]** ****[new]**** You can obtain an instance of PdoOne using the static method PdoOne::instance()
2060+
* **[core]** ****[fix]**** Method lastError() always returns a string (empty if not error) instead of a NULL.
20562061
* **[core]** **[change]** <u>Method getMessages() rename to getMessageContainer()</u>
2057-
* **[core]** **[new]** Method getMessages() returns all the messages.
2058-
* **[core]** **[new]** Method getErrors(),getFirstError(),getLastError(),hasError() return error messages.
2059-
* **[core]** **[new]** Method getInfos(),getFirstInfo(),getLastInfo() return info messages.
2062+
* **[core]** ****[new]**** Method getMessages() returns all the messages.
2063+
* **[core]** ****[new]**** Method getErrors(),getFirstError(),getLastError(),hasError() return error messages.
2064+
* **[core]** ****[new]**** Method getInfos(),getFirstInfo(),getLastInfo() return info messages.
20602065

20612066
* 2.23 2022-02-04
20622067

2063-
* **[PdoOneQuery]** **[PdoOne]** **[fix]** Fixed compatibility with PHP 8.1. PHP 8.1 deprecates a lot of
2068+
* **[PdoOneQuery]** **[PdoOne]** ****[fix]**** Fixed compatibility with PHP 8.1. PHP 8.1 deprecates a lot of
20642069
functionalities.
2065-
* **[new]** update dependency to php>=7.2.5 to stay in sync with Composer. If you have trouble, then you can use an
2070+
* ****[new]**** update dependency to php>=7.2.5 to stay in sync with Composer. If you have trouble, then you can use an
20662071
old version of the library
20672072

20682073
* 2.22.2 2022-02-01
2069-
* **[PdoOneQuery]** **[fix]** when the argument of a method is empty or zero. Now, it throws an exception.
2074+
* **[PdoOneQuery]** ****[fix]**** when the argument of a method is empty or zero. Now, it throws an exception.
20702075

20712076
* 2.22.1 2022-01-03
20722077
* **[core]** **[edit]** generateAllClasses() now returns errors and warnings.
@@ -2077,48 +2082,48 @@ it as a PHP file.
20772082
* **[_BasePdoOne]** **[edit]** the method page() allows to specify the size of the page.
20782083

20792084
* 2.21 2022-01-28
2080-
* **[core]** **[fix]** method singularTable() is now more exact to convert plural names to singular.
2085+
* **[core]** ****[fix]**** method singularTable() is now more exact to convert plural names to singular.
20812086
* However, it is far from perfect.
20822087
* **[_BasePdoOne]** [fixed] now several methods store the last error.
20832088

20842089
* 2.20 2022-01-04
2085-
* **[new]** update dependency to php>=7.1.3. PHP 5.6 was discontinued 3 years ago.
2090+
* ****[new]**** update dependency to php>=7.1.3. PHP 5.6 was discontinued 3 years ago.
20862091

20872092
* 2.19
2088-
* **[new]** **[core]** callProcedure() could return a value other than true or false (SQL server only)
2089-
* **[new]** **[sqlsrv]** implemented callProcedure() and createProcedure()
2093+
* ****[new]**** **[core]** callProcedure() could return a value other than true or false (SQL server only)
2094+
* ****[new]**** **[sqlsrv]** implemented callProcedure() and createProcedure()
20902095

20912096
* 2.18
2092-
* **[new]** [oci] added oci (oracle) as a new driver.
2093-
* **[fix]** **[core]** dbTypeToPHP() and datesql2Text()
2094-
* **[new]** **[core]** clearError(),removeDoubleQuotes() and a new argument for connect()
2097+
* ****[new]**** [oci] added oci (oracle) as a new driver.
2098+
* ****[fix]**** **[core]** dbTypeToPHP() and datesql2Text()
2099+
* ****[new]**** **[core]** clearError(),removeDoubleQuotes() and a new argument for connect()
20952100

20962101
* 2.16
2097-
* **[fix]** **[sqlsrv]** fixed the format of the date-time of sql.
2098-
* **[fix]** **[sqlsrv]** columnTable() returns distinct values.
2102+
* ****[fix]**** **[sqlsrv]** fixed the format of the date-time of sql.
2103+
* ****[fix]**** **[sqlsrv]** columnTable() returns distinct values.
20992104

21002105
* 2.15 2021-07-24
21012106

21022107
* 2.14.3 2021-06-15
2103-
* **[fix]** **[orm]** setCache()::first() and setCache()::count() didn't work correctly. fixed.
2108+
* ****[fix]**** **[orm]** setCache()::first() and setCache()::count() didn't work correctly. fixed.
21042109
* Query now supports factoryNull()
21052110

21062111
* 2.14.2 2021-06-13
2107-
* **[fix]** **[orm]** useCache() and setRelation() do not chain correctly, fixed.
2108-
* **[fix]** **[orm]** useCache() doubled the cache. fixed.
2112+
* ****[fix]**** **[orm]** useCache() and setRelation() do not chain correctly, fixed.
2113+
* ****[fix]**** **[orm]** useCache() doubled the cache. fixed.
21092114

21102115
* 2.14.1 2021-06-09
2111-
* **[fix]** custom_exception_handler when the error returned does not have an argument, or the argument is not an
2116+
* ****[fix]**** custom_exception_handler when the error returned does not have an argument, or the argument is not an
21122117
array.
21132118

21142119
* 2.14 2021-06-04
21152120

21162121
*
21172122
* **_BasePdoOneRepo** now works more closely with the class **PdoOneQuery**, so each query is a different instance.
21182123

2119-
* **[fix]** **PdoOne** dateConvertInput() does not crash when the value is not a date.
2124+
* ****[fix]**** **PdoOne** dateConvertInput() does not crash when the value is not a date.
21202125

2121-
* **[fix]** **PdoOne** throwError() does not stack errors but still triggers the last error (if any).
2126+
* ****[fix]**** **PdoOne** throwError() does not stack errors but still triggers the last error (if any).
21222127

21232128
* [changes]**PdoOne** aggregate functions (sum,min,max,avg) now returns a value instead of generating a query.
21242129

@@ -2128,7 +2133,7 @@ it as a PHP file.
21282133
```
21292134

21302135

2131-
* **[fix]** **PdoOne** generateCodeArray() used for the generation of classes, returns the correct name when it is set.
2136+
* ****[fix]**** **PdoOne** generateCodeArray() used for the generation of classes, returns the correct name when it is set.
21322137

21332138
* [changes] **_BasePdoOneRepo**: reset(),getQuery(),dropTable(),useCache(),limit(),newQuery(),order(),innerjoin(),left()
21342139
,right()
@@ -2138,7 +2143,7 @@ it as a PHP file.
21382143

21392144
* 2.13.1 2021-05-22
21402145

2141-
* **[fix]** **[orm]** the method where() and limit() generated a new query every time, so the command
2146+
* ****[fix]**** **[orm]** the method where() and limit() generated a new query every time, so the command
21422147
ClaseRepo::recursive()::where() failed generated two queries instead of one.
21432148

21442149
* 2.13 2021-04-17
@@ -2150,16 +2155,16 @@ it as a PHP file.
21502155
(it could be disabled with setting $this->customError=false)
21512156

21522157
* 2.11.1 2021-04-17
2153-
* **[fix]** Mysql extension now knows the type int24 (plus other types of variables).
2154-
* **[fix]** Regresion, some removed { } caused a bug when they are followed by []
2158+
* ****[fix]**** Mysql extension now knows the type int24 (plus other types of variables).
2159+
* ****[fix]**** Regresion, some removed { } caused a bug when they are followed by []
21552160
* [code]
21562161

21572162
* 2.11 2021-04-17
21582163

21592164
* [code] Lots of cleanups. Removed unneeding { }. Merged common code in branches.
21602165

21612166
* 2.10.3 2021-04-14
2162-
* **[fix]** BasePdoOne fixed method getRecursive(), it generated a new query, and now it reuses a query (if any).
2167+
* ****[fix]**** BasePdoOne fixed method getRecursive(), it generated a new query, and now it reuses a query (if any).
21632168
* It also returns the query
21642169

21652170
* 2.10.2 2021-04-06

lib/PdoOne.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
* @package eftec
3030
* @author Jorge Castro Castillo
3131
* @copyright (c) Jorge Castro C. Dual Licence: MIT and Commercial License https://github.com/EFTEC/PdoOne
32-
* @version 4.8
32+
* @version 4.9.1
3333
*/
3434
class PdoOne
3535
{
36-
public const VERSION = '4.8';
36+
public const VERSION = '4.9.1';
3737
/** @var int We need this value because null and false could be a valid value. */
3838
public const NULL = PHP_INT_MAX;
3939
/** @var string Prefix of the related columns. It is used for ORM */

lib/PdoOneQuery.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
/**
1717
* Class PdoOneQuery
1818
*
19-
* @version 4.8
19+
* @version 4.9.1
2020
* @package eftec
2121
* @author Jorge Castro Castillo
2222
* @copyright (c) Jorge Castro C. Dual Licence: MIT and Commercial License https://github.com/EFTEC/PdoOne
2323
*/
2424
class PdoOneQuery
2525
{
26-
public const VERSION = '4.8';
26+
public const VERSION = '4.9.1';
2727
//<editor-fold desc="query builder fields">
2828
/** @var PdoOne */
2929
public PdoOne $parent;
@@ -530,7 +530,7 @@ public function constructParam2(
530530
$named = [];
531531
$pars = [];
532532
if ($params === PdoOne::NULL || $params === null) {
533-
if (is_array($where)) {
533+
if (is_array($where)) { // where( ['field'=>20] ) without argument.
534534
$numeric = isset($where[0]) || $this->numericArgument;
535535
if ($numeric) {
536536
$this->numericArgument = true;
@@ -588,10 +588,10 @@ public function constructParam2(
588588
}
589589
} else {
590590
// where and params are not empty
591-
if (!is_array($params)) {
591+
if (!is_array($params)) { //where( 'field=?',20 )
592592
$params = [$params];
593593
}
594-
if (!is_array($where)) {
594+
if (!is_array($where)) { // where( ['field=?',[20]] )
595595
$queryEnd[] = $where;
596596
$numeric = isset($params[0]);
597597
if ($numeric) {
@@ -657,7 +657,11 @@ public function constructParam2(
657657
$i = -1;
658658
foreach ($queryEnd as $k => $v) {
659659
$i++;
660-
if ($named[$i] !== '' && strpos($v, '?') === false && strpos($v, $named[$i]) === false) {
660+
if (($type === 'where' || $type === 'having') && isset($pars[$k]) && $pars[$k][1] === null) {
661+
// where('column',[null])
662+
$v = "$v is null";
663+
unset($pars[$k]);
664+
} else if ($named[$i] !== '' && strpos($v, '?') === false && strpos($v, $named[$i]) === false) {
661665
$v .= '=' . $named[$i];
662666
$queryEnd[$k] = $v;
663667
}
@@ -1889,7 +1893,7 @@ protected function _insert($tableName = null,
18891893

18901894
/**
18911895
* It sets the mode to fetch the values. By default it uses PDO::FETCH_ASSOC
1892-
* @param int $fetchMode Example: PDO::FETCH_BOTH
1896+
* @param int $fetchMode Example: PDO::FETCH_BOTH
18931897
* @param mixed|null $fetchArgument the argument of the fetch_mode
18941898
* @return PdoOneQuery
18951899
* @see https://www.php.net/manual/en/pdostatement.fetch.php

tests/PdoOne_mysql_Test.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,27 @@ public function test_camel():void {
11041104
self::assertEquals('CamelFormat',PdoOne::camelize('camel-format'));
11051105
self::assertEquals('CamelFormat',PdoOne::camelize('camelFormat'));
11061106
}
1107+
public function test_null():void {
1108+
try {
1109+
$r = $this->pdoOne->runRawQuery('drop table product_category');
1110+
self::assertEquals(true, $r, 'Drop failed');
1111+
} catch (Exception $e) {
1112+
$r = false;
1113+
// drops silently
1114+
}
1115+
$sqlT2 = 'CREATE TABLE `product_category` (`id_category` INT NOT NULL,`catname`
1116+
VARCHAR(45) NULL, PRIMARY KEY (`id_category`));';
1117+
try {
1118+
$r = $this->pdoOne->runRawQuery($sqlT2);
1119+
} catch (Exception $e) {
1120+
echo $e->getMessage() . '<br>';
1121+
}
1122+
$this->pdoOne->insert('product_category', ['id_category' => 3, 'catname' => 'cheap']);
1123+
$this->pdoOne->insert('product_category', ['id_category' => 4, 'catname' => null]);
1124+
$this->assertEquals([0=>['id_category' => 4, 'catname' => null]],
1125+
$this->pdoOne->select('*')->from('product_category')->where(['catname'=>null])->toList());
1126+
1127+
}
11071128

11081129
/**
11091130
* @throws Exception

0 commit comments

Comments
 (0)