From 6157938ad5dd9d48607921593ca4ed7bff3e3a8b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Jan 2008 22:22:42 +0000 Subject: --- system/database/drivers/mysqli/mysqli_driver.php | 15 ++++++++------- system/database/drivers/oci8/oci8_driver.php | 15 ++++++++------- system/database/drivers/odbc/odbc_driver.php | 15 ++++++++------- system/database/drivers/postgre/postgre_driver.php | 15 ++++++++------- system/database/drivers/sqlite/sqlite_driver.php | 15 ++++++++------- 5 files changed, 40 insertions(+), 35 deletions(-) diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index d295ca9f2..94a29937b 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -446,27 +446,28 @@ class CI_DB_mysqli_driver extends CI_DB { // This function may get "item1 item2" as a string, and so // we may need "`item1` `item2`" and not "`item1 item2`" - if (strpos($item, ' ') !== FALSE) + if (ctype_alnum($item) === FALSE) { // This function may get "field >= 1", and need it to return "`field` >= 1" - if ($first_word_only === TRUE) - { - return '`'.preg_replace('/ /', '` ', $item, 1); - } + $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + } + else + { + return "`{$item}`"; } $exceptions = array('AS', '/', '-', '%', '+', '*'); foreach ($exceptions as $exception) { + if (stristr($item, " `{$exception}` ") !== FALSE) { $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); } } - return $item; } diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 6d3b72261..160a56d51 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -557,27 +557,28 @@ class CI_DB_oci8_driver extends CI_DB { // This function may get "item1 item2" as a string, and so // we may need "`item1` `item2`" and not "`item1 item2`" - if (strpos($item, ' ') !== FALSE) + if (ctype_alnum($item) === FALSE) { // This function may get "field >= 1", and need it to return "`field` >= 1" - if ($first_word_only === TRUE) - { - return '`'.preg_replace('/ /', '` ', $item, 1); - } + $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + } + else + { + return "`{$item}`"; } $exceptions = array('AS', '/', '-', '%', '+', '*'); foreach ($exceptions as $exception) { + if (stristr($item, " `{$exception}` ") !== FALSE) { $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); } } - return $item; } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 0bdfc41d5..c5c582d0b 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -422,27 +422,28 @@ class CI_DB_odbc_driver extends CI_DB { // This function may get "item1 item2" as a string, and so // we may need "`item1` `item2`" and not "`item1 item2`" - if (strpos($item, ' ') !== FALSE) + if (ctype_alnum($item) === FALSE) { // This function may get "field >= 1", and need it to return "`field` >= 1" - if ($first_word_only === TRUE) - { - return '`'.preg_replace('/ /', '` ', $item, 1); - } + $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + } + else + { + return "`{$item}`"; } $exceptions = array('AS', '/', '-', '%', '+', '*'); foreach ($exceptions as $exception) { + if (stristr($item, " `{$exception}` ") !== FALSE) { $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); } } - return $item; } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 63a72f5d3..fa27f03d5 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -444,27 +444,28 @@ class CI_DB_postgre_driver extends CI_DB { // This function may get "item1 item2" as a string, and so // we may need ""item1" "item2"" and not ""item1 item2"" - if (strpos($item, ' ') !== FALSE) + if (ctype_alnum($item) === FALSE) { // This function may get "field >= 1", and need it to return ""field" >= 1" - if ($first_word_only === TRUE) - { - return '"'.preg_replace('/ /', '" ', $item, 1); - } + $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + } + else + { + return ""{$item}""; } $exceptions = array('AS', '/', '-', '%', '+', '*'); foreach ($exceptions as $exception) { + if (stristr($item, " "{$exception}" ") !== FALSE) { $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); } } - return $item; } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 2d0ca157c..110b208d2 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -438,27 +438,28 @@ class CI_DB_sqlite_driver extends CI_DB { // This function may get "item1 item2" as a string, and so // we may need "`item1` `item2`" and not "`item1 item2`" - if (strpos($item, ' ') !== FALSE) + if (ctype_alnum($item) === FALSE) { // This function may get "field >= 1", and need it to return "`field` >= 1" - if ($first_word_only === TRUE) - { - return '`'.preg_replace('/ /', '` ', $item, 1); - } + $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + } + else + { + return "`{$item}`"; } $exceptions = array('AS', '/', '-', '%', '+', '*'); foreach ($exceptions as $exception) { + if (stristr($item, " `{$exception}` ") !== FALSE) { $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); } } - return $item; } -- cgit v1.2.3-24-g4f1b