summaryrefslogtreecommitdiff
path: root/lib/SQL.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/SQL.php')
-rw-r--r--lib/SQL.php61
1 files changed, 55 insertions, 6 deletions
diff --git a/lib/SQL.php b/lib/SQL.php
index d568200..add6fa6 100644
--- a/lib/SQL.php
+++ b/lib/SQL.php
@@ -42,6 +42,8 @@ class SQL
'identifier_end' => '"',
);
+ const DEFAULT_QUOTE = '`';
+
/**
* This implements the 'singleton' design pattern
@@ -82,7 +84,8 @@ class SQL
'sybase' => 'mssql',
'dblib' => 'mssql',
'mysqli' => 'mysql',
- 'oracle' => 'oci',
+ 'oci' => 'oracle',
+ 'oci8' => 'oracle',
);
$driver = isset($driver_map[$driver]) ? $driver_map[$driver] : $driver;
@@ -172,6 +175,9 @@ class SQL
$query = $this->set_limit($query, $numrows, $offset);
}
+ // replace self::DEFAULT_QUOTE with driver-specific quoting
+ $query = $this->query_parse($query);
+
$pos = 0;
$idx = 0;
@@ -212,6 +218,51 @@ class SQL
}
/**
+ * Parse SQL query and replace identifier quoting
+ *
+ * @param string $query SQL query
+ *
+ * @return string SQL query
+ */
+ protected function query_parse($query)
+ {
+ $start = $this->options['identifier_start'];
+ $end = $this->options['identifier_end'];
+ $quote = self::DEFAULT_QUOTE;
+
+ if ($start == $quote) {
+ return $query;
+ }
+
+ $pos = 0;
+ $in = false;
+
+ while ($pos = strpos($query, $quote, $pos)) {
+ if ($query[$pos+1] == $quote) { // skip escaped quote
+ $pos += 2;
+ }
+ else {
+ if ($in) {
+ $q = $end;
+ $in = false;
+ }
+ else {
+ $q = $start;
+ $in = true;
+ }
+
+ $query = substr_replace($query, $q, $pos, 1);
+ $pos++;
+ }
+ }
+
+ // replace escaped quote back to normal, see self::quote()
+ $query = str_replace($quote.$quote, $quote, $query);
+
+ return $query;
+ }
+
+ /**
* Helper method to handle DB errors.
* This by default logs the error but could be overriden by a driver implementation
*
@@ -259,10 +310,6 @@ class SQL
*/
public function fetch_assoc($result = null)
{
- if (!$this->connect()) {
- return null;
- }
-
return $this->fetch_row($result, PDO::FETCH_ASSOC);
}
@@ -347,7 +394,9 @@ class SQL
$type = isset($map[$type]) ? $map[$type] : PDO::PARAM_STR;
- return strtr($this->conn->quote($input, $type), array('?' => '??')); // escape ?
+ return strtr($this->conn->quote($input, $type), array(
+ '?' => '??', self::DEFAULT_QUOTE => self::DEFAULT_QUOTE.self::DEFAULT_QUOTE
+ ));
}
/**