Commit 1ec02075 authored by metzlerd's avatar metzlerd
Browse files

Added abilit to support basic types for numeric data.

parent db9c75cf
......@@ -495,6 +495,30 @@ class FrxDataSource{
}
return $clause;
}
public function parmConvert($key, $value) {
if (isset($this->types[$key]) && $this->types[$key]) {
if ($value === NULL || $value ==='') {
$value = NULL;
}
else {
switch (strtolower($this->types[$key])) {
case 'numeric':
case 'flaot':
$value = (float)$value;
break;
case 'int':
case 'integer':
$value = (int)$value;
break;
case 'array':
$value = (array)$value;
break;
}
}
}
return $value;
}
}
......@@ -37,6 +37,9 @@ class FrxDrupal extends FrxDataSource {
if ($this->database != 'default') {
db_set_active($this->database);
}
// Load the types array based on data
$this->types = isset($options['type']) ? $options['type'] : array();
// Load the block from the file
$xml ='';
$sql = $this->te->replace($sql);
......@@ -136,6 +139,7 @@ class FrxDrupal extends FrxDataSource {
*/
public function format($value, $key, $data) {
$db = Database::getConnection('default');
$value = $this->parmConvert($key, $value);
if ($db) {
if ($value==='' || $value===NULL)
$value = 'NULL';
......@@ -158,6 +162,14 @@ class FrxDrupal extends FrxDataSource {
$value = $val;
}
}
elseif (is_int($value)) {
$value = (int)$value;
$value = (string)$value;
}
elseif (is_float($value)) {
$value = (float)$value;
$value = (string)$value;
}
else {
$value = trim($value);
$value = $db->quote($value) ;
......
......@@ -65,6 +65,8 @@ class FrxMSSQL extends FrxDataSource {
// Load the block from the file
$db = $this->db;
$xml ='';
// Load the types array based on data
$this->types = isset($options['type']) ? $options['type'] : array();
if ($sql && $db) {
$sql = $this->te->replace($sql);
......@@ -137,7 +139,19 @@ class FrxMSSQL extends FrxDataSource {
* @param unknown_type $data
*/
public function format($value, $key, $data) {
if ($value===''||$value===NULL) $value = 'NULL'; else $value = "'" . str_replace("'", "''", $value) . "'";
$value = $this->parmConvert($key, $value);
if ($value===''||$value===NULL) {
$value = 'NULL';
}
elseif (is_int($value)) {
$value = (int)$value;
$value = (string)$value;
}
elseif (is_float($value)) {
$value = (float)$value;
$value = (string)$value;
}
else $value = "'" . str_replace("'", "''", $value) . "'";
return $value;
}
......
......@@ -280,6 +280,7 @@ class FrxOracle extends FrxDataSource {
* @param unknown_type $data
*/
public function format($value, $key, $data) {
$value = $this->parmConvert($key, $value);
if ($value==='' || $value ===NULL || $value ===array())
$value = 'NULL';
else {
......@@ -304,11 +305,20 @@ class FrxOracle extends FrxDataSource {
$value = $val . ')';
}
}
elseif (is_int($value)) {
$value = (int)$value;
$value = (string)$value;
}
elseif (is_float($value)) {
$value = (float)$value;
$value = (string)$value;
}
else {
$value = trim($value);
$value = "'" . str_replace("'", "''", $value) . "'";
}
}
return $value;
}
......
......@@ -136,10 +136,19 @@ class FrxPDO extends FrxDataSource {
*/
public function format($value, $key, $data) {
$db = $this->db;
$value = $this->parmConvert($key, $value);
if ($db) {
if ($value==='' || $value ===NULL || $value === array()) {
$value = 'NULL';
}
elseif (is_int($value)) {
$value = (int)$value;
$value = (string)$value;
}
elseif (is_float($value)) {
$value = (float)$value;
$value = (string)$value;
}
elseif (is_array($value)) {
if ($value == array()) {
$value = 'NULL';
......
......@@ -131,6 +131,7 @@ class FrxPostgres extends FrxDataSource {
* @param unknown_type $data
*/
public function format($value, $key, $data) {
$value = $this->parmConvert($key, $value);
if ($value===''||$value===NULL)
$value = 'NULL';
else {
......@@ -152,6 +153,15 @@ class FrxPostgres extends FrxDataSource {
$value = $val;
}
}
elseif (is_int($value)) {
$value = (int)$value;
$value = (string)$value;
}
elseif (is_float($value)) {
$value = (float)$value;
$value = (string)$value;
}
else {
$value = trim($value);
$value = "'" . pg_escape_string($value) . "'";
......
......@@ -2,6 +2,11 @@
SELECT nid, type, title, uid, sticky, promote from node WHERE type=:content_type
and status=1
ORDER BY title
--IF=:limit
LIMIT :limit
--INFO
; This demonstrates loading node entities.
entity_type = node
entity_id = nid
\ No newline at end of file
entity_id = nid
; the following demonstrates an optional limit clause that can be used with SQL
type[limit] = int
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment