Skip to content

Commit 2b83925

Browse files
committed
bug fix, add/update preset table functions, finish removing global functions where table name passed in
1 parent ede99e1 commit 2b83925

File tree

6 files changed

+100
-36
lines changed

6 files changed

+100
-36
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ Mainly by:
2929
- Renamed `select` of `ez_mysqli` to `dbSelect`.
3030
- Renamed class method and behavior of `selecting` to `select`.
3131
- `selecting`, and new `inserting` methods, can be called without table name, only the other necessary parameters:
32-
- The Table *name* with *prefix*, can be preset/stored with methods `tableSetup(name, prefix), or setTable(name), setPrefix(append)`, if called without presetting, `false` is returned.
33-
- This **feature** will be added to **all** database access methods, each method name will have an `ing` ending added.
32+
- The table *name* with *prefix*, can be preset/stored with methods `tableSetup(name, prefix), or setTable(name), setPrefix(append)`, if called without presetting, `false` is returned.
33+
- This **feature** will be added to **all** database *CRUD* access methods , each method name will have an `ing` ending added.
34+
- Removed global functions where `table` name passed in, use functions using preset table names ending with `ing`.
3435

3536
[__version 4__](https://github.com/ezSQL/ezsql/tree/v4) has many modern programming practices in which will break users of version 3.
3637

lib/ezFunctions.php

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ function inserting(array $keyValue)
595595
/**
596596
* Preforms a `update` method call on a already preset `table name`, and optional `prefix`
597597
*
598-
* This function **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)`
598+
* This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
599599
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
600600
*
601601
* Does an `update` query with an array, by conditional operator array
@@ -632,7 +632,7 @@ function updating(array $keyValue, ...$whereConditions)
632632
/**
633633
* Preforms a `create` method call on a already preset `table name`, and optional `prefix`
634634
*
635-
* This function **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)`
635+
* This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
636636
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
637637
*
638638
* Creates an database table with columns, by either:
@@ -664,7 +664,7 @@ function creating(...$schemas)
664664
/**
665665
* Preforms a `delete` method call on a already preset `table name`, and optional `prefix`
666666
*
667-
* This function **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)`
667+
* This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
668668
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
669669
*
670670
* Does an `delete` query with an array
@@ -698,6 +698,42 @@ function deleting(...$whereConditions)
698698
: false;
699699
}
700700

701+
/**
702+
* Preforms a `replace` method call on a already preset `table name`, and optional `prefix`
703+
*
704+
* This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
705+
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
706+
*
707+
* Does an `replace` query with an array
708+
* @param array $keyValue - table fields, assoc array with key = value (doesn't need escaping)
709+
* @return mixed bool/id of replaced record, or false for error
710+
*/
711+
function replacing(array $keyValue)
712+
{
713+
$ezQuery = getInstance();
714+
return ($ezQuery instanceof DatabaseInterface)
715+
? $ezQuery->replacing($keyValue)
716+
: false;
717+
}
718+
719+
/**
720+
* Preforms a `drop` method call on a already preset `table name`, and optional `prefix`
721+
*
722+
* This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
723+
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
724+
*
725+
* Does an `drop` table query if table exists.
726+
*
727+
* @return bool|int
728+
*/
729+
function dropping()
730+
{
731+
$ezQuery = getInstance();
732+
return ($ezQuery instanceof DatabaseInterface)
733+
? $ezQuery->dropping()
734+
: false;
735+
}
736+
701737
/**
702738
* Set table `name` and `prefix` for global usage on calls to database
703739
* **method/function** *names* ending with `ing`.
@@ -744,7 +780,7 @@ function set_prefix(string $append = '')
744780
}
745781

746782
/**
747-
* Does an select into statement by calling selecting method
783+
* Does an `select into` statement by calling `select` method
748784
* @param $newTable, - new database table to be created
749785
* @param $fromColumns - the columns from old database table
750786
* @param $oldTable - old database table
@@ -1081,7 +1117,7 @@ function fullJoin(
10811117
}
10821118

10831119
/**
1084-
* Returns an `UNION` SELECT SQL string, given the
1120+
* Returns an `UNION` SELECT `SQL` string, given the
10851121
* - table, column fields, conditions or conditional array.
10861122
*
10871123
* In the following format:
@@ -1112,7 +1148,7 @@ function union($table = '', $columnFields = '*', ...$conditions)
11121148
}
11131149

11141150
/**
1115-
* Returns an `UNION ALL` SELECT SQL string, given the
1151+
* Returns an `UNION ALL` SELECT `SQL` string, given the
11161152
* - table, column fields, conditions or conditional array.
11171153
*
11181154
* In the following format:
@@ -1174,20 +1210,6 @@ function limit($numberOf, $offset = null)
11741210
: false;
11751211
}
11761212

1177-
/**
1178-
* Does an `replace` query with an array
1179-
* @param $table, - database table to access
1180-
* @param $keyValue - table fields, assoc array with key = value (doesn't need escaping)
1181-
* @return mixed bool/id of replaced record, or false for error
1182-
*/
1183-
function replace($table = '', $keyValue = null)
1184-
{
1185-
$ezQuery = getInstance();
1186-
return ($ezQuery instanceof DatabaseInterface)
1187-
? $ezQuery->replace($table, $keyValue)
1188-
: false;
1189-
}
1190-
11911213
function ezFunctions()
11921214
{
11931215
return true;

lib/ezQuery.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -987,12 +987,6 @@ public function alter(string $table = null, ...$schemas)
987987
return false;
988988
}
989989

990-
/**
991-
* Does an `drop` table query if table exists.
992-
* @param $table - database table to erase
993-
*
994-
* @return bool
995-
*/
996990
public function drop(string $table = null)
997991
{
998992
if (empty($table))
@@ -1039,6 +1033,12 @@ public function creating(...$schemas)
10391033
return ($table === false) ? false : $this->create($table, ...$schemas);
10401034
}
10411035

1036+
public function dropping()
1037+
{
1038+
$table = $this->table_prefix();
1039+
return ($table === false) ? false : $this->drop($table);
1040+
}
1041+
10421042
/**
10431043
* Check and return the stored **global** database `table` preset with any `prefix`.
10441044
*

lib/ezQueryInterface.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,18 @@ public function deleting(...$whereConditions);
610610
*/
611611
public function replace(string $table = null, $keyValue);
612612

613+
/**
614+
* Preforms a `replace` method call on a already preset `table name`, and optional `prefix`
615+
*
616+
* This method **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)`
617+
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
618+
*
619+
* Does an `replace` query with an array
620+
* @param array $keyValue - table fields, assoc array with key = value (doesn't need escaping)
621+
* @return mixed bool/id of replaced record, or false for error
622+
*/
623+
function replacing(array $keyValue);
624+
613625
/**
614626
* Does an `insert` query with an array
615627
* @param $table, - database table to access
@@ -700,4 +712,24 @@ public function create(string $table = null, ...$schemas);
700712
* @return mixed results of query() call
701713
*/
702714
public function creating(...$schemas);
715+
716+
/**
717+
* Does an `drop` table query if table exists.
718+
* @param string $table - database table to erase
719+
*
720+
* @return bool|int
721+
*/
722+
public function drop(string $table = null);
723+
724+
/**
725+
* Preforms a `drop` method call on a already preset `table name`, and optional `prefix`
726+
*
727+
* This method **expects** either `tableSetup(name, prefix)`, `setTable(name)`, or `setPrefix(append)`
728+
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
729+
*
730+
* Does an `drop` table query if table exists.
731+
*
732+
* @return bool|int
733+
*/
734+
public function dropping();
703735
}

tests/ezFunctionsTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
updating,
4242
creating,
4343
deleting,
44-
replace,
44+
dropping,
45+
replacing,
4546
selecting,
4647
inserting,
4748
table_setup,
@@ -263,6 +264,16 @@ public function testSelecting()
263264
$this->assertFalse(selecting());
264265
}
265266

267+
public function testReplacing()
268+
{
269+
$this->assertFalse(replacing(['data' => 'data2']));
270+
}
271+
272+
public function testDropping()
273+
{
274+
$this->assertFalse(dropping());
275+
}
276+
266277
public function testSet_Table()
267278
{
268279
$this->assertFalse(set_table());
@@ -272,9 +283,4 @@ public function testSet_Prefix()
272283
{
273284
$this->assertFalse(set_prefix());
274285
}
275-
276-
public function testReplace()
277-
{
278-
$this->assertFalse(replace('field', ['data' => 'data2']));
279-
}
280286
}

tests/mysqli/mysqliTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ public function testReplace()
268268

269269
public function testCreatingReplacing()
270270
{
271+
$this->object->quick_connect();
271272
$this->object->prepareOff();
272273
$this->assertFalse($this->object->replacing([]));
273274
$this->assertFalse($this->object->creating([]));
@@ -276,12 +277,14 @@ public function testCreatingReplacing()
276277
$this->assertEquals(
277278
0,
278279
$this->object->creating(
279-
column('id', INTR, 11, PRIMARY),
280+
column('id', INTR, 11, AUTO, PRIMARY),
280281
column('test_key', VARCHAR, 50)
281282
)
282283
);
283284

284-
inserting(array('id' => 3, 'test_key' => 'test 3'));
285+
inserting(array('test_key' => 'test 1'));
286+
inserting(array('test_key' => 'test 2'));
287+
inserting(array('test_key' => 'test 3'));
285288
$this->assertEquals(3, $this->object->replacing(array('id' => 3, 'test_key' => 'test 4')));
286289
}
287290

0 commit comments

Comments
 (0)