Changeset 13

Show
Ignore:
Timestamp:
10/09/06 02:40:15
Author:
svn
Message:

support for PostgreSQL (actually tested)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phptagengine.class.inc.php

    r12 r13  
    22 
    33// Copyright (c) 2006 Alex King. All rights reserved. 
    4 // http://www.alexking.org/software/phptagengine/ 
     4// http://alexking.org/projects/php-tag-engine 
    55// 
    66// Released under the LGPL license 
     
    3333        var $db; 
    3434        /** 
     35         * Column name escape string for the database being used. Checks for: mysql, postgres7, mssql 
     36         * 
     37         * @var string 
     38         */ 
     39        var $db_col_escape_char; 
     40        /** 
    3541         * Name of the tags table in the database 
    3642         * 
     
    181187                $this->language = 'english'; 
    182188                $this->charset = 'UTF-8'; 
     189                $this->db_type = 'mysql'; 
    183190                $this->strings = array(); 
    184191                $this->tag_browse_url = 'http://example.com/index.php?view=tags&tag=<tag>&type=<type>'; 
     
    196203                $this->version = '1.0'; 
    197204        } 
     205         
     206        /** 
     207         * Sets the character used for escaping column names for the database type in use 
     208         */ 
     209        function set_db_col_escape_char() { 
     210                switch ($this->db->databaseType) { 
     211                        case 'mysql': 
     212                                $this->db_col_escape_char = '`'; 
     213                                break; 
     214                        case 'postgres7': 
     215                        case 'mssql': 
     216                                $this->db_col_escape_char = '"'; 
     217                                break; 
     218                } 
     219        } 
    198220 
    199221        /** 
     
    267289                        INSERT 
    268290                        INTO $this->table_tag_names 
    269                         ( name 
     291                        ( ".$this->db_col_escape_char."name".$this->db_col_escape_char." 
    270292                        ) 
    271293                        VALUES  
     
    273295                        ) 
    274296                ") or die($this->db->ErrorMsg().' in '.__FILE__); 
     297                 
    275298                if ($result) { 
    276                         return $this->db->Insert_ID(); 
    277                 } 
     299                        $id = false; 
     300                        if (strstr($this->db->databaseType, 'postgres')) { 
     301                                $id = $this->db->GetOne(" 
     302                                        SELECT CURRVAL('".$this->table_tag_names."_id_seq') as id 
     303                                ") or die($this->db->ErrorMsg()); 
     304                        } 
     305                        else { 
     306                                $id = $this->db->Insert_ID(); 
     307                        } 
     308                        return $id; 
     309                } 
     310                 
    278311                return false; 
    279312        } 
     
    305338                } 
    306339                else { 
     340                        $this->set_db_col_escape_char(); 
    307341                        $result = $this->db->Execute(" 
    308342                                INSERT 
    309343                                INTO $this->table_tags 
    310                                 ( $this->table_tags.user 
    311                                 , $this->table_tags.item 
    312                                 , $this->table_tags.type 
    313                                 , $this->table_tags.tag 
    314                                 , $this->table_tags.date 
     344                                ( ".$this->db_col_escape_char."user".$this->db_col_escape_char." 
     345                                , ".$this->db_col_escape_char."item".$this->db_col_escape_char." 
     346                                , ".$this->db_col_escape_char."type".$this->db_col_escape_char." 
     347                                , ".$this->db_col_escape_char."tag".$this->db_col_escape_char." 
     348                                , ".$this->db_col_escape_char."date".$this->db_col_escape_char." 
    315349                                ) 
    316350                                VALUES