- $parts = preg_split('/\sORDER\s*BY\s/si', $sql, 2);
- if(count($parts) == 2) {
- $sql = $parts[0];
- $this->order = $parts[1];
- }
- $parts = preg_split('/\sGROUP\s*BY\s/si', $sql, 2);
- if(count($parts) == 2) {
- $sql = $parts[0];
- $this->group = $parts[1];
- }
- $parts = preg_split('/\sWHERE\s/si', $sql, 2);
- if(count($parts) == 2) {
- $sql = $parts[0];
- $this->where = $parts[1];
- }
- $parts = preg_split('/\sFROM\s/si', $sql, 2);
- if(count($parts) == 2) {
- $sql = $parts[0];
- $this->from = $parts[1];
+
+ if(is_array($sql)) {
+ foreach(explode(' ', 'select from where group order') as $section) {
+ $this->$section = @$sql[$section];
+ }
+ $this->select = "SELECT ".$this->select;
+ }
+ else {
+ // parse the query
+ $parts = preg_split('/\sFROM\s/si', $sql, 2);
+ if (count($parts) == 2) {
+ $this->select = $parts[0];
+ $sql = $parts[1];
+ } else {
+ if ($SysPrefs->go_debug)
+ display_error("Invalid sql input for db_pager");
+ }
+
+ $parts = preg_split('/\sWHERE(?!.*WHERE.*)\s/si', $sql, 2); // last occurence
+ if(count($parts) == 2) {
+ $this->from = $parts[0];
+ $sql = $parts[1];
+
+ $parts = preg_split('/\sORDER\s*BY\s/si', $sql, 2);
+ if(count($parts) == 2) {
+ $sql = $parts[0];
+ $this->order = $parts[1];
+ }
+ $parts = preg_split('/\sGROUP\s*BY\s/si', $sql, 2);
+ if(count($parts) == 2) {
+ $sql = $parts[0];
+ $this->group = $parts[1];
+ }
+ $this->where = $sql;
+ }