I'm trying to build a query with Doctrine 2
$qb = $em->createQueryBuilder()
->select('*')
->from('Countries','c')
//getDQL
->getQuery();
echo "<pre>";
echo ($qb->execute());
echo "</pre>";
die;
for some reason I'm getting an error:
Fatal error: Uncaught exception
'Doctrine\ORM\Query\QueryException'
with message '[Syntax Error] line 0,
col 7: Error: Expected
IdentificationVariable |
StateFieldPathExpression |
AggregateExpression | "(" Subselect
")" | ScalarExpression, got '*'' in
/home/dodo/doctrine-orm/Doctrine/ORM/Query/QueryException.php
on line 42
select('c.*') didn't work for me, select('c') was enough
There is no such a thing as "global wildcard" - you should use c.*.
Related
I'm setting up query builder in CakePHP 3.7 to get value in single row, inside UsersTable. I want to get row value "where Name = 'Budi'"
I'm tried to solved it by browsing in https://book.cakephp.org/3.0/en/orm/query-builder.html but doesn't work
<?php
//UsersController.php
namespace App\Controller;
use App\Controller\AppController;
use App\Model\Table\UsersTable;
use Cake\Event\event;
use Cake\I18n\Time;
use Cake\ORM\TableRegistry;
class UsersController extends AppController
{
public function index
{
$query = $users->find()
->select(['ID', 'Nama'])
->where(['Nama =' => 'Budi']);
foreach ($query as $users) {
debug($users->Nama);
}
$this->set(compact('users'));
}
//code from cake bake all
}
?>
the messages error shown here
Notice (8): Undefined variable: users [APP/Controller\UsersController.php, line 20]
Notice (1024): Undefined property: ErrorController::$Auth in C:\xampp\htdocs\klinikucing\src\Controller\AppController.php on line 57 [CORE\src\Controller\Controller.php, line 388]
Warning (512): Unable to emit headers. Headers sent in file=C:\xampp\htdocs\klinikucing\vendor\cakephp\cakephp\src\Error\Debugger.php line=853 [CORE\src\Http\ResponseEmitter.php, line 48]
Warning (2): Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\klinikucing\vendor\cakephp\cakephp\src\Error\Debugger.php:853) [CORE\src\Http\ResponseEmitter.php, line 148]
Warning (2): Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\klinikucing\vendor\cakephp\cakephp\src\Error\Debugger.php:853) [CORE\src\Http\ResponseEmitter.php, line 181]
Warning (2): Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\klinikucing\vendor\cakephp\cakephp\src\Error\Debugger.php:853) [CORE\src\Http\ResponseEmitter.php, line 181]
An Internal Server Error Occurred
I expect the output is
-------------------------------------------------
| Nama | Role | Dibuat | Diubah |
-------------------------------------------------
| Budi | Visitor | 10/04/2019 | 12/04/2019 |
-------------------------------------------------
You need to reference the model of the controller as well
Use
$query = $this->Users->find()
->select(['ID', 'Nama'])
->where(['Nama =' => 'Budi']);
on first line of index function, i think you must define $users variable
$users = TableRegistry::get('Users');
I'm trying to learn about objects detection with Deep Learning, and I'm actually trying to run the sample code "ssd_object_detection.cpp". In this code it's necessary to input the following parameters:
const char* params
= "{ help | false | print usage }"
"{ proto | | model configuration }"
"{ model | | model weights }"
"{ camera_device | 0 | camera device number}"
"{ video | | video or image for detection}"
"{ min_confidence | 0.5 | min confidence }";
Following the instructions of this code, I downloaded some pretrained models from this web: https://github.com/weiliu89/caffe/tree/ssd#models\n
So, I obtained a folder with the next archives:
deploy.prototxt
finetune_ssd_pascal.py
solver.prototxt
test.prototxt
train.prototxt
VGG_VOC0712Plus_SSD_300x300_ft_iter_160000.caffemodel
Then, I copied all this data to my project folder, and tried this code:
const char* params
= "{ help | false | print usage }"
"{ proto |test.prototxt| model configuration }"
"{ model |VGG_VOC0712Plus_SSD_300x300_ft_iter_160000.caffemodel| model weights }"
"{ camera_device | 0 | camera device number}"
"{ video |MyRoute...| video or image for detection}"
"{ min_confidence | 0.5 | min confidence }";
But at output I get the following error:
[libprotobuf ERROR
C:\build\master_winpack-build-win64-vc14\opencv\3rdparty\protobuf\src\google\protobuf\text_format.cc:298] Error parsing text-format opencv_caffe.NetParameter: 13:18: Message
type "opencv_caffe.TransformationParameter" has no field named
"resize_param". OpenCV Error: Unspecified error (FAILED:
ReadProtoFromTextFile(param_file, param).
Failed to parse NetParameter
file: test.prototxt) in cv::dnn::ReadNetParamsFromTextFileOrDie, file
C:\build\master_winpack-build-win64-vc14\opencv\modules\dnn\src\caffe\caffe_io.cpp,
line 1145
I used all the .prototxt archives, and tried other possible solutions, but I still cant run the example code.
Can someone explain me what parameters should I write in this code or what am i doing wrong?
Sorry about my bad English and thanks in advance.
I am getting a lot of Global symbol <symbol> requires explicit package name errors in my code, immediately after the line of code where I have used smart matching. All of those global variables are defined and code worked before using smart matching.
if (ref($aActivityErrorStrings) eq "ARRAY" && $sChompedOutput ~~ #$aActivityErrorStrings)
The first line of error gives me a hint that there is something wrong with my usage of smart matching. Error line is
Status message: Failed: syntax error at common.pm line 320, near "$sChompedOutput ~" Global symbol "$rOutput" requires explicit package name
my Perl version is 5.12
Can someone please tell me what is wrong with smart matching?
My mistake guys. User of this code was running it on a device which had Perl version 5.8.
Thank you for all the feedbacks. Much appriciated.
Error here:
if (ref($aActivityErrorStrings) eq "ARRAY"
&& $sChompedOutput ~~ #$aActivityErrorStrings))
^
|
You've got an extra closing parenthesis. Here's proof that your code can work:
use strict;
use warnings;
use 5.020;
my $aActivityErrorStrings = [
"Error1",
"Error2",
];
my $sChompedOutput = "Error1";
if (ref($aActivityErrorStrings) eq "ARRAY"
&& $sChompedOutput ~~ #$aActivityErrorStrings) {
say 'yes'
}
say "#$aActivityErrorStrings";
--output:--
Smartmatch is experimental at 1.pl line 14.
yes
Error1 Error2
The error
Global symbol "$sChompedOutput" requires explicit package name at ...
pops up, if you have $sChompedOutput undefined.
The following code produces this error:
my $aActivityErrorStrings = ["mumu", "Bubu", "hello"];
#my $sChompedOutput = "hello";
if (ref($aActivityErrorStrings) eq "ARRAY" && $sChompedOutput ~~ #$aActivityErrorStrings) {
print "have hello";
}
if you remove the comment before #my $sChomped... the error goes away.
I am trying to wrap a text fixture around some PowerShell code that extends an object with a property. I get an error that appears to be caused by Pester. I have a contrived example below that displays what I am trying to do.
Has anyone succeeded in writing tests on functions that use properties with Pester?
The error I get:
Describing Get-PropertyOfItem
Select-Object : Property cannot be processed because property "should" already exists.
At C:\Repos\ClinicientOps\clinicientops\General\Functions\Get-PropertyOfItem.ps1:4 char:11
+ $files | Select-Object *, #{Name = "TestProperty"; Expression = { $dir.Length}} ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Windows:PSObject) [Select-Object], PSArgumentException
+ FullyQualifiedErrorId : AlreadyExistingUserSpecifiedPropertyNoExpand,Microsoft.PowerShell.Commands.SelectObjectCommand
My function:
function Get-PropertyOfItem {
$dir = "C:\"
$files = Get-ChildItem $dir
$files | Select-Object *, #{Name = "TestProperty"; Expression = { $dir.Length}} -Last 1
}
My test code:
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"
Describe "Get-PropertyOfItem" {
It "does something useful" {
$prop = Get-PropertyOfItem
$prop.TestProperty.should.be(3)
}
}
It appears to be a limitation they are investigating in version 2.
Pester version 2.0.1 has been silently released. You'll have to rewrite your expectation to be
$prop.TestProperty | Should Be 3
It also means that all your other tests will need to migrate to this pipeline form Expectation syntax.
Does anyone know if there is a way to force CakePHP TestSuite to view the Expected and Result values of an assertion when it fails? Typical PHPUnit tests are showing it by default in the output but not Cake's TestSuite (which uses PHPUnit). A side from that, when i debug a test case in NetBeans i get some kind of Socket Exception whenever i try to set a watch for a variable, and it only happens in CakePHP test cases, it works fine in evry other source file. Is there a solution for this aswell?
check out
http://www.dereuromark.de/2011/12/04/unit-testing-tips-for-2-0-and-phpunit/
basically, you can extend the TestCase class and make your own additional methods like
public function details($is, $expected) {
echo 'is:' . $is; echo '<br />';
echo 'expected: ' . $expected; ob_flush();
}
and call it internally or sth on fail.
or you just debug() everywhere.
Ok I somehow worked it out tho the solution will be wiped when u update the Cake Library files. You need to edit the file lib\Cake\TestSuite\Reporter\CakeHtmlReporter and change the method:
public function paintFail($message, $test)
{
$trace = $this->_getStackTrace($message);
$testName = get_class($test) . '(' . $test->getName() . ')';
echo "<li class='fail'>\n";
echo "<span>Failed</span>";
echo "<div class='msg'><pre>" . $this->_htmlEntities($message) . "</pre></div>\n";
echo "<div class='msg'>" . __d('cake_dev', 'Test case: %s', $testName) . "</div>\n";
echo "<div class='msg'>" . __d('cake_dev', 'Stack trace:') . '<br />' . $trace . "</div>\n";
echo "</li>\n";
}
to:
public function paintFail($message, $test) {
$trace = $this->_getStackTrace($message);
$testName = get_class($test) . '(' . $test->getName() . ')';
echo "<li class='fail'>\n";
echo "<span>Failed</span>";
echo "<div class='msg'><pre>" . $this->_htmlEntities($message->getComparisonFailure()->toString()) . "</pre></div>\n";
echo "<div class='msg'>" . __d('cake_dev', 'Test case: %s', $testName) . "</div>\n";
echo "<div class='msg'>" . __d('cake_dev', 'Stack trace:') . '<br />' . $trace . "</div>\n";
echo "</li>\n";
}
And this will output you something like this when the assertion fails:
Failed asserting that two arrays are equal.--- Expected
+++ Actual
## ##
Array (
- 0 => 'Crypto3DS'
- 1 => 'Zlib'
+ 1 => 'Crypto3DS'
+ 2 => 'Zlib'
)
Faster testing in Cake Yeppie :D