summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schneider2017-04-26 15:57:03 +0200
committerChristian Schneider2017-04-26 15:57:03 +0200
commit1fcbcc10d2eaa05d1f2a0c9355832c46932bcff8 (patch)
treeafaa38e8cb527d293260df6b14aef6818e315c9c
parentc81def8b826f25adbd8ac53a89898f56f5552267 (diff)
downloaditools-1fcbcc10d2eaa05d1f2a0c9355832c46932bcff8.tar.gz
itools-1fcbcc10d2eaa05d1f2a0c9355832c46932bcff8.tar.bz2
itools-1fcbcc10d2eaa05d1f2a0c9355832c46932bcff8.zip
Style and dead code cleanup
-rw-r--r--it_dbi.class36
1 files changed, 19 insertions, 17 deletions
diff --git a/it_dbi.class b/it_dbi.class
index 5159431..c814aa6 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -242,13 +242,13 @@ function _connect($p = array())
*/
function _set($tags, $allfields = false)
{
- $r = array();
+ $result = array();
foreach((array)$tags as $field => $value)
{
if (substr($field, 0, 1) === "-" && !$this->_fields[trim($field, "-")] && $this->_fields['dyncols'])
$dyns[] = $this->escape_string(trim($field, "-")) . ", $value";
else if (substr($field, 0, 1) === '-') # Unquoted value (always added)
- $r[] = substr($field, 1)."=$value";
+ $result[] = substr($field, 1) . "=$value";
else if ($allfields || (isset($value) && isset($this->_data[$field]) ? strval($value) !== strval($this->_data[$field]) : $value !== $this->_data[$field]))
{
if ($this->_p['charset'] == "utf8") # NOTE: Mysql charset is simply utf8, not utf-8
@@ -257,27 +257,28 @@ function _set($tags, $allfields = false)
if (!$this->_fields[$field] && $this->_fields['dyncols'])
$dyns[] = $this->escape_string(trim($field, "-")) . ", " . (!isset($value) ? 'NULL' : (it::match('^\d+$', $value) ? $value : ($this->escape_string($value))));
else
- $r[] = "`$field`=".(isset($value) ? $this->escape_string($value) : 'NULL');
+ $result[] = "`$field`=" . (isset($value) ? $this->escape_string($value) : 'NULL');
}
}
if (($dyn = join(", ", (array)$dyns)))
- $r[] = "dyncols = IF(dyncols IS NULL, COLUMN_CREATE($dyn), COLUMN_ADD(dyncols, $dyn))";
+ $result[] = "dyncols = IF(dyncols IS NULL, COLUMN_CREATE($dyn), COLUMN_ADD(dyncols, $dyn))";
- return $r ? 'SET '.implode(', ', $r) : '';
+ return $result ? 'SET ' . implode(', ', $result) : '';
}
/**
* INTERNAL: construct SQL FROM clause of fields JOIN and FROM in query params
+ * @see select()
*/
-function _from($params = null, $omit_from = false) {
- $res = $this->_p['table'];
+function _from($params, $omit_from = false)
+{
+ $result = $this->_p['table'];
+
if (isset($params['JOIN']) || isset($params['FROM'])) # WARNING: this field gets abused for "tablename USE INDEX (fast2)
- {
- $res = trim($params['FROM'] . " " . $params['JOIN']);
- unset($params['JOIN'], $params['FROM']);
- }
- return ($omit_from ? "" : "FROM ") . $res;
+ $result = trim($params['FROM'] . " " . $params['JOIN']);
+
+ return ($omit_from ? "" : "FROM ") . $result;
}
@@ -299,9 +300,10 @@ function _from($params = null, $omit_from = false) {
* @see select()
* @see iterate()
*/
-function _where($params = null, $dummy_link = null, $omit_where = false)
+function _where($params)
{
unset($params['JOIN'], $params['FROM']);
+
if (is_array($params) && (count($params) > 0))
{
$query = '';
@@ -402,7 +404,7 @@ function _where($params = null, $dummy_link = null, $omit_where = false)
$query .= $stringquery;
- if ($needs_where && !$omit_where)
+ if ($needs_where)
$query = "WHERE $query";
}
@@ -607,7 +609,7 @@ function select(/* $query = array|string, ... */)
unset($query['NOFETCH']);
$this->clear(false);
- if ($this->_result = $this->query($sql = "SELECT $what " . $this->_from($query) . " " . $this->_where($query, $this->_link)))
+ if ($this->_result = $this->query($sql = "SELECT $what " . $this->_from($query) . " " . $this->_where($query)))
{
$result = $this->_p['unbuffered'] ? true : mysqli_num_rows($this->_result);
@@ -761,7 +763,7 @@ function update($tags = array(), $where = null)
if (!isset($where))
$where = array($this->_p['keyfield'] => $this->_data[$this->_p['keyfield']]);
- if ($result = $this->query("UPDATE " . $this->_from($where, true) . " $set " . $this->_where($where, $this->_link)))
+ if ($result = $this->query("UPDATE " . $this->_from($where, true) . " $set " . $this->_where($where)))
{
$result = mysqli_affected_rows($this->_link);
@@ -794,7 +796,7 @@ function delete($query = null)
$this->clear();
}
- if ($query && $this->query("DELETE " . $this->_from($query) . " " . $this->_where($query, $this->_link)))
+ if ($query && $this->query("DELETE " . $this->_from($query) . " " . $this->_where($query)))
$result = mysqli_affected_rows($this->_link);
return $result;