Issue 2694: Add support for CAST and CONVERT functions

git-svn-id: http://xe-core.googlecode.com/svn/branches/luminous@12237 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2012-11-15 16:34:32 +00:00
parent 6f66f4f8b9
commit 156d7655e9
4 changed files with 39 additions and 1 deletions

View file

@ -144,7 +144,7 @@
if(strpos($match,')') !== false) continue;
if(in_array($match, array(',', '.'))) continue;
if($brackets == $total_brackets){
if(!is_numeric($match)) {
if(!is_numeric($match) && !in_array(strtoupper($match), array('UNSIGNED', 'INTEGER', 'AS'))) {
$match = $this->escapeColumnExpression($match);
}
}

View file

@ -380,4 +380,26 @@ class MysqlSelectTest extends MysqlTest {
limit 5";
$this->_test($xml_file, $argsString, $expected);
}
/**
* Add support for CAST / CONVERT function
*/
function testCast()
{
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/cast.xml";
$argsString = '';
$expected = "select cast(`document_srl` as unsigned integer) from `xe_documents` as `documents`";
$this->_test($xml_file, $argsString, $expected);
}
/**
* Add support for CAST / CONVERT function
*/
function testConvert()
{
$xml_file = _TEST_PATH_ . "db/xml_query/mysql/data/convert.xml";
$argsString = '';
$expected = "select convert(`document_srl`, unsigned integer) from `xe_documents` as `documents`";
$this->_test($xml_file, $argsString, $expected);
}
}

View file

@ -0,0 +1,8 @@
<query id="getDocumentListWithinComment" action="select">
<tables>
<table name="documents" alias="documents" />
</tables>
<columns>
<column name="CAST(document_srl as UNSIGNED INTEGER)" />
</columns>
</query>

View file

@ -0,0 +1,8 @@
<query id="getDocumentListWithinComment" action="select">
<tables>
<table name="documents" alias="documents" />
</tables>
<columns>
<column name="CONVERT(document_srl, UNSIGNED INTEGER)" />
</columns>
</query>