From fe0fd407cf3b43b2b20491a2c7ab7e492f7668e5 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Sun, 30 Dec 2012 12:21:49 -0500 Subject: [PATCH] Added inc/decrement functionality to the Model Sure beats incrementing the variable then setting it! Usage: $model->record['column'] = '++'; // or '--'. Only works with single row updates at the moment. May expand into allowing a variable step to be defined (+10 or ++10 or something... I say that cause I think the double character is a bit safer since you could in theory set a value to -10000 and not want it to decrement by 10k) --- classes/Model.php | 12 +++++++++++- jar.php | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/classes/Model.php b/classes/Model.php index 822bc54..51f2e70 100644 --- a/classes/Model.php +++ b/classes/Model.php @@ -1301,7 +1301,17 @@ class Model extends Object $sql .= ', '; } - $sql .= $column . ' = ?'; + $sql .= $column . ' = '; + + if (in_array($value, array('++', '--'))) + { + $sql .= $column . ' ' . substr($value, 0, 1) . ' ?'; + $value = 1; + } + else + { + $sql .= '?'; + } } else { diff --git a/jar.php b/jar.php index e29fd92..21a4470 100755 --- a/jar.php +++ b/jar.php @@ -5560,7 +5560,17 @@ class Model extends Object $sql .= ', '; } - $sql .= $column . ' = ?'; + $sql .= $column . ' = '; + + if (in_array($value, array('++', '--'))) + { + $sql .= $column . ' ' . substr($value, 0, 1) . ' ?'; + $value = 1; + } + else + { + $sql .= '?'; + } } else {