Error: PostgresSQL create table default value for integer column #12267

Closed
Ridlsan opened this Issue Sep 29, 2016 · 2 comments

Projects

None yet

2 participants

@Ridlsan
Ridlsan commented Sep 29, 2016 edited

Phalcon 3.0.1

If setting default value 0 for integer column, phalcon escapes it as string and postgres complains as column "0" not exists.

Change its behavior in https://github.com/phalcon/cphalcon/blob/master/phalcon/db/dialect/postgresql.zep#L382

Just add check - if INTEGER so not escape value. Phalcon already has check for BOOLEAN

        if column->hasDefault() {
                let defaultValue = column->getDefault();
                if memstr(strtoupper(columnDefinition), "BOOLEAN") {
                    let sql .= " DEFAULT " . (defaultValue ? "true" : "false");
                } elseif memstr(strtoupper(defaultValue), "CURRENT_TIMESTAMP") {
                    let columnLine .= " DEFAULT CURRENT_TIMESTAMP";
                } else {
                    let columnLine .= " DEFAULT \"" . addcslashes(defaultValue, "\"") . "\"";
                }
        }
@sergeyklay sergeyklay added this to the 3.0.2 milestone Sep 29, 2016
@sergeyklay sergeyklay self-assigned this Sep 29, 2016
@sergeyklay
Collaborator

Refs: phalcon/phalcon-devtools#859
I'll fix it ASAP.

@sergeyklay
Collaborator
sergeyklay commented Sep 30, 2016 edited

Fixed. You have to update Phalcon from the 3.0.x branch:

git clone git@github.com:phalcon/cphalcon.git
cd cphalcon
git checkout 3.0.x

zephir fullclean
zephir build

Thank you for contributing!

@sergeyklay sergeyklay closed this Sep 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment