Changeset 5971 for trunk/prototype/services/PostgreSQL.php
- Timestamp:
- 04/18/12 18:19:41 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/prototype/services/PostgreSQL.php
r5933 r5971 15 15 $justthese = self::parseJustthese($justthese, $map); 16 16 17 return $this->exec ResultSql( 'SELECT '.$justthese['select'].' FROM '. (Config::get($uri['concept'],'PostgreSQL.concept')) .' '.$criteria );17 return $this->execSql( 'SELECT '.$justthese['select'].' FROM '. (Config::get($uri['concept'],'PostgreSQL.concept')) .' '.$criteria ); 18 18 } 19 19 … … 22 22 $map = Config::get($uri['concept'], 'PostgreSQL.mapping'); 23 23 $justthese = self::parseJustthese($justthese, $map); 24 $criteria = ($criteria !== false) ? $this->parseCriteria ( $criteria , $map , ' WHERE id = \''.addslashes( $uri['id'] ).'\'') : ' WHERE id= \''.addslashes( $uri['id'] ).'\'';24 $criteria = ($criteria !== false) ? $this->parseCriteria ( $criteria , $map , ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\'') : ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\''; 25 25 26 return $this->exec ResultSql( 'SELECT '.$justthese['select'].' FROM '. (Config::get($uri['concept'],'PostgreSQL.concept')) .$criteria , true );26 return $this->execSql( 'SELECT '.$justthese['select'].' FROM '. (Config::get($uri['concept'],'PostgreSQL.concept')) .$criteria , true ); 27 27 } 28 28 … … 33 33 } 34 34 35 public function delete ( $uri, $justthese = false ){ 36 return $this->execSql('DELETE FROM '.(Config::get($uri['concept'],'PostgreSQL.concept')).' WHERE id = '.addslashes($uri['id'])); 35 public function delete ( $uri, $justthese = false, $criteria = false ){ 36 $map = Config::get($uri['concept'], 'PostgreSQL.mapping'); 37 if(!self::parseCriteria ( $criteria , $map)) return false; //Validador para não apagar tabela inteira 38 $criteria = ($criteria !== false) ? $this->parseCriteria ( $criteria , $map , ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\'') : ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\''; 39 return $this->execSql('DELETE FROM '.(Config::get($uri['concept'],'PostgreSQL.concept')).$criteria); 37 40 } 38 41 … … 48 51 49 52 public function create ( $uri, $data ){ 50 return $this->execResultSql( 'INSERT INTO '.(Config::get($uri['concept'],'PostgreSQL.concept')).' '.self::parseInsertData( $data , $uri['concept'] ), true ); 51 } 52 53 private function execSql( $sql ){ 54 if(!$this->con) $this->open( $this->config ); 53 return $this->execSql( 'INSERT INTO '.(Config::get($uri['concept'],'PostgreSQL.concept')).' '.self::parseInsertData( $data , $uri['concept'] ), true ); 54 } 55 56 public function execSql( $sql, $unique = false ) 57 { 58 if(!$this->con) $this->open( $this->config ); 55 59 56 60 $rs = pg_query( $this->con, $sql ); 57 61 58 if ( !$rs ){ 59 $this->error = pg_last_error ( $this->con ); 60 return false; 61 } 62 63 return $rs; 64 } 65 62 if( is_bool( $rs ) ) 63 { 64 if ( !$rs ) 65 $this->error = pg_last_error ( $this->con ); 66 67 return( $rs ); 68 } 69 70 if( pg_num_rows( $rs ) <= 0 ) 71 return array(); 72 73 $return = array(); 74 75 while( $row = pg_fetch_assoc( $rs ) ) 76 $return[] = $row; 77 78 return( $unique ? $return[0] : $return ); 79 } 80 81 //@DEPRECATED 66 82 public function execResultSql( $sql, $unique = false ){ 67 $rs = $this->execSql( $sql ); 68 69 if( $rs && $rs > 0 ) 70 return self::parseSelectResult( $rs , $unique ); 71 72 return $rs; 83 return $this->execSql( $sql, $unique ); 73 84 } 74 85 … … 146 157 } 147 158 148 return '('.implode(',', $ind).') VALUES ('.implode(',', $val).') RETURNING id';159 return '('.implode(',', $ind).') VALUES ('.implode(',', $val).') RETURNING '.$map['id'].' as id'; 149 160 } 150 161 … … 161 172 return 'SET '.implode(',', $d); 162 173 } 163 164 private static function parseSelectResult( $result , $unique = false){ 165 166 $return = array(); 167 168 if (!$result) return false; 169 if (pg_num_rows($result) === 0) return $return; 170 else 171 while( $row = pg_fetch_assoc( $result )) 172 $return[] = $row; 173 174 if($unique === true) return $return[0]; 175 176 return $return; 177 } 178 174 179 175 private static function parseCriteria( $criteria , &$map , $query = '' ){ 180 176
Note: See TracChangeset
for help on using the changeset viewer.