Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object of class Phalcon\Db\RawValue could not be converted to float #12766

Closed
mzf opened this issue Apr 4, 2017 · 17 comments
Closed

Object of class Phalcon\Db\RawValue could not be converted to float #12766

mzf opened this issue Apr 4, 2017 · 17 comments

Comments

@mzf
Copy link

mzf commented Apr 4, 2017

Expected and Actual Behavior

Describe what you are trying to achieve and what goes wrong.

Provide output if related. Provide coredump if any. Use https://github.com/phalcon/cphalcon/wiki/Generating-a-backtrace as reference

<?php
namespace Tasks;

use PhalconExt\Cli\Task;

class LogsTasks extends \Phalcon\Mvc\Model
{

    /**
     *
     * @var integer
     * @Primary
     * @Identity
     * @Column(type="integer", length=10, nullable=false)
     */
    public $id;

    /**
     *
     * @var double
     * @Column(type="double", length=9, nullable=true)
     */
    public $exec_time;

    /**
     *
     * @var integer
     * @Column(type="integer", length=10, nullable=false)
     */
    public $pid;

}

class IssueTask extends Task
{

    /**
     * @help("Воспроизведение ошибки")
     * @paramsFormat("<y>cli.php {task} {action}</y>")
     * @shortcut("12766")
     * @param type $param
     */
    public function issue12766Action($parameters = null)
    {
        $model = new LogsTasks;
        $model->pid = 1212;
        $model->save();

        $model->exec_time = 0.1212;

        $saved = $model->update();
    }
}

DB Scheme

CREATE TABLE `logs_tasks` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,  
  `exec_time` decimal(9,3) DEFAULT NULL,
  `pid` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `pid` (`pid`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

When update model get error

Notice: Object of class Phalcon\Db\RawValue could not be converted to float in Z:\OpenServer\server\trunk\app\cli\tasks\IssueTask.php on line 56

Details

  • Phalcon version: 3.1.1
  • PHP Version: PHP 7.0.15 (cli) (built: Jan 17 2017 13:44:27) ( NTS )
  • Operating System: Win 7
  • Database: MariaDB-5.5-x64
@sergeyklay
Copy link
Contributor

@Jurigag Could you please take a look

@Jurigag
Copy link
Contributor

Jurigag commented Apr 4, 2017

Yea, can you provide your table schema?

@mzf
Copy link
Author

mzf commented Apr 4, 2017

@Jurigag added in start post

@409H
Copy link

409H commented Apr 4, 2017

What happens if you do $model->exec_time = floatval(0.1212);

@mzf
Copy link
Author

mzf commented Apr 4, 2017

@409H same error on $this->update() line

@Jurigag
Copy link
Contributor

Jurigag commented Apr 4, 2017

Can't reproduce.

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$di = new FactoryDefault();
$di->set(
    'db',
    function () {
        $adapter = new \Phalcon\Db\Adapter\Pdo\Mysql(
            [
                'host'     => 'localhost',
                'username' => 'root',
                'password' => '',
                'dbname'   => 'phalcon_test',
                'options'  => [
                    PDO::ATTR_EMULATE_PREPARES   => false,
                    PDO::ATTR_STRINGIFY_FETCHES  => false,
                    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
                ],
                'charset'  => 'utf8',
            ]
        );

        return $adapter;
    }
);
$di->set('modelsMetadata', function (){
   $metadata = new Model\MetaData\Apc();
   $metadata->setStrategy(new Model\MetaData\Strategy\Annotations());

   return $metadata;
});

require "LogsTasks.php";

$model = new LogsTasks;
$model->pid = 1212;
$model->save();

$model->exec_time = 0.1212;

$saved = $model->update();

var_dump($saved); // true

Checked on php 7.1.1 but i doubt that on 7.0 there will be difference

@mzf
Copy link
Author

mzf commented Apr 4, 2017

Screenshot
What am I doing wrong?

@mzf
Copy link
Author

mzf commented Apr 4, 2017

I test this code on Phalcon 3.0.4 - work fine.
On 3.1.0 same error

@Jurigag
Copy link
Contributor

Jurigag commented Apr 4, 2017

I don't know, you sure you posted full code of your model? Just with this code you posted i don't have error.

@mzf
Copy link
Author

mzf commented Apr 4, 2017

@Jurigag i ran you code and get error

Fatal error: Uncaught Error: Class 'FactoryDefault' not found

What version you use?

@Jurigag
Copy link
Contributor

Jurigag commented Apr 4, 2017

Oh i forgot use statements:

use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Model;

@mzf
Copy link
Author

mzf commented Apr 4, 2017

Your example work fine on Phalcon 3.1.1. Thanks!
I'll figure out what I've done

@Jurigag
Copy link
Contributor

Jurigag commented Apr 4, 2017

Maybe you need to clear metadata? I don't know really.

@mzf
Copy link
Author

mzf commented Apr 4, 2017

Try this example please.

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Model;

class ModelDynamicUpdate extends \Phalcon\Mvc\User\Plugin
{

    /**
     * @var boolean
     */
    protected $dynamicUpdate;

    /**
     * @param boolean $dynamicUpdate
     */
    public function __construct($dynamicUpdate = true)
    {
        $this->dynamicUpdate = $dynamicUpdate;
    }

    /**
     * @param \Phalcon\Events\Event               $event
     * @param \Phalcon\Mvc\Model\ManagerInterface $modelsManager
     * @param \Phalcon\Mvc\ModelInterface         $model
     */
    public function afterInitialize(\Phalcon\Events\Event $event, \Phalcon\Mvc\Model\ManagerInterface $modelsManager, \Phalcon\Mvc\ModelInterface $model)
    {
        $modelsManager->useDynamicUpdate($model, $this->dynamicUpdate);
    }
}

$di = new FactoryDefault();
$di->set(
    'db', function () {
    $adapter = new \Phalcon\Db\Adapter\Pdo\Mysql(
        [
        'host' => 'localhost',
        'username' => 'root',
        'password' => '',
        'dbname' => 'phalcon_test',
        'options' => [
            PDO::ATTR_EMULATE_PREPARES => false,
            PDO::ATTR_STRINGIFY_FETCHES => false,
            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
        ],
        'charset' => 'utf8',
        ]
    );

    return $adapter;
}
);

$di->set('modelsManager', function () {

    $eventsManager = new \Phalcon\Events\Manager;
    $modelsManager = new Model\Manager;
    $eventsManager->attach("modelsManager", new ModelDynamicUpdate(true));
    $modelsManager->setEventsManager($eventsManager);

    return $modelsManager;
});



require "LogsTasks.php";

$model = new LogsTasks;
$model->pid = 1212;
$model->save();

$model->exec_time = 0.1212;

$saved = $model->update();

var_dump($saved); // true

?>

@Jurigag
Copy link
Contributor

Jurigag commented Apr 4, 2017

Yea, now i see, let me fix it.

Jurigag added a commit to Jurigag/cphalcon that referenced this issue Apr 4, 2017
Jurigag added a commit to Jurigag/cphalcon that referenced this issue Apr 4, 2017
Jurigag added a commit to Jurigag/cphalcon that referenced this issue Apr 4, 2017
Jurigag added a commit to Jurigag/cphalcon that referenced this issue Apr 4, 2017
@Jurigag Jurigag mentioned this issue Apr 4, 2017
3 tasks
Jurigag added a commit to Jurigag/cphalcon that referenced this issue Apr 4, 2017
Jurigag added a commit to Jurigag/cphalcon that referenced this issue Apr 4, 2017
@Jurigag
Copy link
Contributor

Jurigag commented Apr 4, 2017

Created PR.

sergeyklay added a commit that referenced this issue Apr 4, 2017
@sergeyklay
Copy link
Contributor

Fixed in the 3.1.x branch.

sergeyklay pushed a commit that referenced this issue Apr 5, 2017
sergeyklay pushed a commit that referenced this issue Apr 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants