Use the Index DbTools version for list prepare thing.
This commit is contained in:
parent
e369038609
commit
baefea88df
4 changed files with 14 additions and 17 deletions
|
@ -4,6 +4,7 @@ namespace Misuzu\Changelog;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Index\DateTime;
|
use Index\DateTime;
|
||||||
|
use Index\Data\DbTools;
|
||||||
use Index\Data\IDbConnection;
|
use Index\Data\IDbConnection;
|
||||||
use Index\Data\IDbResult;
|
use Index\Data\IDbResult;
|
||||||
use Misuzu\DbStatementCache;
|
use Misuzu\DbStatementCache;
|
||||||
|
@ -122,7 +123,7 @@ class Changelog {
|
||||||
$query .= (++$args > 1 ? ' AND' : ' WHERE');
|
$query .= (++$args > 1 ? ' AND' : ' WHERE');
|
||||||
$query .= sprintf(
|
$query .= sprintf(
|
||||||
' change_id IN (SELECT change_id FROM msz_changelog_change_tags WHERE tag_id IN (%s))',
|
' 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);
|
$stmt = $this->cache->get($query);
|
||||||
|
@ -177,7 +178,7 @@ class Changelog {
|
||||||
$query .= (++$args > 1 ? ' AND' : ' WHERE');
|
$query .= (++$args > 1 ? ' AND' : ' WHERE');
|
||||||
$query .= sprintf(
|
$query .= sprintf(
|
||||||
' change_id IN (SELECT change_id FROM msz_changelog_change_tags WHERE tag_id IN (%s))',
|
' 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';
|
$query .= ' GROUP BY change_created, change_id ORDER BY change_created DESC, change_id DESC';
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Misuzu\Config;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Index\Data\DataException;
|
use Index\Data\DataException;
|
||||||
|
use Index\Data\DbTools;
|
||||||
use Index\Data\IDbConnection;
|
use Index\Data\IDbConnection;
|
||||||
use Index\Data\IDbStatement;
|
use Index\Data\IDbStatement;
|
||||||
use Index\Data\IDbResult;
|
use Index\Data\IDbResult;
|
||||||
|
@ -57,7 +58,7 @@ class DbConfig implements IConfig {
|
||||||
|
|
||||||
$stmt = $this->cache->get(sprintf(
|
$stmt = $this->cache->get(sprintf(
|
||||||
'SELECT COUNT(*) FROM msz_config WHERE config_name IN (%s)',
|
'SELECT COUNT(*) FROM msz_config WHERE config_name IN (%s)',
|
||||||
msz_where_in_list($nameCount)
|
DbTools::prepareListString($nameCount)
|
||||||
));
|
));
|
||||||
for($i = 0; $i < $nameCount; ++$i)
|
for($i = 0; $i < $nameCount; ++$i)
|
||||||
$stmt->addParameter($i + 1, $names[$i]);
|
$stmt->addParameter($i + 1, $names[$i]);
|
||||||
|
@ -83,7 +84,7 @@ class DbConfig implements IConfig {
|
||||||
$nameCount = count($names);
|
$nameCount = count($names);
|
||||||
$stmt = $this->cache->get(sprintf(
|
$stmt = $this->cache->get(sprintf(
|
||||||
'DELETE FROM msz_config WHERE config_name IN (%s)',
|
'DELETE FROM msz_config WHERE config_name IN (%s)',
|
||||||
msz_where_in_list($nameCount)
|
DbTools::prepareListString($nameCount)
|
||||||
));
|
));
|
||||||
|
|
||||||
for($i = 0; $i < $nameCount; ++$i)
|
for($i = 0; $i < $nameCount; ++$i)
|
||||||
|
@ -143,7 +144,7 @@ class DbConfig implements IConfig {
|
||||||
|
|
||||||
$stmt = $this->cache->get(sprintf(
|
$stmt = $this->cache->get(sprintf(
|
||||||
'SELECT config_name, config_value FROM msz_config WHERE config_name IN (%s)',
|
'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)
|
for($i = 0; $i < $nameCount; ++$i)
|
||||||
$stmt->addParameter($i + 1, $names[$i]);
|
$stmt->addParameter($i + 1, $names[$i]);
|
||||||
|
@ -267,7 +268,7 @@ class DbConfig implements IConfig {
|
||||||
|
|
||||||
$stmt = $this->cache->get(sprintf(
|
$stmt = $this->cache->get(sprintf(
|
||||||
'REPLACE INTO msz_config (config_name, config_value) VALUES %s',
|
'REPLACE INTO msz_config (config_name, config_value) VALUES %s',
|
||||||
msz_where_in_list($valueCount, '(?, ?)')
|
DbTools::prepareListString($valueCount, '(?, ?)')
|
||||||
));
|
));
|
||||||
|
|
||||||
$args = 0;
|
$args = 0;
|
||||||
|
|
|
@ -3,6 +3,7 @@ namespace Misuzu\Profile;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
use Index\Data\DbTools;
|
||||||
use Index\Data\IDbConnection;
|
use Index\Data\IDbConnection;
|
||||||
use Index\Data\IDbResult;
|
use Index\Data\IDbResult;
|
||||||
use Misuzu\DbStatementCache;
|
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';
|
$query = 'SELECT field_id, field_order, field_key, field_title, field_regex FROM msz_profile_fields';
|
||||||
if($hasFieldValueInfos)
|
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';
|
$query .= ' ORDER BY field_order ASC';
|
||||||
|
|
||||||
$stmt = $this->cache->get($query);
|
$stmt = $this->cache->get($query);
|
||||||
|
@ -74,12 +75,12 @@ class ProfileFields {
|
||||||
|
|
||||||
if($hasFieldInfos) {
|
if($hasFieldInfos) {
|
||||||
++$args;
|
++$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)
|
if($hasFieldValueInfos)
|
||||||
$query .= sprintf(' %s format_id IN (%s)',
|
$query .= sprintf(' %s format_id IN (%s)',
|
||||||
(++$args > 1 ? 'AND' : 'WHERE'),
|
(++$args > 1 ? 'AND' : 'WHERE'),
|
||||||
msz_where_in_list($fieldValueInfos)
|
DbTools::prepareListString($fieldValueInfos)
|
||||||
);
|
);
|
||||||
|
|
||||||
$stmt = $this->cache->get($query);
|
$stmt = $this->cache->get($query);
|
||||||
|
@ -226,7 +227,7 @@ class ProfileFields {
|
||||||
$args = 0;
|
$args = 0;
|
||||||
$stmt = $this->cache->get(
|
$stmt = $this->cache->get(
|
||||||
'REPLACE INTO msz_profile_fields_values (field_id, user_id, format_id, field_value) VALUES '
|
'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) {
|
foreach($rows as $row) {
|
||||||
|
@ -261,7 +262,7 @@ class ProfileFields {
|
||||||
$args = 0;
|
$args = 0;
|
||||||
$stmt = $this->cache->get(sprintf(
|
$stmt = $this->cache->get(sprintf(
|
||||||
'DELETE FROM msz_profile_fields_values WHERE user_id = ? AND field_id IN (%s)',
|
'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);
|
$stmt->addParameter(++$args, $userInfo);
|
||||||
foreach($fieldInfos as $value)
|
foreach($fieldInfos as $value)
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
use Index\Colour\Colour;
|
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
|
// render_error and render_info need to be nuked from orbit
|
||||||
|
|
||||||
function render_error(int $code, string $template = 'errors.%d'): string {
|
function render_error(int $code, string $template = 'errors.%d'): string {
|
||||||
|
|
Loading…
Reference in a new issue