Skip to content

Commit 688c58b

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 3879084 commit 688c58b

29 files changed

Lines changed: 777 additions & 180 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' => 'WHERE ' . $iterator->rawAnalyseCrit(['NOT' => ['olas_id_ttr' => '0']]), //FIXME: maybe just make it RAW sql instead of using an iterator here
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-
return $result && ($DB->affectedRows() > 0);
255+
return $result && ($DB->getAffectedRows() > 0);
256256
}
257257

258258
// SPECIFIC FUNCTIONS
@@ -297,7 +297,7 @@ public function install($pID, $tID)
297297
'date_use' => null,
298298
]
299299
);
300-
if ($result && ($DB->affectedRows() > 0)) {
300+
if ($result && ($DB->getAffectedRows() > 0)) {
301301
$changes = [
302302
'0',
303303
'',
@@ -342,7 +342,7 @@ public function uninstall($ID)
342342

343343
if (
344344
$result
345-
&& ($DB->affectedRows() > 0)
345+
&& ($DB->getAffectedRows() > 0)
346346
) {
347347
$changes = [
348348
'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
@@ -734,7 +734,7 @@ public function updateInDB($updates, $oldvalues = [])
734734
$tobeupdated,
735735
['id' => $this->fields['id']]
736736
);
737-
$affected_rows = $DB->affectedRows();
737+
$affected_rows = $DB->getAffectedRows();
738738

739739
if (count($oldvalues) && $affected_rows > 0) {
740740
Log::constructHistory($this, $oldvalues, $this->fields);
@@ -801,9 +801,8 @@ public function restoreInDB()
801801
$params['date_mod'] = $_SESSION["glpi_currenttime"];
802802
}
803803

804-
if ($DB->update(static::getTable(), $params, ['id' => $this->fields['id']])) {
805-
return true;
806-
}
804+
$DB->update(static::getTable(), $params, ['id' => $this->fields['id']]);
805+
return true;
807806
}
808807
return false;
809808
}
@@ -1896,7 +1895,15 @@ protected function manageLocks()
18961895
);
18971896
foreach ($fields as $field) {
18981897
try {
1899-
$DB->executeStatement($stmt, [$field]);
1898+
$DB->executeStatement(
1899+
$stmt,
1900+
[
1901+
'itemtype' => static::class,
1902+
'items_id' => $this->fields['id'],
1903+
'date_creation' => $_SESSION["glpi_currenttime"],
1904+
'field' => $field,
1905+
]
1906+
);
19001907
} catch (StatementException $e) {
19011908
if ($e->getCode() != 1062) {
19021909
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
@@ -262,7 +262,7 @@ public function start()
262262
]
263263
);
264264

265-
if ($DB->affectedRows() > 0) {
265+
if ($DB->getAffectedRows() > 0) {
266266
$this->timer = microtime(true);
267267
$this->volume = 0;
268268
$log = new CronTaskLog();
@@ -346,7 +346,7 @@ public function end($retcode, int $log_state = CronTaskLog::STATE_STOP)
346346
]
347347
);
348348

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

src/CronTaskLog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static function cleanOld($id, $days)
7676
]
7777
);
7878

79-
return $result ? $DB->affectedRows() : 0;
79+
return $result ? $DB->getAffectedRows() : 0;
8080
}
8181

8282

0 commit comments

Comments
 (0)