cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

PhalconException: Column type does not support scale parameter

Open wxd237 opened this issue 13 years ago • 17 comments

when i try to find data from a model . how can i set the model's column 's scale.

the table include int ,double type.

    CREATE TABLE `carddatalist` (
  `dataseq` int(11) NOT NULL,
  `data_type` varchar(255) DEFAULT NULL,
  `brclvl` varchar(1) DEFAULT NULL,
  `brc` varchar(8) DEFAULT NULL,
  `desc1` varchar(16) DEFAULT NULL,
  `desc2` varchar(32) DEFAULT NULL,
  `numval` int(11) DEFAULT NULL,
  `amtval` double(21,2) DEFAULT NULL,
  `datatype2` varchar(2) DEFAULT NULL,
  KEY `datalist_idx1` (`dataseq`,`brclvl`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

my model is simple:

class  Carddatalist extends \Phalcon\Mvc\Model{
      public function initialize()
    {
         $this->setConnectionService('mysql');
    }

    public function getSource(){
            return "carddatalist";
    }

}

i just Carddatalist:find(); in IndexController

PhalconException: Column type does not support scale parameter

i don's know how can i define the scale of column.

wxd237 avatar Oct 30 '13 11:10 wxd237

@dreamsxin could you please take a look?

ghost avatar Dec 11 '13 08:12 ghost

OK, i test it.

dreamsxin avatar Dec 12 '13 00:12 dreamsxin

I test in 1.3.0 it't OK, What version are you using?

INSERT INTO `phalcon_test`.`carddatalist` ( `data_type`, `brclvl`, `brc`, `desc1`, `desc2`, `numval`, `amtval`, `datatype2`) 
VALUES ('data_type', 'v', 'brn', 'desc1', 'desc2', '1', '12345678.20', 'at');

Model

<?php

class Carddatalist extends Phalcon\Mvc\Model
{

    public function getSource()
    {
        return 'carddatalist';
    }

}

test code

        $di = new Phalcon\DI();

        $di->set('modelsManager', function(){
            return new Phalcon\Mvc\Model\Manager();
        });

        $di->set('modelsMetadata', function(){
            return new Phalcon\Mvc\Model\Metadata\Memory();
        });

        $di->set('db', function(){
            return new Phalcon\Db\Adapter\Pdo\Mysql(array(
                "adapter" => "mysql",
                "host" => "localhost",
                "username" => "root",
                "password" => "",
                "name" => "phalcon_test"
            ));
        });

        $test = Carddatalist::find();

        var_dump($test->toArray());

resutl

array(2) {
  [0] =>
  array(9) {
    'dataseq' =>
    string(1) "0"
    'data_type' =>
    string(9) "data_type"
    'brclvl' =>
    string(1) "v"
    'brc' =>
    string(3) "brn"
    'desc1' =>
    string(5) "desc1"
    'desc2' =>
    string(5) "desc2"
    'numval' =>
    string(1) "1"
    'amtval' =>
    string(11) "12345678.20"
    'datatype2' =>
    string(2) "at"
  }
  [1] =>
  array(9) {
    'dataseq' =>
    string(1) "0"
    'data_type' =>
    string(9) "data_type"
    'brclvl' =>
    string(1) "v"
    'brc' =>
    string(3) "brn"
    'desc1' =>
    string(5) "desc1"
    'desc2' =>
    string(5) "desc2"
    'numval' =>
    string(1) "1"
    'amtval' =>
    string(11) "12345678.20"
    'datatype2' =>
    string(2) "at"
  }
}

dreamsxin avatar Dec 12 '13 01:12 dreamsxin

Fixed in 1.3.0, please re-open this if it's still failing

ghost avatar Dec 19 '13 17:12 ghost

This happen again in 2.0.0

overbid avatar Apr 23 '15 05:04 overbid

@overbid Yes, I'm experiencing this bug as well with 2.0.0

lothern avatar Apr 23 '15 19:04 lothern

Same here with 2.0.0. Phalcon is having an issue with one of the columns in my table being a double(11,1). My temporary workaround is to convert it to int(11) and live with it...

feloot avatar Apr 28 '15 09:04 feloot

If you're comfortable compiling the extension from the .zep, you can add

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

at line ~197 of phalcon/db/adapter/pdo/mysql.zep until my pull request gets approved.

ghost avatar Apr 28 '15 16:04 ghost

I still have this problem on 2.0.1.

Surt avatar May 25 '15 13:05 Surt

Version 2.0.2 I have this problem:

I created a table: CREATE TABLE razor.phalcon_test ( id INT NULL, name VARCHAR(45) NOT NULL, price DOUBLE(7,2) NULL, agreement TINYINT(4) NULL, PRIMARY KEY (id), UNIQUE INDEX idphalcon_test_UNIQUE (id ASC));

Model not created and shows error: "Error: Column type does not support scale parameter"

When i change "price DOUBLE(7,2) NULL," to "price DOUBLE NULL," all right.

kostjantin avatar Jun 03 '15 14:06 kostjantin

@commit aa12ad95bd4870af0a06003a22b9eab2e34a3115 It's same to me.

overbid avatar Jun 04 '15 01:06 overbid

It's fix both master or 2.0.x branch.

overbid avatar Jun 10 '15 06:06 overbid

The old error has appeared again, although the scale is present in the source texts: Phalcon version: 5.6.1 Column type does not support scale parameter file: phalcon/Db/Column.zep line: 398

basilgon avatar Mar 08 '24 08:03 basilgon

The old error has appeared again, although the scale is present in the source texts: Phalcon version: 5.6.1 Column type does not support scale parameter file: phalcon/Db/Column.zep line: 398

Can you post an example please? This code has not been touched since 2019

niden avatar Mar 10 '24 04:03 niden

Class example: image Call example: image Result: Array ( [name] => id [caption] => ID [type] => hidden [size] => [scale] => [colspan] => 0 ) Column type does not support scale parameter file: phalcon/Db/Column.zep line: 398

basilgon avatar Mar 10 '24 16:03 basilgon

They type you have there is hidden. That is not a recognized type for a column. If your type is numeric then it will go in that if block and will get the scale, otherwise it will show what you are seeing (the exception).

niden avatar Mar 11 '24 13:03 niden

Thanks for the answer

basilgon avatar Mar 12 '24 14:03 basilgon