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

Already on GitHub? Sign in to your account

SQLSTATE[HY093] on "initListMyObjectAssociatedsPKs" #10

Closed
Lionel09 opened this Issue Dec 11, 2012 · 11 comments

Comments

Projects
None yet
3 participants
Contributor

Lionel09 commented Dec 11, 2012

Hi,

I just installed the behavior (with sf2.1 & propel 1.6.7 env) and encountered a problem in the "initListMyObjectAssociatedsPKs" method:

SQLSTATE[HY093]: Invalid parameter number
500 Internal Server Error - PDOException

It seems the bindValue doesn't work properly.

Thanks.

Contributor

willdurand commented Dec 11, 2012

error 500?

Contributor

Lionel09 commented Dec 11, 2012

This part of code fails:

$stmt = $con->prepare($sql); $stmt->bindValue(':id', $this->getPrimaryKey(), PDO::PARAM_INT); $stmt->execute();

If I use this method to bind values, it works:

$sql = "SELECT ... WHERE ... = ? ... AND ... = ?" // i just change ":id" by "?"

$stmt->bindValue(1, $this->getPrimaryKey(), PDO::PARAM_INT);
$stmt->bindValue(2, $this->getPrimaryKey(), PDO::PARAM_INT);

Contributor

willdurand commented Dec 11, 2012

I wonder why it's not covered by tests.. What is your failing code?

William Durand | http://www.williamdurand.fr

On Tue, Dec 11, 2012 at 5:53 PM, Lionel notifications@github.com wrote:

This part of code fails:

$stmt = $con->prepare($sql);
$stmt->bindValue(':id', $this->getPrimaryKey(), PDO::PARAM_INT);
$stmt->execute();

If I use this method to bind values, it works:

$sql = "SELECT ... WHERE ... = ? ... AND ... = ?" // i just change ":id"
by "?"

$stmt->bindValue(1, $this->getPrimaryKey(), PDO::PARAM_INT);
$stmt->bindValue(2, $this->getPrimaryKey(), PDO::PARAM_INT);


Reply to this email directly or view it on GitHubhttps://github.com/CraftyShadow/EqualNestBehavior/issues/10#issuecomment-11251672.

Contributor

Lionel09 commented Dec 11, 2012

I'm talking about the base propel generated code of my "Product" object (BaseProduct.php):

/** \* Initializes the list of Equal Nest ProductAssociateds PKs. * \* This will query the database for Equal Nest ProductAssociateds relations to this Product object. \* It will set the list to an empty array if the object is newly created. * \* @param PropelPDO $con */ protected function initListProductAssociatedsPKs(PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_READ); }
    if (null === $this->listEqualNestProductAssociatedsPKs) {
        if ($this->isNew()) {
            $this->listEqualNestProductAssociatedsPKs = array();
        } else {
            $sql = "
SELECT DISTINCT product.id
FROM product
INNER JOIN product_associated ON
product.id = product_associated.product_1
OR
product.id = product_associated.product_2
WHERE
product.id IN (
    SELECT product_associated.product_1
    FROM product_associated
    WHERE product_associated.product_2 = :id
)
OR
product.id IN (
    SELECT product_associated.product_2
    FROM product_associated
    WHERE product_associated.product_1 = :id
)";

            $stmt = $con->prepare($sql);
            $stmt->bindValue(':id', $this->getPrimaryKey(), PDO::PARAM_INT);
            $stmt->execute();

            $this->listEqualNestProductAssociatedsPKs = $stmt->fetchAll(PDO::FETCH_COLUMN);
        }
    }
}
Contributor

willdurand commented Dec 11, 2012

Ah ok. Weird because it should work..

Owner

VanTanev commented Dec 11, 2012

It really should work, and is covered by unit tests - this is basically the main part of the behavior.

What is your exact error, and php version?

Contributor

Lionel09 commented Dec 11, 2012

I'm using the php version delivered with ubuntu ("PHP 5.3.10-1ubuntu3.4")

SF2 Stack Trace:

Stack Trace
in /home/user/www/My Project v1.0/vendor/propel/propel1/runtime/lib/connection/DebugPDOStatement.php at line 90  -+
        public function execute($input_parameters = null)
        {
            $debug    = $this->pdo->getDebugSnapshot();
            $return    = parent::execute($input_parameters);
            $sql = $this->getExecutedQueryString();
            $this->pdo->log($sql, null, __METHOD__, $debug);
at PDOStatement ->execute (null)
in /home/user/www/My Project v1.0/vendor/propel/propel1/runtime/lib/connection/DebugPDOStatement.php at line 90  -+
at DebugPDOStatement ->execute ()
in /home/user/www/My Project v1.0/src/SlaviaVintage/Model/om/BaseProduct.php at line 4216  -+
at BaseProduct ->initListProductAssociatedsPKs (null)
in /home/user/www/My Project v1.0/src/SlaviaVintage/Model/om/BaseProduct.php at line 4279  -+
at BaseProduct ->getProductAssociateds ()
in /home/user/www/My Project v1.0/vendor/symfony/symfony/src/Symfony/Component/Form/Util/PropertyPath.php at line 410  -
Owner

VanTanev commented Dec 11, 2012

I see no reason this should be happening, but then again, I don't see a problem with moving to a positional bindValue().

@willdurand agree?

@studioecho could you open a pull request?

Contributor

willdurand commented Dec 11, 2012

Well, why not but I'd like to understand the issue before merging a fix.

William Durand | http://www.williamdurand.fr

On Tue, Dec 11, 2012 at 6:35 PM, Ivan Tanev notifications@github.comwrote:

I see no reason this should be happening, but then again, I don't see a
problem with moving to a positional bindValue().

@willdurand https://github.com/willdurand agree?

@studioecho https://github.com/StudioEcho could you open a pull request?


Reply to this email directly or view it on GitHubhttps://github.com/CraftyShadow/EqualNestBehavior/issues/10#issuecomment-11253589.

Contributor

Lionel09 commented Dec 11, 2012

OK for the pull request, but I had to train myself cause I'm beginner in github's stuff... i'll see that tomorrow! :)

Owner

VanTanev commented Dec 11, 2012

To me it sounds like an issue with the particular version of PDO, it makes
no sense otherwise.

On Tue, Dec 11, 2012 at 7:45 PM, Lionel notifications@github.com wrote:

OK for the pull request, but I had to train myself cause I'm beginner in
github's stuff... i'll see that tomorrow! :)


Reply to this email directly or view it on GitHubhttps://github.com/CraftyShadow/EqualNestBehavior/issues/10#issuecomment-11254012.

Lionel09 added a commit to Lionel09/EqualNestBehavior that referenced this issue Dec 12, 2012

@willdurand willdurand closed this Dec 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment