Jump to content

select where bug 4.2.0


BomAle

Recommended Posts

Posted
<?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

Posted

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' ) )

 

Posted

I would do:

$where[] = array( \IPS\Db::i()->in( 'pid', array( '57', '58' ) ) ); 
$where[] = array( 'poll_closed=1' ); 

Returns:

Quote

C:\wamp64\www\test.php:8:string 'SELECT COUNT(*) as cnt FROM `core_polls` WHERE ( pid IN('57','58') ) AND poll_closed=1' (length=86)

 

Posted

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)

Archived

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

  • Recently Browsing   0 members

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