~desarrollokumbia/kumbia/ActiveRecord

« back to all changes in this revision

Viewing changes to db_pool/adapters/pgsql_db.php

  • Committer: Deivinson Tejeda
  • Date: 2010-01-10 14:12:33 UTC
  • Revision ID: deivinsontejeda@gmail.com-20100110141233-aw1q2fulb90v8dk2
arreglos en el adapter de pgsql

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
            //ejecutando la consulta preparada
57
57
            $results = $prepare->execute(array('database'=>'test', 'schema'=>'public', 'table'=>'prueba'));
58
58
            if ($results) {
59
 
                require_once CORE_PATH . 'libs/ActiveRecord/db_pool/rows.php';
60
 
                $row = new Rows();
 
59
                require_once CORE_PATH . 'libs/ActiveRecord/db_pool/metadata.php';
 
60
                $metadata = new Metadata();
61
61
                while ($field = $prepare->fetchObject()) {
62
62
                    //Nombre del Campo
63
 
                    $column = $row->column($field->name);
64
 
                    $column->setAlias($field->name);
 
63
                    $attribute = $metadata->attribute($field->name);
 
64
                    //alias
 
65
                    $attribute->alias =  ucwords(strtr($field->name,'_-','  '));
65
66
                    //valor por defecto
66
67
                    if (! is_null($field->default)) {
67
68
                        if (strpos($field->default, 'nextval(') !== FALSE) {
68
 
                            $column->autoIncrement = TRUE;
 
69
                            $attribute->autoIncrement = TRUE;
69
70
                        } elseif ($field->type == 'serial' || $field->type == 'bigserial') {
70
 
                            $column->autoIncrement = TRUE;
 
71
                            $attribute->autoIncrement = TRUE;
71
72
                        } else {
72
 
                            $column->default = $field->default;
 
73
                            $attribute->default = $field->default;
73
74
                        }
74
75
                    }
75
76
                    //puede ser null?
76
77
                    if($field->null == 'NO'){
77
 
                        $column->notNull = FALSE;
 
78
                        $attribute->notNull = FALSE;
78
79
                    }
79
80
                    //Relaciones
80
81
                    if(substr($field->name, strlen($field->name) -3, 3) == '_id'){
81
 
                        $row->setRelation($field->name, $column->relation);
 
82
                        $metadata->setRelation($field->name, $attribute->relation);
 
83
                        $attribute->alias =  ucwords(strtr($field->name,'_-','  '));
82
84
                    }
83
85
                    //tipo de dato
84
 
                    $column->type = $field->type;
 
86
                    $attribute->type = $field->type;
85
87
                    //longitud
86
 
                    $column->length = $field->length;
 
88
                    $attribute->length = $field->length;
87
89
                    //indices
88
90
                    switch ($field->index){
89
91
                        case 'PRI':
90
 
                            $row->setPK($field->name);
91
 
                            $column->PK = TRUE;
 
92
                            $metadata->setPK($field->name);
 
93
                            $attribute->PK = TRUE;
92
94
                            break;
93
95
                        case 'FK':
94
 
                            $row->setFK($field->name);
95
 
                            $column->FK = TRUE;
 
96
                            $metadata->setFK($field->name);
 
97
                            $attribute->FK = TRUE;
96
98
                            break;
97
99
                        case 'UNI':
98
 
                            $column->unique = TRUE;
 
100
                            $attribute->unique = TRUE;
99
101
                            break;
100
102
                    }
101
103
                }
103
105
        } catch (PDOException $e) {
104
106
            throw new KumbiaException($e->getMessage());
105
107
        }
106
 
        return $row;
 
108
        return $metadata;
107
109
    }
108
110
}