Skip to content

Commit 77222ad

Browse files
committed
code is optimized
1 parent ebb4106 commit 77222ad

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/ClickHousePlatform.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,31 +1253,30 @@ public function getDefaultValueDeclarationSQL($field) : string
12531253
if (! isset($field['default'])) {
12541254
return '';
12551255
}
1256-
1257-
$default = " DEFAULT '" . $field['default'] . "'";
1258-
$fieldType = $field['type'] ?? null;
1256+
$defaultValue = $this->quoteStringLiteral($field['default']);
1257+
$fieldType = $field['type'] ?: null;
12591258
if ($fieldType !== null) {
1260-
if (in_array($fieldType, [
1259+
if ($fieldType === DatableClickHouseType::TYPE_DATE ||
1260+
$fieldType instanceof DateType ||
1261+
in_array($fieldType, [
12611262
'Integer',
12621263
'SmallInt',
12631264
'Float',
12641265
]) ||
12651266
(
12661267
$fieldType === 'BigInt'
1267-
&& Type::getType('BigInt')->getBindingType() === ParameterType::INTEGER)
1268+
&& Type::getType('BigInt')->getBindingType() === ParameterType::INTEGER
1269+
)
12681270
) {
1269-
$default = ' DEFAULT ' . $field['default'];
1271+
$defaultValue = $field['default'];
12701272
} elseif ($fieldType === DatableClickHouseType::TYPE_DATE_TIME &&
12711273
$field['default'] === $this->getCurrentTimestampSQL()
12721274
) {
1273-
$default = ' DEFAULT ' . $this->getCurrentTimestampSQL();
1274-
} elseif (// TODO check if string matches constant date like 'dddd-yy-mm' and quote it
1275-
$fieldType === DatableClickHouseType::TYPE_DATE) {
1276-
$default = ' DEFAULT ' . $field['default'];
1275+
$defaultValue = $this->getCurrentTimestampSQL();
12771276
}
12781277
}
12791278

1280-
return $default;
1279+
return sprintf(' DEFAULT %s', $defaultValue);
12811280
}
12821281

12831282
/**

src/ClickHouseStatement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ function ($row) {
231231
public function fetchColumn($columnIndex = 0)
232232
{
233233
$elem = $this->fetch(FetchMode::NUMERIC);
234-
if (is_array($elem) && array_key_exists($columnIndex, $elem)) {
235-
return $elem[$columnIndex];
234+
if (is_array($elem)) {
235+
return $elem[$columnIndex] ?? $elem[0];
236236
}
237237

238238
return false;

0 commit comments

Comments
 (0)