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

integers in bounds placed as string fails (using ModelsManager) #2240

Closed
zyxep opened this issue Mar 26, 2014 · 1 comment
Closed

integers in bounds placed as string fails (using ModelsManager) #2240

zyxep opened this issue Mar 26, 2014 · 1 comment

Comments

@zyxep
Copy link

zyxep commented Mar 26, 2014

Hi.

I am trying to do a simple query on my table i have.
i am trying to set a limit and offset but i get errors.

my code i'm running

$app->get('/pictures', function($limit = 10, $offset = 0, $filename = '41232fa061a8a.jpg') use ($app)
{
    #$phql = "SELECT p.id, p.filename, p.age FROM pictures p WHERE p.status = 'active' LIMIT 10 OFFSET 0";
    $phql = "SELECT p.id, p.filename, p.age FROM pictures p WHERE p.status = 'active' AND p.filename = :filename: LIMIT :limit: OFFSET :offset:";
    $pictures = $app->modelsManager->executeQuery($phql, array(
        "limit" => $limit,
        "offset" => $offset,
        'filename' => $filename
    ));

    $data = array();
    foreach ($pictures as $picture) {
        $data[] = array(
            'id' => $picture->id,
            'filename' => $picture->filename,
            'age' => $picture->age,
        );
    }

    echo json_encode($data);
});

the error
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''10' OFFSET '0'' at line 1' in /media/sf_pattegufv3/index.php:29 Stack trace: #0 [internal function]: PDOStatement->execute() #1 [internal function]: Phalcon\Db\Adapter\Pdo->executePrepared(Object(PDOStatement), Array, NULL) #2 [internal function]: Phalcon\Db\Adapter\Pdo->query('SELECT p.id...', Array, NULL) #3 [internal function]: Phalcon\Mvc\Model\Query->_executeSelect(Array, Array, NULL) #4 [internal function]: Phalcon\Mvc\Model\Query->execute(Array, NULL) #5 /media/sf_pattegufv3/index.php(29): Phalcon\Mvc\Model\Manager->executeQuery('SELECT p.id, p....', Array) #6 [internal function]: {closure}() #7 /media/sf_pattegufv3/index.php(58): Phalcon\Mvc\Micro->handle() #8 {main} thrown in /media/sf_pattegufv3/index.php on line 29

When i change :limit: and :offset: to the numbers up in my function() does it works like a charm.

don't mind the filename it was just to test if the problem was with a string too.

@zyxep
Copy link
Author

zyxep commented Mar 26, 2014

FYI, im running 1.3.1/1.3.0 (from master)

@zyxep zyxep closed this as completed Mar 27, 2014
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

2 participants