diff options
author | Stanislav <stanislau.wolski@gmail.com> | 2011-11-11 17:57:23 +0300 |
---|---|---|
committer | Stanislav <stanislau.wolski@gmail.com> | 2011-11-11 17:57:23 +0300 |
commit | e0ee7661fd524e342cb57b73a098986d85c94fbd (patch) | |
tree | 60011a82d7d162987999f3cd6a5c8a47b58c8d86 /codebase | |
parent | c83f0293bc6f67ceb4c141c9051683302e1f9d12 (diff) | |
parent | 7a79e1d9a75908f8f36c43117dbc1be95ee363fa (diff) | |
download | connector-php-e0ee7661fd524e342cb57b73a098986d85c94fbd.zip connector-php-e0ee7661fd524e342cb57b73a098986d85c94fbd.tar.gz connector-php-e0ee7661fd524e342cb57b73a098986d85c94fbd.tar.bz2 |
Merge branch 'dev' of 192.168.1.251:connector-php into dev
Diffstat (limited to 'codebase')
-rw-r--r-- | codebase/base_connector.php | 8 | ||||
-rw-r--r-- | codebase/db_common.php | 23 | ||||
-rw-r--r-- | codebase/db_mssql.php | 3 | ||||
-rw-r--r-- | codebase/db_oracle.php | 3 | ||||
-rw-r--r-- | codebase/db_pdo.php | 8 | ||||
-rw-r--r-- | codebase/db_postgre.php | 3 | ||||
-rw-r--r-- | codebase/db_sasql.php | 54 | ||||
-rw-r--r-- | codebase/db_sqlsrv.php | 3 |
8 files changed, 100 insertions, 5 deletions
diff --git a/codebase/base_connector.php b/codebase/base_connector.php index 76351b9..451c61d 100644 --- a/codebase/base_connector.php +++ b/codebase/base_connector.php @@ -230,7 +230,7 @@ class DataItem{ @return escaped string */ - protected function xmlentities($string) { + public function xmlentities($string) { return str_replace( array( '&', '"', "'", '<', '>', '’' ), array( '&' , '"', ''' , '<' , '>', ''' ), $string); } @@ -387,6 +387,12 @@ class Connector { $this->request->parse_sql($sql); return $this->render(); } + + public function render_complex_sql($sql,$id,$fields,$extra=false,$relation_id=false){ + $this->config->init($id,$fields,$extra,$relation_id); + $this->request->parse_sql($sql, true); + return $this->render(); + } /*! render already configured connector diff --git a/codebase/db_common.php b/codebase/db_common.php index a37d54d..996feda 100644 --- a/codebase/db_common.php +++ b/codebase/db_common.php @@ -215,14 +215,28 @@ class DataRequestConfig{ @param sql incoming sql string */ - public function parse_sql($sql){ - $sql= preg_replace("/[ \n\t]+limit[\n ,0-9]/i","",$sql); + public function parse_sql($sql, $as_is = false){ + if ($as_is){ + $this->fieldset = $sql; + return; + } + + $sql= preg_replace("/[ \n\t]+limit[\n\t ,0-9]*$/i","",$sql); $data = preg_split("/[ \n\t]+\\_from\\_/i",$sql,2); if (count($data)!=2) $data = preg_split("/[ \n\t]+from/i",$sql,2); $this->fieldset = preg_replace("/^[\s]*select/i","",$data[0],1); - + + //Ignore next type of calls + //direct call to stored procedure without FROM + if ((count($data) == 1) || + //UNION select + preg_match("#[ \n\r\t]union[ \n\t\r]#i", $sql)){ + $this->fieldset = $sql; + return; + } + $table_data = preg_split("/[ \n\t]+where/i",$data[1],2); /* if sql code contains group_by we will place all sql query in the FROM @@ -719,6 +733,9 @@ abstract class DBDataWrapper extends DataWrapper{ sql string for select operation */ protected function select_query($select,$from,$where,$sort,$start,$count){ + if (!$from) + return $select; + $sql="SELECT ".$select." FROM ".$from; if ($where) $sql.=" WHERE ".$where; if ($sort) $sql.=" ORDER BY ".$sort; diff --git a/codebase/db_mssql.php b/codebase/db_mssql.php index e082c03..0bbcf63 100644 --- a/codebase/db_mssql.php +++ b/codebase/db_mssql.php @@ -43,6 +43,9 @@ class MsSQLDBDataWrapper extends DBDataWrapper{ } protected function select_query($select,$from,$where,$sort,$start,$count){ + if (!$from) + return $select; + $sql="SELECT " ; if ($count) $sql.=" TOP ".($count+$start); diff --git a/codebase/db_oracle.php b/codebase/db_oracle.php index 5dcbd71..210af43 100644 --- a/codebase/db_oracle.php +++ b/codebase/db_oracle.php @@ -58,6 +58,9 @@ class OracleDBDataWrapper extends DBDataWrapper{ } protected function select_query($select,$from,$where,$sort,$start,$count){ + if (!$from) + return $select; + $sql="SELECT ".$select." FROM ".$from; if ($where) $sql.=" WHERE ".$where; if ($sort) $sql.=" ORDER BY ".$sort; diff --git a/codebase/db_pdo.php b/codebase/db_pdo.php index 281b23d..c008adb 100644 --- a/codebase/db_pdo.php +++ b/codebase/db_pdo.php @@ -15,12 +15,18 @@ class PDODBDataWrapper extends DBDataWrapper{ LogMaster::log($sql); $res=$this->connection->query($sql); - if ($res===false) throw new Exception("PDO - sql execution failed\n".$this->connection->errorInfo()); + if ($res===false) { + $message = $this->connection->errorInfo(); + throw new Exception("PDO - sql execution failed\n".$message[2]); + } return new PDOResultSet($res); } protected function select_query($select,$from,$where,$sort,$start,$count){ + if (!$from) + return $select; + $sql="SELECT ".$select." FROM ".$from; if ($where) $sql.=" WHERE ".$where; if ($sort) $sql.=" ORDER BY ".$sort; diff --git a/codebase/db_postgre.php b/codebase/db_postgre.php index f944714..011bd47 100644 --- a/codebase/db_postgre.php +++ b/codebase/db_postgre.php @@ -17,6 +17,9 @@ class PostgreDBDataWrapper extends DBDataWrapper{ } protected function select_query($select,$from,$where,$sort,$start,$count){ + if (!$from) + return $select; + $sql="SELECT ".$select." FROM ".$from; if ($where) $sql.=" WHERE ".$where; if ($sort) $sql.=" ORDER BY ".$sort; diff --git a/codebase/db_sasql.php b/codebase/db_sasql.php new file mode 100644 index 0000000..85959df --- /dev/null +++ b/codebase/db_sasql.php @@ -0,0 +1,54 @@ +<?php +require_once("db_common.php"); +/*! SaSQL implementation of DataWrapper +**/ +class SaSQLDBDataWrapper extends DBDataWrapper{ + private $last_id=""; //!< ID of previously inserted record + + public function query($sql){ + LogMaster::log($sql); + $res=sasql_query($this->connection, $sql); + if ($res===false) throw new Exception("SaSQL operation failed\n".sasql_error($this->connection)); + $this->last_result = $res; + return $res; + } + + public function get_next($res){ + if (!$res) + $res = $this->last_result; + + return sasql_fetch_assoc($res); + } + + protected function get_new_id(){ + return sasql_insert_id($this->connection); + } + + protected function insert_query($data,$request){ + $sql = parent::insert_query($data,$request); + $this->insert_operation=true; + return $sql; + } + + protected function select_query($select,$from,$where,$sort,$start,$count){ + if (!$from) + return $select; + + $sql="SELECT " ; + if ($count) + $sql.=" TOP ".($count+$start); + $sql.=" ".$select." FROM ".$from; + if ($where) $sql.=" WHERE ".$where; + if ($sort) $sql.=" ORDER BY ".$sort; + return $sql; + } + + public function escape($data){ + return sasql_escape_string($this->connection, $data); + } + + public function begin_transaction(){ + $this->query("BEGIN TRAN"); + } +} +?>
\ No newline at end of file diff --git a/codebase/db_sqlsrv.php b/codebase/db_sqlsrv.php index c0f9299..597a74d 100644 --- a/codebase/db_sqlsrv.php +++ b/codebase/db_sqlsrv.php @@ -60,6 +60,9 @@ class SQLSrvDBDataWrapper extends DBDataWrapper{ } protected function select_query($select,$from,$where,$sort,$start,$count){ + if (!$from) + return $select; + $sql="SELECT " ; if ($count) $sql.=" TOP ".($count+$start); |