Skip to content

Commit f84f3c7

Browse files
committed
Begin work on prepared statements
Rework affected rows (must be retrieved from statement) Handle Prepared from migrations Handle possible exisiting QueryExpression statement values Try to detect early bind issues Limit to simple cases for now Fix prepared IN, fix buildUpdate Try to get extra information on failure rawAnalyzeCrit (maybe to remove)
1 parent 53464a3 commit f84f3c7

34 files changed

Lines changed: 1119 additions & 293 deletions

install/migrations/update_9.4.3_to_9.4.5.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ function update943to945()
5050
$migration->setVersion('9.4.5');
5151

5252
/** Add OLA TTR begin date field to Tickets */
53-
$iterator = new DBmysqlIterator(null);
53+
$iterator = new DBmysqlIterator($DB);
5454
$migration->addField(
5555
'glpi_tickets',
5656
'ola_ttr_begin_date',
5757
'datetime',
5858
[
5959
'after' => 'olalevels_id_ttr',
6060
'update' => $DB->quoteName('date'), // Assign ticket creation date by default
61-
'condition' => 'WHERE ' . $iterator->analyseCrit(['NOT' => ['olas_id_ttr' => '0']]),
61+
'condition' => sprintf('WHERE NOT(%s = %d)', $DB->quoteName('olas_id_ttr'), 0),
6262
]
6363
);
6464
/** /Add OLA TTR begin date field to Tickets */

src/AbstractQuery.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
abstract class AbstractQuery
4040
{
4141
protected ?string $alias = null;
42+
/** @var array<int, mixed> */
43+
protected array $values = [];
4244

4345
/**
4446
* Create a query
@@ -74,4 +76,21 @@ public function __toString()
7476
{
7577
return $this->getQuery();
7678
}
79+
80+
/**
81+
* @return array<int, mixed>
82+
*/
83+
public function getValues(): array
84+
{
85+
return $this->values;
86+
}
87+
88+
/**
89+
* @param array<int, mixed> $values
90+
*/
91+
public function setValues(array $values): static
92+
{
93+
$this->values = $values;
94+
return $this;
95+
}
7796
}

src/Cartridge.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function backToStock(array $input, $history = true)
252252
'id' => $input['id'],
253253
]
254254
);
255-
if ($result && ($DB->affectedRows() > 0)) {
255+
if ($result && ($DB->getAffectedRows() > 0)) {
256256
$changesCartrige = [
257257
0,
258258
'',
@@ -314,7 +314,7 @@ public function install($pID, $tID)
314314
'date_use' => null,
315315
]
316316
);
317-
if ($result && ($DB->affectedRows() > 0)) {
317+
if ($result && ($DB->getAffectedRows() > 0)) {
318318
$changes = [
319319
'0',
320320
'',
@@ -373,7 +373,7 @@ public function uninstall($ID)
373373

374374
if (
375375
$result
376-
&& ($DB->affectedRows() > 0)
376+
&& ($DB->getAffectedRows() > 0)
377377
) {
378378
$changes = [
379379
'0',

src/CartridgeItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public static function addCompatibleType($cartridgeitems_id, $printermodels_id)
202202
];
203203
$result = $DB->insert('glpi_cartridgeitems_printermodels', $params);
204204

205-
if ($result && ($DB->affectedRows() > 0)) {
205+
if ($result && ($DB->getAffectedRows() > 0)) {
206206
return true;
207207
}
208208
}

src/CommonDBTM.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ public function updateInDB($updates, $oldvalues = [])
736736
$tobeupdated,
737737
['id' => $this->fields['id']]
738738
);
739-
$affected_rows = $DB->affectedRows();
739+
$affected_rows = $DB->getAffectedRows();
740740

741741
if (count($oldvalues) && $affected_rows > 0) {
742742
Log::constructHistory($this, $oldvalues, $this->fields);
@@ -803,9 +803,8 @@ public function restoreInDB()
803803
$params['date_mod'] = $_SESSION["glpi_currenttime"];
804804
}
805805

806-
if ($DB->update(static::getTable(), $params, ['id' => $this->fields['id']])) {
807-
return true;
808-
}
806+
$DB->update(static::getTable(), $params, ['id' => $this->fields['id']]);
807+
return true;
809808
}
810809
return false;
811810
}
@@ -1903,7 +1902,15 @@ protected function manageLocks()
19031902
);
19041903
foreach ($fields as $field) {
19051904
try {
1906-
$DB->executeStatement($stmt, [$field]);
1905+
$DB->executeStatement(
1906+
$stmt,
1907+
[
1908+
'itemtype' => static::class,
1909+
'items_id' => $this->fields['id'],
1910+
'date_creation' => $_SESSION["glpi_currenttime"],
1911+
'field' => $field,
1912+
]
1913+
);
19071914
} catch (StatementException $e) {
19081915
if ($e->getCode() != 1062) {
19091916
throw new RuntimeException('Unable to add locked field!', code: $e->getCode(), previous: $e);

src/CronTask.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public function start(): bool
267267
]
268268
);
269269

270-
if ($DB->affectedRows() > 0) {
270+
if ($DB->getAffectedRows() > 0) {
271271
$this->timer = microtime(true);
272272
$this->volume = 0;
273273
$log = new CronTaskLog();
@@ -353,7 +353,7 @@ public function end(?int $retcode, int $log_state = CronTaskLog::STATE_STOP): bo
353353
]
354354
);
355355

356-
if ($DB->affectedRows() > 0) {
356+
if ($DB->getAffectedRows() > 0) {
357357
// No gettext for log but add gettext line to be parsed for pot generation
358358
// order is important for insertion in english in the database
359359
if ($log_state === CronTaskLog::STATE_ERROR) {

src/CronTaskLog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static function cleanOld($id, $days)
7979
]
8080
);
8181

82-
return $result ? $DB->affectedRows() : 0;
82+
return $result ? $DB->getAffectedRows() : 0;
8383
}
8484

8585

0 commit comments

Comments
 (0)