Use the Index DbTools version for list prepare thing.

This commit is contained in:
Pachira 2023-07-22 13:54:42 +00:00
parent e369038609
commit baefea88df
4 changed files with 14 additions and 17 deletions

View file

@ -4,6 +4,7 @@ namespace Misuzu\Changelog;
use InvalidArgumentException;
use RuntimeException;
use Index\DateTime;
use Index\Data\DbTools;
use Index\Data\IDbConnection;
use Index\Data\IDbResult;
use Misuzu\DbStatementCache;
@ -122,7 +123,7 @@ class Changelog {
$query .= (++$args > 1 ? ' AND' : ' WHERE');
$query .= sprintf(
' change_id IN (SELECT change_id FROM msz_changelog_change_tags WHERE tag_id IN (%s))',
msz_where_in_list($tags)
DbTools::prepareListString($tags)
);
}
$stmt = $this->cache->get($query);
@ -177,7 +178,7 @@ class Changelog {
$query .= (++$args > 1 ? ' AND' : ' WHERE');
$query .= sprintf(
' change_id IN (SELECT change_id FROM msz_changelog_change_tags WHERE tag_id IN (%s))',
msz_where_in_list($tags)
DbTools::prepareListString($tags)
);
}
$query .= ' GROUP BY change_created, change_id ORDER BY change_created DESC, change_id DESC';

View file

@ -4,6 +4,7 @@ namespace Misuzu\Config;
use RuntimeException;
use InvalidArgumentException;
use Index\Data\DataException;
use Index\Data\DbTools;
use Index\Data\IDbConnection;
use Index\Data\IDbStatement;
use Index\Data\IDbResult;
@ -57,7 +58,7 @@ class DbConfig implements IConfig {
$stmt = $this->cache->get(sprintf(
'SELECT COUNT(*) FROM msz_config WHERE config_name IN (%s)',
msz_where_in_list($nameCount)
DbTools::prepareListString($nameCount)
));
for($i = 0; $i < $nameCount; ++$i)
$stmt->addParameter($i + 1, $names[$i]);
@ -83,7 +84,7 @@ class DbConfig implements IConfig {
$nameCount = count($names);
$stmt = $this->cache->get(sprintf(
'DELETE FROM msz_config WHERE config_name IN (%s)',
msz_where_in_list($nameCount)
DbTools::prepareListString($nameCount)
));
for($i = 0; $i < $nameCount; ++$i)
@ -143,7 +144,7 @@ class DbConfig implements IConfig {
$stmt = $this->cache->get(sprintf(
'SELECT config_name, config_value FROM msz_config WHERE config_name IN (%s)',
msz_where_in_list($nameCount)
DbTools::prepareListString($nameCount)
));
for($i = 0; $i < $nameCount; ++$i)
$stmt->addParameter($i + 1, $names[$i]);
@ -267,7 +268,7 @@ class DbConfig implements IConfig {
$stmt = $this->cache->get(sprintf(
'REPLACE INTO msz_config (config_name, config_value) VALUES %s',
msz_where_in_list($valueCount, '(?, ?)')
DbTools::prepareListString($valueCount, '(?, ?)')
));
$args = 0;

View file

@ -3,6 +3,7 @@ namespace Misuzu\Profile;
use InvalidArgumentException;
use RuntimeException;
use Index\Data\DbTools;
use Index\Data\IDbConnection;
use Index\Data\IDbResult;
use Misuzu\DbStatementCache;
@ -22,7 +23,7 @@ class ProfileFields {
$query = 'SELECT field_id, field_order, field_key, field_title, field_regex FROM msz_profile_fields';
if($hasFieldValueInfos)
$query .= sprintf(' WHERE field_id IN (%s)', msz_where_in_list($fieldValueInfos));
$query .= sprintf(' WHERE field_id IN (%s)', DbTools::prepareListString($fieldValueInfos));
$query .= ' ORDER BY field_order ASC';
$stmt = $this->cache->get($query);
@ -74,12 +75,12 @@ class ProfileFields {
if($hasFieldInfos) {
++$args;
$query .= sprintf(' WHERE field_id IN (%s)', msz_where_in_list($fieldInfos));
$query .= sprintf(' WHERE field_id IN (%s)', DbTools::prepareListString($fieldInfos));
}
if($hasFieldValueInfos)
$query .= sprintf(' %s format_id IN (%s)',
(++$args > 1 ? 'AND' : 'WHERE'),
msz_where_in_list($fieldValueInfos)
DbTools::prepareListString($fieldValueInfos)
);
$stmt = $this->cache->get($query);
@ -226,7 +227,7 @@ class ProfileFields {
$args = 0;
$stmt = $this->cache->get(
'REPLACE INTO msz_profile_fields_values (field_id, user_id, format_id, field_value) VALUES '
. msz_where_in_list($rows, '(?, ?, ?, ?)')
. DbTools::prepareListString($rows, '(?, ?, ?, ?)')
);
foreach($rows as $row) {
@ -261,7 +262,7 @@ class ProfileFields {
$args = 0;
$stmt = $this->cache->get(sprintf(
'DELETE FROM msz_profile_fields_values WHERE user_id = ? AND field_id IN (%s)',
msz_where_in_list($fieldInfos)
DbTools::prepareListString($fieldInfos)
));
$stmt->addParameter(++$args, $userInfo);
foreach($fieldInfos as $value)

View file

@ -1,12 +1,6 @@
<?php
use Index\Colour\Colour;
function msz_where_in_list(Countable|array|int $count, string $repeat = '?', string $separator = ', '): string {
if(is_countable($count))
$count = count($count);
return implode($separator, array_fill(0, $count, $repeat));
}
// render_error and render_info need to be nuked from orbit
function render_error(int $code, string $template = 'errors.%d'): string {