Skip to content

Commit

Permalink
[WIP] Refactored Model (#12328)
Browse files Browse the repository at this point in the history
* Refactored Model::validate().
* Refactored Model::hasChanged().
* Refactored Model::_checkForeignKeys*().
* Refactored Model::skipAttributes().
* Refactored ModelManager::setConnectionService().
* Refactored ModelManager::get*Records().
* Refactored ModelManager::get*().
* Removed unused variables.
* Refactored ModelManager::getRelationsBetween().
* Refactored ModelManager::getModelSource().
* Refactored ModelManager::notifyEvent().
* Refactored ModelManager::getModelSchema().
* Refactored ModelManager::missingMethod().
* Refactored ModelManager::_getConnectionService().
* Refactored Model::setSnapshotData().
* Refactored ModelRelation::isForeignKey().
* Refactored ModelMetadata::(read|write)MetaDataIndex().
* Removed call_user_func_array calls from Model Transaction
* Refactored ModelCriteria::*where().
* Refactored ModelQueryBuilder::*where().
* Refactored ModelManager::getCustomEventsManager().
* Refactored ModelManager::getRelationByAlias().
* Refactored ModelManager::getRelations().
* Refactored ModelManager::get*Records().
* Refactored ModelManager::load().
* Refactored Model::_getRelatedRecords().
* Refactored Model::_invokeFinder().
* Refactored ModelMetadata::getStrategy().
* Removed a weird loop.
* Removed weird loop.
* Removed weird loop.
  • Loading branch information
SidRoberts authored and sergeyklay committed Oct 21, 2016
1 parent cda3929 commit 29e8771
Show file tree
Hide file tree
Showing 10 changed files with 604 additions and 1,056 deletions.
147 changes: 47 additions & 100 deletions phalcon/db/adapter/pdo/mysql.zep
Original file line number Diff line number Diff line change
Expand Up @@ -128,161 +128,108 @@ class Mysql extends PdoAdapter implements AdapterInterface
*/
let columnType = field[1];

loop {

if memstr(columnType, "enum") {
/**
* Enum are treated as char
*/
if memstr(columnType, "enum") {
let definition["type"] = Column::TYPE_CHAR;
break;
}

let definition["type"] = Column::TYPE_CHAR;
} elseif memstr(columnType, "bigint") {
/**
* Smallint/Bigint/Integers/Int are int
*/
if memstr(columnType, "bigint") {
let definition["type"] = Column::TYPE_BIGINTEGER,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_INT;
break;
}

let definition["type"] = Column::TYPE_BIGINTEGER,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_INT;
} elseif memstr(columnType, "int") {
/**
* Smallint/Bigint/Integers/Int are int
*/
if memstr(columnType, "int") {
let definition["type"] = Column::TYPE_INTEGER,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_INT;
break;
}

let definition["type"] = Column::TYPE_INTEGER,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_INT;
} elseif memstr(columnType, "varchar") {
/**
* Varchar are varchars
*/
if memstr(columnType, "varchar") {
let definition["type"] = Column::TYPE_VARCHAR;
break;
}

let definition["type"] = Column::TYPE_VARCHAR;
} elseif memstr(columnType, "datetime") {
/**
* Special type for datetime
*/
if memstr(columnType, "datetime") {
let definition["type"] = Column::TYPE_DATETIME;
break;
}

let definition["type"] = Column::TYPE_DATETIME;
} elseif memstr(columnType, "char") {
/**
* Chars are chars
*/
if memstr(columnType, "char") {
let definition["type"] = Column::TYPE_CHAR;
break;
}

let definition["type"] = Column::TYPE_CHAR;
} elseif memstr(columnType, "date") {
/**
* Date are dates
*/
if memstr(columnType, "date") {
let definition["type"] = Column::TYPE_DATE;
break;
}

let definition["type"] = Column::TYPE_DATE;
} elseif memstr(columnType, "timestamp") {
/**
* Timestamp are dates
*/
if memstr(columnType, "timestamp") {
let definition["type"] = Column::TYPE_TIMESTAMP;
break;
}

let definition["type"] = Column::TYPE_TIMESTAMP;
} elseif memstr(columnType, "text") {
/**
* Text are varchars
*/
if memstr(columnType, "text") {
let definition["type"] = Column::TYPE_TEXT;
break;
}

let definition["type"] = Column::TYPE_TEXT;
} elseif memstr(columnType, "decimal") {
/**
* Decimals are floats
*/
if memstr(columnType, "decimal"){
let definition["type"] = Column::TYPE_DECIMAL,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_DECIMAL;
break;
}

let definition["type"] = Column::TYPE_DECIMAL,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_DECIMAL;
} elseif memstr(columnType, "double") {
/**
* Doubles
*/
if memstr(columnType, "double"){
let definition["type"] = Column::TYPE_DOUBLE,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_DECIMAL;
break;
}

let definition["type"] = Column::TYPE_DOUBLE,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_DECIMAL;
} elseif memstr(columnType, "float") {
/**
* Float/Smallfloats/Decimals are float
*/
if memstr(columnType, "float") {
let definition["type"] = Column::TYPE_FLOAT,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_DECIMAL;
break;
}

let definition["type"] = Column::TYPE_FLOAT,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_DECIMAL;
} elseif memstr(columnType, "bit") {
/**
* Boolean
*/
if memstr(columnType, "bit") {
let definition["type"] = Column::TYPE_BOOLEAN,
definition["bindType"] = Column::BIND_PARAM_BOOL;
break;
}

let definition["type"] = Column::TYPE_BOOLEAN,
definition["bindType"] = Column::BIND_PARAM_BOOL;
} elseif memstr(columnType, "tinyblob") {
/**
* Tinyblob
*/
if memstr(columnType, "tinyblob") {
let definition["type"] = Column::TYPE_TINYBLOB,
definition["bindType"] = Column::BIND_PARAM_BOOL;
break;
}

let definition["type"] = Column::TYPE_TINYBLOB,
definition["bindType"] = Column::BIND_PARAM_BOOL;
} elseif memstr(columnType, "mediumblob") {
/**
* Mediumblob
*/
if memstr(columnType, "mediumblob") {
let definition["type"] = Column::TYPE_MEDIUMBLOB;
break;
}

let definition["type"] = Column::TYPE_MEDIUMBLOB;
} elseif memstr(columnType, "longblob") {
/**
* Longblob
*/
if memstr(columnType, "longblob") {
let definition["type"] = Column::TYPE_LONGBLOB;
break;
}

let definition["type"] = Column::TYPE_LONGBLOB;
} elseif memstr(columnType, "blob") {
/**
* Blob
*/
if memstr(columnType, "blob") {
let definition["type"] = Column::TYPE_BLOB;
break;
}

let definition["type"] = Column::TYPE_BLOB;
} else {
/**
* By default is string
*/
let definition["type"] = Column::TYPE_VARCHAR;
break;
}

/**
Expand Down
Loading

0 comments on commit 29e8771

Please sign in to comment.