Skip to content

Commit feff84f

Browse files
committed
:octocat: rename Query::sql() to getSQL()
1 parent 8385cfa commit feff84f

17 files changed

+39
-39
lines changed

src/Query/AlterDatabase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function name(string $dbname):static{
2323
return $this->setName($dbname);
2424
}
2525

26-
protected function getSQL():array{
26+
protected function sql():array{
2727
return []; // @todo
2828
}
2929

src/Query/AlterTable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function name(string $tablename):static{
2424
return $this->setName($tablename);
2525
}
2626

27-
protected function getSQL():array{
27+
protected function sql():array{
2828
return []; // @todo
2929
}
3030

src/Query/CreateDatabase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function ifNotExists():static{
3232
}
3333

3434
/** @inheritdoc */
35-
protected function getSQL():array{
35+
protected function sql():array{
3636
return $this->dialect->createDatabase($this->name, $this->ifNotExists, $this->charset);
3737
}
3838

src/Query/CreateTable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function ifNotExists():static{
4242
return $this->setIfNotExists();
4343
}
4444

45-
protected function getSQL():array{
45+
protected function sql():array{
4646
return $this->dialect->createTable($this->name, $this->cols, $this->primaryKey, $this->ifNotExists, $this->temp, $this->dir);
4747
}
4848

src/Query/Delete.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function offset(int $offset):static{
4444
return $this->setOffset($offset);
4545
}
4646

47-
protected function getSQL():array{
47+
protected function sql():array{
4848
return $this->dialect->delete($this->name, $this->getWhere());
4949
}
5050

src/Query/DropDatabase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function ifExists():static{
2828
}
2929

3030
/** @inheritdoc */
31-
protected function getSQL():array{
31+
protected function sql():array{
3232
return $this->dialect->dropDatabase($this->name, $this->ifExists);
3333
}
3434

src/Query/DropTable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function ifExists():static{
2929
}
3030

3131
/** @inheritdoc */
32-
protected function getSQL():array{
32+
protected function sql():array{
3333
return $this->dialect->dropTable($this->name, $this->ifExists);
3434
}
3535

src/Query/Insert.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function values(iterable $values):static{
4242
return $this;
4343
}
4444

45-
protected function getSQL():array{
45+
protected function sql():array{
4646

4747
if(empty($this->bindValues)){
4848
throw new QueryException('no values given');

src/Query/Query.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
interface Query{
1515

16-
public function sql(bool|null $multi = null):string;
16+
public function getSQL(bool|null $multi = null):string;
1717

1818
/**
1919
* @throws \chillerlan\Database\Query\QueryException

src/Query/Select.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function cached(int|null $ttl = null):static{
5353
return $this->setCached($ttl);
5454
}
5555

56-
protected function getSQL():array{
56+
protected function sql():array{
5757

5858
if(empty($this->from)){
5959
throw new QueryException('no FROM expression specified');

src/Query/ShowCreateTable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function name(string $name):static{
1717
return $this->setName($name);
1818
}
1919

20-
protected function getSQL():array{
20+
protected function sql():array{
2121
return $this->dialect->showCreateTable($this->name);
2222
}
2323

src/Query/ShowDatabases.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class ShowDatabases extends StatementAbstract implements Query{
1515

16-
protected function getSQL():array{
16+
protected function sql():array{
1717
return $this->dialect->showDatabases(); // @todo? WHERE
1818
}
1919

src/Query/ShowTables.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function closeBracket():static{
3333
return $this->setCloseBracket();
3434
}
3535

36-
protected function getSQL():array{
36+
protected function sql():array{
3737
return $this->dialect->showTables($this->name, $this->pattern, $this->getWhere());
3838
}
3939

src/Query/StatementAbstract.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected function setWhere(mixed $val1, mixed $val2, string|null $operator = nu
143143

144144
}
145145
else if($val2 instanceof Query){
146-
$where[] = $operator.'('.$val2->sql().')';
146+
$where[] = $operator.'('.$val2->getSQL().')';
147147

148148
if($val2 instanceof BindValues){
149149
$this->bindValues = array_merge($this->bindValues, $val2->getBindValues());
@@ -157,7 +157,7 @@ protected function setWhere(mixed $val1, mixed $val2, string|null $operator = nu
157157
$where[] = $operator;
158158

159159
if($val2 instanceof Query){
160-
$where[] = '('.$val2->sql().')';
160+
$where[] = '('.$val2->getSQL().')';
161161

162162
if($val2 instanceof BindValues){
163163
$this->bindValues = array_merge($this->bindValues, $val2->getBindValues());
@@ -246,22 +246,22 @@ protected function getWhere():string{
246246
/**
247247
* @throws \chillerlan\Database\Query\QueryException
248248
*/
249-
protected function getSQL():array{
250-
throw new QueryException('getSQL() not supported/implemented');
249+
protected function sql():array{
250+
throw new QueryException('sql() not supported/implemented');
251251
}
252252

253253
/**
254254
* @throws \chillerlan\Database\Query\QueryException
255255
*/
256-
public function sql(bool|null $multi = null):string{
256+
public function getSQL(bool|null $multi = null):string{
257257

258258
if(!$this instanceof Query){
259259
throw new QueryException('Query not supported');
260260
}
261261

262262
$this->multi = $multi ?? false;
263263

264-
$sql = trim(implode(' ', $this->getSQL()));
264+
$sql = trim(implode(' ', $this->sql()));
265265

266266
// this should only happen on a corrupt dialect implementation
267267
if(empty($sql)){
@@ -351,7 +351,7 @@ public function executeQuery(string|null $index = null):Result{
351351
throw new QueryException('Query not supported');
352352
}
353353

354-
$sql = $this->sql(false);
354+
$sql = $this->getSQL(false);
355355
$values = $this instanceof BindValues ? $this->getBindValues() : null;
356356

357357
$this->logger->debug('QueryTrait::executeQuery()', ['method' => __METHOD__, 'sql' => $sql, 'val' => $values, 'index' => $index]);
@@ -372,7 +372,7 @@ public function executeMultiQuery(array|null $values = null, Closure|null $callb
372372
throw new QueryException('MultiQuery not supported');
373373
}
374374

375-
$sql = $this->sql(true);
375+
$sql = $this->getSQL(true);
376376

377377
if($values !== null && $callback !== null){
378378
$this->logger->debug('MultiQueryTrait::executeMultiQuery()', ['method' => __METHOD__, 'sql' => $sql, 'val' => $values]);

src/Query/Truncate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function table(string $name):static{
2222
return $this->setName($name);
2323
}
2424

25-
protected function getSQL():array{
25+
protected function sql():array{
2626
return $this->dialect->truncate($this->name);
2727
}
2828

src/Query/Update.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function offset(int $offset):static{
4848
return $this->setOffset($offset);
4949
}
5050

51-
protected function getSQL():array{
51+
protected function sql():array{
5252

5353
if(empty($this->set)){
5454
throw new QueryException('no fields to update specified');
@@ -62,7 +62,7 @@ public function set(array $set, bool|null $bind = null):static{
6262
foreach($set as $k => $v){
6363

6464
if($v instanceof Statement){
65-
$this->set[] = $this->dialect->quote($k).' = ('.$v->sql().')';
65+
$this->set[] = $this->dialect->quote($k).' = ('.$v->getSQL().')';
6666

6767
if($v instanceof BindValues){
6868
$this->bindValues = array_merge($this->bindValues, $v->getBindValues());

tests/Query/QueryTestAbstract.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public function testSelectCached():void{
213213

214214
$r = $this->db->select->from([$this::TABLE])->cached(2);
215215
$getCacheKey = $this->getMethod('cacheKey');
216-
$cacheKey = $getCacheKey->invokeArgs($this->db, [$r->sql(), [], 'hash']);
216+
$cacheKey = $getCacheKey->invokeArgs($this->db, [$r->getSQL(), [], 'hash']);
217217

218218
// uncached
219219
$this::assertFalse($this->cache->has($cacheKey));
@@ -228,22 +228,22 @@ public function testSelectCached():void{
228228

229229
// raw uncached
230230
$this::assertFalse($this->cache->has($cacheKey));
231-
$this->db->rawCached($r->sql(), 'hash', true, 1);
231+
$this->db->rawCached($r->getSQL(), 'hash', true, 1);
232232

233233
// cached
234234
$this::assertTrue($this->cache->has($cacheKey));
235-
$this->db->rawCached($r->sql(), 'hash', true, 1);
235+
$this->db->rawCached($r->getSQL(), 'hash', true, 1);
236236

237237
sleep(2);
238238
# $this->cache->clear();
239239

240240
// prepared uncached
241241
$this::assertFalse($this->cache->has($cacheKey));
242-
$this->db->preparedCached($r->sql(), [], 'hash', true, 1);
242+
$this->db->preparedCached($r->getSQL(), [], 'hash', true, 1);
243243

244244
// cached
245245
$this::assertTrue($this->cache->has($cacheKey));
246-
$this->db->preparedCached($r->sql(), [], 'hash', true, 1);
246+
$this->db->preparedCached($r->getSQL(), [], 'hash', true, 1);
247247
}
248248

249249
public function testShowDatabases():void{
@@ -294,70 +294,70 @@ public function testCreateDatabaseNoNameException():void{
294294
$this->expectException(QueryException::class);
295295
$this->expectExceptionMessage('no name specified');
296296

297-
$this->db->create->database('')->sql();
297+
$this->db->create->database('')->getSQL();
298298
}
299299

300300
public function testCreateTableNoNameException():void{
301301
$this->expectException(QueryException::class);
302302
$this->expectExceptionMessage('no name specified');
303303

304-
$this->db->create->table('')->sql();
304+
$this->db->create->table('')->getSQL();
305305
}
306306

307307
public function testDropDatabaseNoNameException():void{
308308
$this->expectException(QueryException::class);
309309
$this->expectExceptionMessage('no name specified');
310310

311-
$this->db->drop->database('')->sql();
311+
$this->db->drop->database('')->getSQL();
312312
}
313313

314314
public function testDropTableNoNameException():void{
315315
$this->expectException(QueryException::class);
316316
$this->expectExceptionMessage('no name specified');
317317

318-
$this->db->drop->table('')->sql();
318+
$this->db->drop->table('')->getSQL();
319319
}
320320

321321
public function testInsertTableNoNameException():void{
322322
$this->expectException(QueryException::class);
323323
$this->expectExceptionMessage('no name specified');
324324

325-
$this->db->insert->into('')->sql();
325+
$this->db->insert->into('')->getSQL();
326326
}
327327

328328
public function testInsertInvalidDataException():void{
329329
$this->expectException(QueryException::class);
330330
$this->expectExceptionMessage('no values given');
331331

332-
$this->db->insert->into('foo')->values([])->sql();
332+
$this->db->insert->into('foo')->values([])->getSQL();
333333
}
334334

335335
public function testSelectEmptyFromException():void{
336336
$this->expectException(QueryException::class);
337337
$this->expectExceptionMessage('no FROM expression specified');
338338

339-
$this->db->select->from([])->sql();
339+
$this->db->select->from([])->getSQL();
340340
}
341341

342342
public function testUpdateNoTableException():void{
343343
$this->expectException(QueryException::class);
344344
$this->expectExceptionMessage('no name specified');
345345

346-
$this->db->update->table('')->sql();
346+
$this->db->update->table('')->getSQL();
347347
}
348348

349349
public function testUpdateNoSetException():void{
350350
$this->expectException(QueryException::class);
351351
$this->expectExceptionMessage('no fields to update specified');
352352

353-
$this->db->update->table('foo')->set([])->sql();
353+
$this->db->update->table('foo')->set([])->getSQL();
354354
}
355355

356356
public function testDeleteNoTableException():void{
357357
$this->expectException(QueryException::class);
358358
$this->expectExceptionMessage('no name specified');
359359

360-
$this->db->delete->from('')->sql();
360+
$this->db->delete->from('')->getSQL();
361361
}
362362

363363
}

0 commit comments

Comments
 (0)