Skip to content

Commit c7d4b3b

Browse files
committed
CrateDB bulk operations: Remove CRATE_ATTR_BULK_MODE attribute again
Going modeless is better anyway, and mitigates corresponding ux flaws.
1 parent 50988a6 commit c7d4b3b

File tree

5 files changed

+12
-56
lines changed

5 files changed

+12
-56
lines changed

src/Crate/PDO/PDO.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class PDO extends BasePDO implements PDOInterface
4242

4343
public const CRATE_ATTR_HTTP_BASIC_AUTH = 1000;
4444
public const CRATE_ATTR_DEFAULT_SCHEMA = 1001;
45-
public const CRATE_ATTR_BULK_MODE = 1009;
4645

4746
public const CRATE_ATTR_SSL_MODE = 1008;
4847
public const CRATE_ATTR_SSL_MODE_DISABLED = 1;
@@ -127,7 +126,7 @@ public function __construct($dsn, $username = null, $passwd = null, $options = [
127126
$this->lastStatement = $statement;
128127

129128
try {
130-
if ($this->getAttribute(self::CRATE_ATTR_BULK_MODE)) {
129+
if ($statement->isBulkMode()) {
131130
return $this->server->executeBulk($sql, $parameters);
132131
} else {
133132
return $this->server->execute($sql, $parameters);
@@ -328,10 +327,6 @@ public function setAttribute($attribute, $value)
328327
$this->attributes['defaultSchema'] = $value;
329328
break;
330329

331-
case self::CRATE_ATTR_BULK_MODE:
332-
$this->attributes['bulkMode'] = $value;
333-
break;
334-
335330
case self::CRATE_ATTR_SSL_MODE:
336331
$this->attributes['sslMode'] = $value;
337332
break;
@@ -412,9 +407,6 @@ public function getAttribute($attribute)
412407
case self::CRATE_ATTR_DEFAULT_SCHEMA:
413408
return $this->attributes['defaultSchema'];
414409

415-
case self::CRATE_ATTR_BULK_MODE:
416-
return $this->attributes['bulkMode'];
417-
418410
case self::CRATE_ATTR_SSL_MODE:
419411
return $this->attributes['sslMode'];
420412

src/Crate/PDO/PDOStatement.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ public function __construct(PDOInterface $pdo, Closure $request, $sql, array $op
103103
$this->pdo = $pdo;
104104
$this->options = array_merge($this->options, $options);
105105
$this->request = $request;
106-
107-
// Storing `bulkMode` flag because calling `pdo->getAttribute()` at runtime reveals weird errors.
108-
$this->options["bulkMode"] = $this->pdo->getAttribute(PDO::CRATE_ATTR_BULK_MODE);
109106
}
110107

111108
private function replaceNamedParametersWithPositionals($sql)
@@ -698,4 +695,9 @@ private function getObjectResult(array $columns, array $row)
698695

699696
return $obj;
700697
}
698+
699+
public function isBulkMode()
700+
{
701+
return $this->options["bulkMode"];
702+
}
701703
}

test/CrateIntegrationTest/PDO/PDOStatementTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,12 @@ public function testInsertNull()
355355
public function testInsertBulk()
356356
{
357357
// Insert records in bulk mode.
358-
$this->pdo->setAttribute(PDO::CRATE_ATTR_BULK_MODE, true);
359358
$parameters = [[5, 'foo', 1], [6, 'bar', 2], [7, 'foo', 3], [8, 'bar', 4]];
360-
$statement = $this->pdo->prepare('INSERT INTO test_table (id, name, int_type) VALUES (?, ?, ?)');
359+
$statement = $this->pdo->prepare('INSERT INTO test_table (id, name, int_type) VALUES (?, ?, ?)', array("bulkMode" => true));
360+
$retval = $statement->execute($parameters);
361361
$this->assertTrue($statement->execute($parameters));
362362

363363
// Verify records have been inserted correctly.
364-
$this->pdo->setAttribute(PDO::CRATE_ATTR_BULK_MODE, false);
365364
$this->pdo->exec("REFRESH TABLE test_table");
366365
$statement = $this->pdo->prepare("SELECT id, name, int_type FROM test_table");
367366
$results = $statement->fetchAll(PDO::FETCH_NUM);

test/CrateTest/PDO/Http/ServerPoolTest.php

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -209,36 +209,14 @@ public function testGuzzleClientOptionTest(array $options, array $expected)
209209

210210
}
211211

212-
public function pdoOptionsBulk()
213-
{
214-
return [
215-
[
216-
[
217-
PDO::CRATE_ATTR_BULK_MODE => true,
218-
],
219-
[
220-
'base_uri' => 'http://localhost:4200',
221-
],
222-
],
223-
];
224-
}
225-
226212
/**
227213
* Verify Guzzle client behavior when using CrateDB bulk operations.
228214
* https://crate.io/docs/crate/reference/en/latest/interfaces/http.html#bulk-operations
229215
*
230-
* @dataProvider pdoOptionsBulk
231-
*
232-
* @param array $options
233-
* @param array $expected
234216
*/
235-
public function testGuzzleClientOptionTestBulkMode(array $options, array $expected)
217+
public function testGuzzleClientOptionTestBulkMode()
236218
{
237-
foreach ($options as $attr => $val) {
238-
$this->pdo->setAttribute($attr, $val);
239-
}
240-
241-
$expectedWithDefaults = array_merge([
219+
$expectedWithDefaults = [
242220
RequestOptions::TIMEOUT => 0.0,
243221
RequestOptions::CONNECT_TIMEOUT => 0.0,
244222
RequestOptions::JSON => [
@@ -252,7 +230,7 @@ public function testGuzzleClientOptionTestBulkMode(array $options, array $expect
252230

253231
RequestOptions::AUTH => null,
254232
'base_uri' => 'http://localhost:4200',
255-
], $expected);
233+
];
256234

257235
$body = json_encode(['results' => [["foo", "bar"]], 'cols' => [], 'duration' => 0]);
258236

test/CrateTest/PDO/PDOTest.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -356,20 +356,6 @@ public function fetchModeStyleProvider()
356356
];
357357
}
358358

359-
/**
360-
* Verify support for CrateDB bulk operations.
361-
* https://crate.io/docs/crate/reference/en/latest/interfaces/http.html#bulk-operations
362-
*
363-
* @covers ::getAttribute
364-
* @covers ::setAttribute
365-
*/
366-
public function testGetAndSetBulkMode()
367-
{
368-
$this->assertEquals(false, $this->pdo->getAttribute(PDO::CRATE_ATTR_BULK_MODE));
369-
$this->pdo->setAttribute(PDO::CRATE_ATTR_BULK_MODE, true);
370-
$this->assertEquals(true, $this->pdo->getAttribute(PDO::CRATE_ATTR_BULK_MODE));
371-
}
372-
373359
/**
374360
* Verify support for CrateDB bulk operations.
375361
* https://crate.io/docs/crate/reference/en/latest/interfaces/http.html#bulk-operations
@@ -378,8 +364,7 @@ public function testGetAndSetBulkMode()
378364
*/
379365
public function testBulkMode()
380366
{
381-
$this->pdo->setAttribute(PDO::CRATE_ATTR_BULK_MODE, true);
382-
$statement = $this->pdo->query("INSERT INTO foobar;", null, [["foo", "bar"]]);
367+
$statement = $this->pdo->prepare("INSERT INTO foobar;", array("bulkMode" => true));
383368

384369
// Enable accessing the private `options` property of the `PDOStatement` instance.
385370
$class = new ReflectionClass($statement);

0 commit comments

Comments
 (0)