diff --git a/classes/db/DBCubrid.class.php b/classes/db/DBCubrid.class.php index f0bf25499..165444499 100644 --- a/classes/db/DBCubrid.class.php +++ b/classes/db/DBCubrid.class.php @@ -5,7 +5,7 @@ * @brief Cubrid DBMS to use the class * @version 1.0 * - * Works with CUBRID up to 8.4.0 + * Works with CUBRID up to 8.4.1 **/ class DBCubrid extends DB @@ -67,7 +67,7 @@ **/ function __connect($connection) { - // attempts to connect + // attempts to connect $result = @cubrid_connect($connection["db_hostname"], $connection["db_port"], $connection["db_database"], $connection["db_userid"], $connection["db_password"]); // check connections @@ -75,7 +75,15 @@ $this->setError (-1, 'database connect fail'); return; } - return $result; + + if(!defined('__CUBRID_VERSION__')) { + $cubrid_version = cubrid_get_server_info($result); + $cubrid_version_elem = explode('.', $cubrid_version); + $cubrid_version = $cubrid_version_elem[0] . '.' . $cubrid_version_elem[1] . '.' . $cubrid_version_elem[2]; + define('__CUBRID_VERSION__', $cubrid_version); + } + + return $result; } /** diff --git a/classes/db/queryparts/condition/Condition.class.php b/classes/db/queryparts/condition/Condition.class.php index c482626f5..5fe11adf3 100644 --- a/classes/db/queryparts/condition/Condition.class.php +++ b/classes/db/queryparts/condition/Condition.class.php @@ -108,7 +108,11 @@ case 'like_tail' : case 'like_prefix' : case 'like' : - return $name.' like '.$value; + if(defined('__CUBRID_VERSION__') + && __CUBRID_VERSION__ >= '8.4.1') + return $name.' rlike '.$value; + else + return $name.' like '.$value; break; case 'notlike_tail' : case 'notlike_prefix' : diff --git a/classes/xml/xmlquery/argument/ConditionArgument.class.php b/classes/xml/xmlquery/argument/ConditionArgument.class.php index cdbebfdf0..f734d2a1d 100644 --- a/classes/xml/xmlquery/argument/ConditionArgument.class.php +++ b/classes/xml/xmlquery/argument/ConditionArgument.class.php @@ -23,13 +23,27 @@ switch($operation) { case 'like_prefix' : - $this->value = $value.'%'; + if(defined('__CUBRID_VERSION__') + && __CUBRID_VERSION__ >= '8.4.1') { + $this->value = '^' . str_replace('%', '(.*)', preg_quote($value)); + } + else + $this->value = $value.'%'; break; case 'like_tail' : - $this->value = '%'.$value; + if(defined('__CUBRID_VERSION__') + && __CUBRID_VERSION__ >= '8.4.1') + $this->value = str_replace('%', '(.*)', preg_quote($value)) . '$'; + else + $this->value = '%'.$value; break; case 'like' : - $this->value = '%'.$value.'%'; + if(defined('__CUBRID_VERSION__') + && __CUBRID_VERSION__ >= '8.4.1') { + $this->value = str_replace('%', '(.*)', preg_quote($value)); + } + else + $this->value = '%'.$value.'%'; break; case 'notlike' : $this->value = '%'.$value.'%'; diff --git a/tests/classes/db/db/xml_query/cubrid/CubridSelectTest.php b/tests/classes/db/db/xml_query/cubrid/CubridSelectTest.php index c5192733a..31c1f1f78 100644 --- a/tests/classes/db/db/xml_query/cubrid/CubridSelectTest.php +++ b/tests/classes/db/db/xml_query/cubrid/CubridSelectTest.php @@ -392,5 +392,13 @@ where "expired" <= \'' . date("YmdHis") . '\''; $this->_test($xml_file, $argsString, $expected); } + + function test_rlike_1(){ + $xml_file = _TEST_PATH_ . "db/xml_query/cubrid/data/rlike1.xml"; + $argsString = '$args->title = "aaa";'; + $expected = 'select * from "xe_modules" as "modules" where "title" rlike \'aaa\''; + define('__CUBRID_VERSION__', '8.4.1'); + $this->_test($xml_file, $argsString, $expected); + } } \ No newline at end of file diff --git a/tests/classes/db/db/xml_query/cubrid/data/rlike1.xml b/tests/classes/db/db/xml_query/cubrid/data/rlike1.xml new file mode 100644 index 000000000..895b1ccb0 --- /dev/null +++ b/tests/classes/db/db/xml_query/cubrid/data/rlike1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + +