~desarrollokumbia/kumbia/ActiveRecord

« back to all changes in this revision

Viewing changes to db_pool/adapters/mysql_db.php

  • Committer: Deivinson Tejeda
  • Date: 2010-01-24 20:53:08 UTC
  • Revision ID: deivinsontejeda@gmail.com-20100124205308-hsovf0apo3pbg3s0
Mejorando el chain where, quedan ahora los metodos where() y whereOr y se puede concatenar los where, ademas se crea un método interno para el DbQuery quien ira armando el los where en el orden como se vayan llamando y para dejar mas facil el where y whereOr solo reciben string asi no liamos a los usarios con array, sin embargo seguimos evaluando
Eje...
    public function consulta()
    {
        $this->get()->where('id < :id2')
                    ->where('id > :id')
                    ->bind(array(':id'=>2, ':id2'=>5));
        return $this->find();
    }
la consulta generada del anterios chain es:
SELECT * FROM prueba WHERE  (id < :id2)  AND (id > :id)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
     **/
32
32
    public function describe($table, $schema=null)
33
33
    {
34
 
        try {
35
 
            $results = $this->pdo()->query("DESCRIBE $table");
36
 
                        
37
 
            if ($results) {
38
 
                require_once CORE_PATH . 'libs/ActiveRecord/db_pool/metadata.php';
39
 
                $metadata = new Metadata();
40
 
                while ($field = $results->fetchObject()) {
41
 
                    //Nombre del Campo
42
 
                    $attribute = $metadata->attribute($field->Field);
43
 
                    //alias
44
 
                    $attribute->alias =  ucwords(strtr($field->Field,'_-','  '));
45
 
                    
46
 
                    // autoincremental
47
 
                    if ($field->Extra === 'auto_increment') {
48
 
                        $attribute->autoIncrement = TRUE;
49
 
                    }
50
 
                    
51
 
                    // valor por defecto
52
 
                    $attribute->default = $field->Default;
53
 
                    
54
 
                    //puede ser null?
55
 
                    if($field->Null == 'NO'){
56
 
                        $attribute->notNull = FALSE;
57
 
                    }
58
 
 
59
 
                    //tipo de dato y longitud
60
 
                    if(preg_match('/^(\w+)\((\w+)\)$/', $field->Type, $matches)) {
61
 
                        $attribute->type = $matches[1];
62
 
                        $attribute->length = $matches[2];
63
 
                    } else {
64
 
                        $attribute->type = $field->Type;
65
 
                        $attribute->length = NULL;
66
 
                    }
67
 
 
68
 
                    //indices
69
 
                    switch ($field->Key){
70
 
                        case 'PRI':
71
 
                            $metadata->setPK($field->Field);
72
 
                            $attribute->PK = TRUE;
73
 
                            break;
74
 
                        case 'FK':
75
 
                            $metadata->setFK($field->Field);
76
 
                            $attribute->FK = TRUE;
77
 
                            break;
78
 
                        case 'UNI':
79
 
                            $attribute->unique = TRUE;
80
 
                            break;
81
 
                    }
82
 
                }
 
34
        if($schema) {
 
35
            $source = "$schema.$table";
 
36
        } else {
 
37
            $source = $table;
 
38
        }
 
39
        
 
40
        $tableMetaData = TableMetaData::getInstance($this->_connection, $schema, $table);
 
41
        if(!$tableMetaData->isLoaded()) {
 
42
            $stmt = $this->pdo()->query("DESCRIBE $source");
 
43
            
 
44
            $metadata = array();
 
45
            foreach($stmt as $row) {
 
46
                // aqui falta el codigo para ajustarlo que funcione con el mysql
83
47
            }
84
 
        } catch (PDOException $e) {
85
 
            throw new KumbiaException($e->getMessage());
 
48
            
 
49
            $tableMetaData->setMetadata($metadata);
86
50
        }
87
 
        return $metadata;
 
51
        
 
52
        return $tableMetaData;
88
53
    }
89
54
}