From a6d708a76340f520449c2ad8ebdf5808e76410ab Mon Sep 17 00:00:00 2001 From: Paminger Date: Mon, 2 May 2016 00:36:59 +0200 Subject: [PATCH] PG-Array --- application/config/fhcomplete.php | 2 + application/controllers/ModelTest.php | 46 +++++++++++++++++++++ application/core/DB_Model.php | 58 ++++++++++++++++++++++++++- 3 files changed, 104 insertions(+), 2 deletions(-) diff --git a/application/config/fhcomplete.php b/application/config/fhcomplete.php index e893464f9..836112873 100644 --- a/application/config/fhcomplete.php +++ b/application/config/fhcomplete.php @@ -7,4 +7,6 @@ $config['fhc_acl'] = array 'public.tbl_person' => 'basis/person', 'public.tbl_prestudent' => 'basis/person', 'public.tbl_organisationseinheit' => 'basis/organisationseinheit' +, + 'public.tbl_sprache' => 'admin' ); diff --git a/application/controllers/ModelTest.php b/application/controllers/ModelTest.php index 5f223db57..0eced1525 100755 --- a/application/controllers/ModelTest.php +++ b/application/controllers/ModelTest.php @@ -115,5 +115,51 @@ class ModelTest extends FHC_Controller echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'
'; else var_dump($res->retval); + + $this->load->model('core/Sprache_model'); + // Insert Sprache + $data = array + ( + 'sprache' => 'test', + 'bezeichnung' => "{'testsprache'}", + 'locale' => 'te_TE', + 'content' => false + ); + $res = $this->Sprache_model->insert($data); + if ($res->error) + echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'
'; + else + $id = $data['sprache']; + var_dump($res); + + // Update Sprache + $data = array + ( + 'index' => 4, + 'bezeichnung' => "{'TestSprache', 'TestLanguage', 'TestSpanisch'}", + 'content' => true + ); + $res = $this->Sprache_model->update($id, $data); + if ($res->error) + echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'
'; + else + $id=$res->retval; //echo $id; + + // Load Sprache + $res = $this->Sprache_model->load($id); + if ($res->error) + echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'
'; + else + { + $result = $res->retval->result_object(); + var_dump($this->Sprache_model->pgArrayPhp($result[0]->bezeichnung)); + } + + // Delete Sprache + $res = $this->Sprache_model->delete($id); + if ($res->error) + echo 'Error: ',$res->error, ', Code: ',$res->code,' -> ',$res->msg,': ',$res->retval,'
'; + else + var_dump($res->retval); } } diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php index 5d84e3ee4..e8905c630 100644 --- a/application/core/DB_Model.php +++ b/application/core/DB_Model.php @@ -110,8 +110,10 @@ class DB_Model extends FHC_Model return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->dbTable], FHC_MODEL_ERROR); // DB-SELECT - if ($this->db->get_where($this->dbTable, array($this->pk => $id))) - return $this->_success($id); + $result = $this->db->get_where($this->dbTable, array($this->pk => $id)); + //var_dump($result); + if ($result) + return $this->_success($result); else return $this->_error($this->db->error(), FHC_DB_ERROR); } @@ -141,6 +143,58 @@ class DB_Model extends FHC_Model return $this->_error($this->db->error(), FHC_DB_ERROR); } + /** --------------------------------------------------------------- + * Convert PG-Array to PHP-Array + * + * @param integer config.php error code numbers + * @return array + */ + public function pgArrayPhp($s,$start=0,&$end=NULL) + { + if (empty($s) || $s[0]!='{') return NULL; + $return = array(); + $br = 0; + $string = false; + $quote=''; + $len = strlen($s); + $v = ''; + for($i=$start+1; $i<$len;$i++) + { + $ch = $s[$i]; + if (!$string && $ch=='}') + { + if ($v!=='' || !empty($return)) + $return[] = $v; + $end = $i; + break; + } + else + if (!$string && $ch=='{') + $v = $this->pgArrayPhp($s,$i,$i); + else + if (!$string && $ch==',') + { + $return[] = $v; + $v = ''; + } + else + if (!$string && ($ch=='"' || $ch=="'")) + { + $string = TRUE; + $quote = $ch; + } + else + if ($string && $ch==$quote && $s[$i-1]=="\\") + $v = substr($v,0,-1).$ch; + else + if ($string && $ch==$quote && $s[$i-1]!="\\") + $string = FALSE; + else + $v .= $ch; + } + return $return; + } + /** --------------------------------------------------------------- * Invalid ID *