diff options
author | Christian Schneider | 2012-11-22 15:43:29 +0000 |
---|---|---|
committer | Christian Schneider | 2012-11-22 15:43:29 +0000 |
commit | 38375bbec1f031be9d3b3e500a758d974e36cce4 (patch) | |
tree | 945c5092277fe47e4024cf11b26cbc68509c7085 | |
parent | 97cc6b69d05b43cea9e66af01fca6e11148cb92a (diff) | |
download | itools-38375bbec1f031be9d3b3e500a758d974e36cce4.tar.gz itools-38375bbec1f031be9d3b3e500a758d974e36cce4.tar.bz2 itools-38375bbec1f031be9d3b3e500a758d974e36cce4.zip |
Remove smart_replace() as alias for store() because it is even worse a name than store()
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | it_dbi.class | 10 | ||||
-rwxr-xr-x | tests/it_dbi.t | 23 |
3 files changed, 9 insertions, 26 deletions
@@ -91,7 +91,7 @@ Functions: $t->update($fields) -- update selected record from key=>value pairs $t->insert($fields) -- insert a new record from key=>value pairs $t->replace($fields) -- replace a new record from key=>value pairs - $t->smart_replace($fields) -- create a record or update efficiently if exists + $t->store($fields) -- create a record or update efficiently if exists $t->delete($query) -- delete current record or those found by query $t->query($sqlquery) -- execute a raw SQL query on db connection $t = Tablename::get($id) -- return valid object loaded with record $id or null diff --git a/it_dbi.class b/it_dbi.class index 6e0d5df..8210b04 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -688,21 +688,13 @@ function replace($tags = array()) * MUST GIVE ALL FIELDS INCLUDING ID * @param $tags key => value pairs to set */ -function smart_replace($tags = array()) +function store($tags = array()) { return $tags[$this->_p['keyfield']] && $this->read($tags[$this->_p['keyfield']]) ? $this->update($tags) : $this->replace($tags); } /** - * Maintain backward compatibility store() == smart_replace() to avoid unnecessary API BC break - */ -function store($tags = array()) -{ - return $this->smart_replace($tags); -} - -/** * Update current record or a number of records given by where condition * @param $tags key => value pairs (these have priority over changes in member vars) * @param $where condition to select records to be modified (if not current record) diff --git a/tests/it_dbi.t b/tests/it_dbi.t index 8623437..b0b25ef 100755 --- a/tests/it_dbi.t +++ b/tests/it_dbi.t @@ -237,52 +237,43 @@ foreach ($record as $dummy_rec) is($count, 2, "Iterator reused"); $GLOBALS['debug_sqllog'] = true; -@$record->smart_replace(array('ID' => 5, 'x' => 6)); +@$record->store(array('ID' => 5, 'x' => 6)); like( $record->_sqllog[1]['query'], "REPLACE", - "smart_replace => REPLACE for new entries" + "store => REPLACE for new entries" ); $record->clear(); @$record->read(5); is( $record->x, 6, - "saving with smart_replace" + "saving with store" ); $record->_sqllog = array(); -@$record->smart_replace(array('ID' => 5, 'x' => 7)); +@$record->store(array('ID' => 5, 'x' => 7)); like( $record->_sqllog[1]['query'], "UPDATE", - "smart_replace => UPDATE for existing entries" + "store => UPDATE for existing entries" ); $record->clear(); @$record->read(5); is( $record->x, 7, - "updating with smart_replace" + "updating with store" ); $record->_sqllog = array(); -@$record->smart_replace(array('ID' => 5, 'x' => 7)); +@$record->store(array('ID' => 5, 'x' => 7)); is( $record->_sqllog[1]['query'], null, # Only SELECT, no UPDATE "Optimized away UPDATE with same values" ); -$record->_sqllog = array(); -method_exists($record, "store") && @$record->store(array('ID' => 5, 'x' => 8)); -like( - $record->_sqllog[1]['query'], - "UPDATE", - "Check for store() alias of smart_replace for backward compatibility" -); -$GLOBALS['debug_sqllog'] = false; - # Test field localization feature $dbi->query('create temporary table it_dbi_testlocalized ( |