Skip to content

Commit

Permalink
Merge pull request #1719 from lantian/1.3.0
Browse files Browse the repository at this point in the history
PDO/Adapter updates from 1.2.5
  • Loading branch information
Phalcon committed Dec 20, 2013
2 parents d590fec + 1a6d975 commit dc95b68
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 182 deletions.
71 changes: 46 additions & 25 deletions ext/db/adapter/pdo/mysql.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
+------------------------------------------------------------------------+
| Phalcon Framework |
Expand Down Expand Up @@ -196,25 +195,39 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){
PHALCON_OBS_NVAR(column_type);
phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY);

/**
* Check the column type to get the correct Phalcon type
*/
while (1) {
/**

/**
* Point are varchars
*/
if (phalcon_memnstr_str(column_type, SL("point"))) {
phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE);
break;
}
/**

/**
* Enum are treated as char
*/
if (phalcon_memnstr_str(column_type, SL("enum"))) {
phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE);
break;
}

/**

/**
* Tinyint(1) is boolean
*/
if (phalcon_memnstr_str(column_type, SL("tinyint(1)"))) {
phalcon_array_update_string_long(&definition, SL("type"), 8, PH_SEPARATE);
phalcon_array_update_string_long(&definition, SL("bindType"), 5, PH_SEPARATE);
PHALCON_INIT_NVAR(column_type);
ZVAL_STRING(column_type, "boolean", 1); // Change column type to skip size check.
break;
}

/**
* Smallint/Bigint/Integers/Int are int
*/
if (phalcon_memnstr_str(column_type, SL("int"))) {
Expand All @@ -223,24 +236,24 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){
phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_SEPARATE);
break;
}
/**

/**
* Varchar are varchars
*/
if (phalcon_memnstr_str(column_type, SL("varchar"))) {
phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE);
break;
}
/**

/**
* Special type for datetime
*/
if (phalcon_memnstr_str(column_type, SL("datetime"))) {
phalcon_array_update_string_long(&definition, SL("type"), 4, PH_SEPARATE);
break;
}
/**

/**
* Decimals are floats
*/
if (phalcon_memnstr_str(column_type, SL("decimal"))) {
Expand All @@ -249,32 +262,40 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){
phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE);
break;
}
/**

/**
* Chars are chars
*/
if (phalcon_memnstr_str(column_type, SL("char"))) {
phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE);
break;
}
/**

/**
* Date/Datetime are varchars
*/
if (phalcon_memnstr_str(column_type, SL("date"))) {
phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE);
break;
}

/**

/**
* Timestamp as date
*/
if (phalcon_memnstr_str(column_type, SL("timestamp"))) {
phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE);
break;
}

/**
* Text are varchars
*/
if (phalcon_memnstr_str(column_type, SL("text"))) {
phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE);
break;
}
/**

/**
* Float/Smallfloats/Decimals are float
*/
if (phalcon_memnstr_str(column_type, SL("float"))) {
Expand All @@ -283,8 +304,8 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){
phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE);
break;
}
/**

/**
* Double are floats
*/
if (phalcon_memnstr_str(column_type, SL("double"))) {
Expand All @@ -293,8 +314,8 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){
phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE);
break;
}
/**

/**
* By default is string
*/
phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE);
Expand Down
150 changes: 102 additions & 48 deletions ext/db/adapter/pdo/oracle.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,60 +214,114 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, describeColumns){
/**
* Check the column type to get the correct Phalcon type
*/
if (phalcon_memnstr_str(column_type, SL("NUMBER"))) {
phalcon_array_update_string_long(&definition, SL("type"), 3, PH_SEPARATE);
phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE);
phalcon_array_update_string(&definition, SL("size"), &column_precision, PH_COPY | PH_SEPARATE);
phalcon_array_update_string(&definition, SL("scale"), &column_scale, PH_COPY | PH_SEPARATE);
phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE);
} else {
while (1) {
/**
* Integer
*/
if (phalcon_memnstr_str(column_type, SL("NUMBER"))) {
phalcon_array_update_string_long(&definition, SL("type"), 3, PH_SEPARATE);
phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE);
phalcon_array_update_string(&definition, SL("size"), &column_precision, PH_COPY | PH_SEPARATE);
phalcon_array_update_string(&definition, SL("scale"), &column_scale, PH_COPY | PH_SEPARATE);
phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE);
break;
}

/**
* Tinyint(1) is boolean
*/
if (phalcon_memnstr_str(column_type, SL("TINYINT(1)"))) {
phalcon_array_update_string_long(&definition, SL("type"), 8, PH_SEPARATE);
phalcon_array_update_string_long(&definition, SL("bindType"), 5, PH_SEPARATE);
break;
}

/**
* Smallint/Bigint/Integers/Int are int
*/
if (phalcon_memnstr_str(column_type, SL("INTEGER"))) {
phalcon_array_update_string_long(&definition, SL("type"), 0, PH_SEPARATE);
phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE);
phalcon_array_update_string(&definition, SL("size"), &column_precision, PH_COPY | PH_SEPARATE);
phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_SEPARATE);
} else {
if (phalcon_memnstr_str(column_type, SL("VARCHAR2"))) {
phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE);
phalcon_array_update_string(&definition, SL("size"), &column_size, PH_COPY | PH_SEPARATE);
} else {
if (phalcon_memnstr_str(column_type, SL("FLOAT"))) {
phalcon_array_update_string_long(&definition, SL("type"), 7, PH_SEPARATE);
phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE);
phalcon_array_update_string(&definition, SL("size"), &column_size, PH_COPY | PH_SEPARATE);
phalcon_array_update_string(&definition, SL("scale"), &column_scale, PH_COPY | PH_SEPARATE);
phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE);
} else {
if (phalcon_memnstr_str(column_type, SL("TIMESTAMP"))) {
phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE);
} else {
if (phalcon_memnstr_str(column_type, SL("RAW"))) {
phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE);
} else {
if (phalcon_memnstr_str(column_type, SL("BLOB"))) {
phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE);
} else {
if (phalcon_memnstr_str(column_type, SL("CLOB"))) {
phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE);
} else {
if (phalcon_memnstr_str(column_type, SL("VARCHAR2"))) {
phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE);
phalcon_array_update_string(&definition, SL("size"), &column_size, PH_COPY | PH_SEPARATE);
} else {
if (phalcon_memnstr_str(column_type, SL("CHAR"))) {
phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE);
phalcon_array_update_string(&definition, SL("size"), &column_size, PH_COPY | PH_SEPARATE);
} else {
phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE);
}
}
}
}
}
}
}
}
break;
}

/**
* Float/Smallfloats/Decimals are float
*/
if (phalcon_memnstr_str(column_type, SL("FLOAT"))) {
phalcon_array_update_string_long(&definition, SL("type"), 7, PH_SEPARATE);
phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE);
phalcon_array_update_string(&definition, SL("size"), &column_size, PH_COPY | PH_SEPARATE);
phalcon_array_update_string(&definition, SL("scale"), &column_scale, PH_COPY | PH_SEPARATE);
phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE);
break;
}

/**
* Date
*/
if (phalcon_memnstr_str(column_type, SL("TIMESTAMP"))) {
phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE);
break;
}

/**
* Text
*/
if (phalcon_memnstr_str(column_type, SL("RAW"))) {
phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE);
break;
}

/**
* Text
*/
if (phalcon_memnstr_str(column_type, SL("BLOB"))) {
phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE);
break;
}

/**
* Text
*/
if (phalcon_memnstr_str(column_type, SL("CLOB"))) {
phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE);
break;
}

/**
* Chars2 are string
*/
if (phalcon_memnstr_str(column_type, SL("VARCHAR2"))) {
phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE);
phalcon_array_update_string(&definition, SL("size"), &column_size, PH_COPY | PH_SEPARATE);
break;
}

/**
* Chars are chars
*/
if (phalcon_memnstr_str(column_type, SL("CHAR"))) {
phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE);
phalcon_array_update_string(&definition, SL("size"), &column_size, PH_COPY | PH_SEPARATE);
break;
}

/**
* Text are varchars
*/
if (phalcon_memnstr_str(column_type, SL("text"))) {
phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE);
break;
}

/**
* By default is string
*/
phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE);
break;
}

if (Z_TYPE_P(old_column) == IS_NULL) {
Expand Down
Loading

0 comments on commit dc95b68

Please sign in to comment.