Jump to content

select where bug 4.2.0


BomAle

Recommended Posts

<?php
require_once './init.php';

$where = array (
	'pid IN(57,58)',
	'poll_closed=1'
);
$select = \IPS\Db::i()->select( 'COUNT(*) as cnt', 'core_polls', $where );
var_dump($select->query);exit;

it print:

D:\Programmi\Ampps\www\ips4\test.php:10:string 'SELECT COUNT(*) as cnt FROM `core_polls` WHERE pid IN(57,58)' (length=60)

where is poll_closed go?

Can anyone test this for 4.2.2 or lastest? @bfarber

 

results.png

Link to comment
Share on other sites

Your where is structured incorrectly, the second index of the array is used for binds (prepared statements), not another where clause.

See the comments on \IPS\Db::compileWhereClause():

	/**
	 * Compile WHERE clause
	 *
	 * @code
	 	// Single clause
	 	"foo IS NOT NULL"
	 	// Single clause with bound values (always bind values to ensure they are properly escaped)
	 	array( 'foo=?', 'fooValue' )
	 	array( 'foo=? OR bar=?', 'fooValue', 'barValue' )
	 	// Multiple clauses (will be joined with AND) with bound values
	 	array( array( 'foo=?, 'fooValue' ), array( 'bar=?', 'barValue' ) )

 

Link to comment
Share on other sites

Thanks for all, I have missed compileWhereClause instructions, therefore I have changed:

[[\IPS\Db::i()->in(
			\IPS\advpolls\Poll::$databasePrefix . \IPS\advpolls\Poll::$databaseColumnMap['container'],
			iterator_to_array(
				\IPS\Db::i()->select(
					\IPS\advpolls\Category::$databasePrefix . \IPS\advpolls\Category::$databaseColumnId,
					\IPS\advpolls\Category::$databaseTable
				)
			)
		)]]

into \IPS\advpolls\Table constructor :thumbsup: (temporary fix, avoiding uncategorized polls)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...