Skip to content

Commit

Permalink
[#13543] Add more pdo types (#13562)
Browse files Browse the repository at this point in the history
* [#13543] - Work on the ENUM for PostgreSql

* [#13543] - Adjusted tests

* [#13543] - Corrected if clause

* [#13543] - Added enum to the PG sample file

* [#13543] - Trying to correct the sql file again

* [#13543] - Reverting changes

* [#13543] - Reverting tests and sql file

* [#13543] - Initial commit for a nanobox isolated environment for tests

* [#13543] - Reintroduced enum type parsing

* [#13543] - Adjusted test

* [#13543] - Again reverting some changes

* [#13543] - Reorganized the if statement

* [#13543] - Reorganized if statement

* [#13543] - More sorting

* [#13543] - Reorganization

* [#13543] - Added bool and bit

* [#13543] - Added initial describe test

* [#13543] - Corrections to the table name and import file

* [#13543] - Minor change to the boxfile; Added boxfile constants to the tests; Changed case in SQL file

* [#13543] - Changed JSON type to TEXT

* [#13543] - More work on the db

* [#13543] - Another correction to the sql file

* [#13543] - Test corrections

* [#13543] - Test corrections

* [#13543] - Corrected the bind parameter type

* [#13543] - Added more fields to the column describe test

* [#13543] - Added all the possible columns for the test

* [#13543] - Corrected typo

* [#13543] - More corrections

* [#13543] - Corrections to the test

* [#13543] - More test corrections

* [#13543] - Correction for bool

* [#13543] - Compilation of php-psr for nanobox

* [#13543] - Changes for boolean

* [#13543] - Disabling some columns temporarily

* [#13543] - Debugging booleans

* [#13543] - Minor corrections

* [#13543] - Adjustments to the if statements; tinyint(1) is a boolean

* [#13543] - Booleans are numbers

* [#13543] - Added more fields in the array for the test

* [#13543] - Adjusted the array for describe

* [#13543] - Corrections for floats

* [#13543] - Corrected array index

* [#13543] - Added more elements to the array of the test; corrections

* [#13543] - Corrected indexes in the test array

* [#13543] - Added more assertions

* [#13543] - Added indexes tests

* [#13543] - Fixed typo in test

* [#13543] - Moved the describe test to a better location; Minor corrections

* [#13543] - Split tests to two files

* [#13543] - Renaming and splitting tests

* [#13543] - More test corrections

* [#13543] - Corrected size

* [#13543] - Added reference tests

* [#13543] - More test corrections

* [#13543] - Refactoring

* [#13543] - More refactoring; Added column as object test

* [#13543] - Changed control structure to stitch from if

* [#13543] - Added more types for MySQL

* [#13543] - Added more types

* [#13543] - Aligning equals

* [#13543] - Added column constants tests

* [#13543] - Corrections and additions to tests

* [#13543] - Removed duplicate test; Corrections to the mysql dialect

* [#13543] - Corrected if statement

* [#13543] - Trying to enable Mysql 5.7

* [#13543] - Trying without the password change

* [#13543] - Changed casting for double to be string; Change to the schema for JSON

* [#13543] - Corrections to the test and schema

* [#13543] - Minor corrections

* [#13543] - Initial work for postgresql columns

* [#13543] - Corrected namespace

* [#13543] - Fixing tests

* [#13543] - More test corrections

* [#13543] - Corrected schema and tests

* [#13543] - Renamed the schema files; other corrections

* [#13543] - Corrected schema names

* [#13543] - Correction to the schema and tests

* [#13543] - Added enum in the tests for mysql

* [#13543] - Test corrections

* [#13543] - Added enum for postgresql

* [#13543] - Adjusted the schemas

* [#13543] - Corrections to the dialect for postgresql, schema and adapter

* [#13543] - Minor refactoring in the dialects; Adjustment to tests

* [#13543] - Changed syntax for foreign references in schema; Debugging Columns

* [#13543] - More test corrections

* [#13543] - More test corrections

* [#13543] - Corrected owner

* [#13543] - Reverted the schema to what it iwas

* [#13543] - Trying to correct the schema

* [#13543] - Skipping reference tests for portgresql

* [#13543] - Corrected parameters for test

* [#13543] - Updated the changelog

* [#13543] - Removed boxfile - will send upstream in different commit

* [#13543] - Reformatted class to trigger build

* [#13543] - Corrected names of schema files
  • Loading branch information
niden authored Dec 4, 2018
1 parent 9c3a70f commit c0af848
Show file tree
Hide file tree
Showing 36 changed files with 14,291 additions and 8,552 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ branches:

addons:
apt:
sources:
- mysql-5.7-trusty
packages:
- beanstalkd
- gdb
- lcov
- beanstalkd
- gdb
- lcov
- mysql-server
- mysql-client

matrix:
fast_finish: true
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Added ability to set a custom template for the Flash Messenger. [#13445](https://github.com/phalcon/cphalcon/issues/13445)
- Added `forUpdate` in the Sqlite dialect to override the method from the base dialect. [#13539](https://github.com/phalcon/cphalcon/issues/13539)
- Added `TYPE_ENUM` in the Mysql adapter. [#11368](https://github.com/phalcon/cphalcon/issues/11368)
- Added more column types for the Mysql adapter. The adapter supports `TYPE_BIGINTEGER`, `TYPE_BIT`, `TYPE_BLOB`, `TYPE_BOOLEAN`, `TYPE_CHAR`, `TYPE_DATE`, `TYPE_DATETIME`, `TYPE_DECIMAL`, `TYPE_DOUBLE`, `TYPE_ENUM`, `TYPE_FLOAT`, `TYPE_INTEGER`, `TYPE_JSON`, `TYPE_JSONB`, `TYPE_LONGBLOB`, `TYPE_LONGTEXT`, `TYPE_MEDIUMBLOB`, `TYPE_MEDIUMINTEGER`, `TYPE_MEDIUMTEXT`, `TYPE_SMALLINTEGER`, `TYPE_TEXT`, `TYPE_TIME`, `TYPE_TIMESTAMP`, `TYPE_TINYBLOB`, `TYPE_TINYINTEGER`, `TYPE_TINYTEXT`, `TYPE_VARCHAR` [#13151](https://github.com/phalcon/cphalcon/issues/13151), [#12223](https://github.com/phalcon/cphalcon/issues/12223), [#524](https://github.com/phalcon/cphalcon/issues/524), [#13225](https://github.com/phalcon/cphalcon/pull/13225) [@zGaron](https://github.com/zGaron), [#12523](https://github.com/phalcon/cphalcon/pull/12523) [@Studentsov](https://github.com/Studentsov), [#12471](https://github.com/phalcon/cphalcon/pull/12471) [@ruudboon](https://github.com/ruudboon)
- Added `Phalcon\Acl\Adapter\Memory::addRole` support multiple inherited
- Added `Phalcon\Tag::renderTitle()` that renders the title enclosed in `<title>` tags. [#13547](https://github.com/phalcon/cphalcon/issues/13547)
- Added `hasHeader()` method to `Phalcon\Http\Response` to provide the ability to check if a header exists. [PR-12189](https://github.com/phalcon/cphalcon/pull/12189)
Expand Down
5 changes: 3 additions & 2 deletions phalcon/db/adapter/pdo.zep
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,11 @@ abstract class Pdo extends Adapter
if typeof dataTypes == "array" && fetch type, dataTypes[wildcard] {

/**
* The bind type is double so we try to get the double value
* The bind type needs to be string because the precision
* is lost if it is casted as a double
*/
if type == Column::BIND_PARAM_DECIMAL {
let castValue = doubleval(value),
let castValue = (string) value,
type = Column::BIND_SKIP;
} else {
if globals_get("db.force_casting") {
Expand Down
260 changes: 194 additions & 66 deletions phalcon/db/adapter/pdo/mysql.zep
Original file line number Diff line number Diff line change
Expand Up @@ -97,115 +97,243 @@ class Mysql extends PdoAdapter
*/
let columnType = field[1];

if memstr(columnType, "enum") {
/**
* The order of these IF statements matters. Since we are using memstr
* to figure out whether a particular string exists in the columnType
* we will end up with false positives if the order changes.
*
* For instance if we have a `varchar` column and we check for `char`
* first, then that will match. Therefore we have firs the IF
* statements that are "unique" and further down the ones that can
* appear a substrings of the columnType above them.
*/

switch true {
/**
* Enum are treated as char
* BOOL
*/
let definition["type"] = Column::TYPE_CHAR;
} elseif memstr(columnType, "bigint") {
case memstr(columnType, "tinyint(1)"):
/**
* tinyint(1) is boolean
*/
let definition["type"] = Column::TYPE_BOOLEAN,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_BOOL;
break;

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

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

/**
* Varchar are varchars
* SMALLINT
*/
let definition["type"] = Column::TYPE_VARCHAR;
} elseif memstr(columnType, "datetime") {
case memstr(columnType, "smallint"):
let definition["type"] = Column::TYPE_SMALLINTEGER,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_INT;
break;

/**
* Special type for datetime
* TINYINT
*/
let definition["type"] = Column::TYPE_DATETIME;
} elseif memstr(columnType, "char") {
case memstr(columnType, "tinyint"):
/**
* Smallint/Bigint/Integers/Int are int
*/
let definition["type"] = Column::TYPE_TINYINTEGER,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_INT;
break;

/**
* Chars are chars
* INT
*/
let definition["type"] = Column::TYPE_CHAR;
} elseif memstr(columnType, "date") {
case memstr(columnType, "int"):
let definition["type"] = Column::TYPE_INTEGER,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_INT;

break;

/**
* Date are dates
* BIT
*/
let definition["type"] = Column::TYPE_DATE;
} elseif memstr(columnType, "timestamp") {
case memstr(columnType, "bit"):
let definition["type"] = Column::TYPE_BIT,
definition["bindType"] = Column::BIND_PARAM_INT;
break;

/**
* Timestamp are dates
* ENUM
*/
let definition["type"] = Column::TYPE_TIMESTAMP;
} elseif memstr(columnType, "text") {
case memstr(columnType, "enum"):
let definition["type"] = Column::TYPE_ENUM;
break;


/**
* Text are varchars
* DATE
*/
let definition["type"] = Column::TYPE_TEXT;
} elseif memstr(columnType, "decimal") {
case memstr(columnType, "datetime"):
let definition["type"] = Column::TYPE_DATETIME;
break;

/**
* DATETIME
*/
case memstr(columnType, "date"):
let definition["type"] = Column::TYPE_DATE;
break;

/**
* Decimals are floats
* DECIMAL - This will need to be a string so as not to lose
* the decimals
*/
let definition["type"] = Column::TYPE_DECIMAL,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_DECIMAL;
} elseif memstr(columnType, "double") {
case memstr(columnType, "decimal"):
let definition["type"] = Column::TYPE_DECIMAL,
definition["isNumeric"] = true;
break;

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

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

/**
* Boolean
* MEDIUMBLOB
*/
let definition["type"] = Column::TYPE_BOOLEAN,
definition["bindType"] = Column::BIND_PARAM_BOOL;
} elseif memstr(columnType, "tinyblob") {
case memstr(columnType, "mediumblob"):
let definition["type"] = Column::TYPE_MEDIUMBLOB;
break;

/**
* Tinyblob
* LONGBLOB
*/
let definition["type"] = Column::TYPE_TINYBLOB;
} elseif memstr(columnType, "mediumblob") {
case memstr(columnType, "longblob"):
let definition["type"] = Column::TYPE_LONGBLOB;
break;

/**
* Mediumblob
* TINYBLOB
*/
let definition["type"] = Column::TYPE_MEDIUMBLOB;
} elseif memstr(columnType, "longblob") {
case memstr(columnType, "tinyblob"):
let definition["type"] = Column::TYPE_TINYBLOB;
break;

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

/**
* Blob
* TIMESTAMP
*/
let definition["type"] = Column::TYPE_BLOB;
} else {
case memstr(columnType, "timestamp"):
let definition["type"] = Column::TYPE_TIMESTAMP;
break;

/**
* TIME
*/
case memstr(columnType, "time"):
let definition["type"] = Column::TYPE_TIME;
break;

/**
* JSON
*/
case memstr(columnType, "json"):
let definition["type"] = Column::TYPE_JSON;
break;

/**
* LONGTEXT
*/
case memstr(columnType, "longtext"):
let definition["type"] = Column::TYPE_LONGTEXT;
break;

/**
* MEDIUMTEXT
*/
case memstr(columnType, "mediumtext"):
let definition["type"] = Column::TYPE_MEDIUMTEXT;
break;

/**
* TINYTEXT
*/
case memstr(columnType, "tinytext"):
let definition["type"] = Column::TYPE_TINYTEXT;
break;

/**
* TEXT
*/
case memstr(columnType, "text"):
let definition["type"] = Column::TYPE_TEXT;
break;

/**
* VARCHAR
*/
case memstr(columnType, "varchar"):
let definition["type"] = Column::TYPE_VARCHAR;
break;

/**
* CHAR
*/
case memstr(columnType, "char"):
let definition["type"] = Column::TYPE_CHAR;
break;

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

/**
* If the column type has a parentheses we try to get the column size from it
*/
if memstr(columnType, "(") {
let matches = null;
if preg_match(sizePattern, columnType, matches) {
if definition["type"] == Column::TYPE_ENUM {
let definition["size"] = substr(columnType, 5, -1);
} elseif preg_match(sizePattern, columnType, matches) {
if fetch matchOne, matches[1] {
let definition["size"] = (int) matchOne;
}
Expand Down
Loading

0 comments on commit c0af848

Please sign in to comment.