whats wrong with this doctrine query? - doctrine-orm

I have the following doctrine dql query, I cant see it being much different from manual but yet I get the following error:
Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException'
with message 'SELECT s FROM \SessionStorage s WHERE id= ?1 AND
expireAt > NOW()'
$dql = "SELECT s FROM SessionStorage s WHERE id= ?1 AND expireAt > NOW()";
$sessionstorage = $this->em->createQuery($dql)
->setParameter(1,$this->cookieManager->getCookie('session')->getValue())
->getResult();
I have tried seperating the createQuery from the setparameter but it fails at the creatQuery, but it gives not a single clue whats wrong with it. According to the documentation it should work, its very simple basic code and it works if I make it a normal pdo request.
What have I tried? i've tried using \SessionStorage, Entities\Sessionstorage, src\SessionStorage.
Tried removing the expireAt > NOW()
Changed the var from ? to :id
Tried without the s in SessionStorage s
i've googled but all I found with this error were a LOT of broken websites.
Since the doctrine documentation is cluttered as hell and unclear as it can be by not explaining what does what i'm at a loss what is wrong with this really really simple query.
Can someone please enlighten me what this query does wrong? I really dont understand why such a simple query gives such an error.

Use CURRENT_TIMESTAMP() or CURRENT_DATE() instead of NOW().

Related

Django Oracle OCA-24450

So I recently had an error with the default oracle db.backend of django.
I performed a raw query directly on my db and it throw me an "django.db.utils.DatabaseError: ORA-24450: Cannot pre-process OCI statement".
I knew the query itself was valid, because it ran in the old flask application as well as in table plus.
I googled and did not really find anything useful on that topic, other than the generic error description.
I will put the answer for future readers here. Hopefully it is helpful.
So you have to remove the comments. It is so easy but I found it nowhere and it was a wild guess when I was out of good ideas.
So just change your cursor.execute("SELECT * FROM your_db /*do the select*/") to cursor.execute("SELECT * FROM your_db")
I think that the true reason for this error is that your query string contained invalid characters. Since you say that removing the comment helped, the invalid characters must have been in the comment.

Query not responding to order_by

I'm trying to order_by a query but i cannot seem to accomplish it, any help would be appreciated
users = User.objects.filter(Q(groups__name=group)).distinct()
This is the starting query i have tried many ways to make this work with the order_by method. But cant seem to get it working i am trying to order the query by the first_name in descending order.
.order_by('-first_name'.desc())
Something like this?
I get an error 'str' object has no attribute 'desc'
I have tried to look this up but cant see it being produced in the context that i am using it so i cant relate to the answers
-- Edit --
i have had some progress, Names are changing places but i cant seem to match a pattern, So i am thinking that (Q(groups__name=group)) could be the cause of it but i have no idea what this actually does, Can anyone explain this to me? thanks
use
.order_by('-first_name')
instead of
.order_by('-first_name'.desc())
- stands for descending already. otherwise you are trying to call a method on a string instead of QuerySet object

OpenCart 2.2 error undefined when viewing order info

When I click the view button next to an order (whether from the dashboard or orders page) I get an "error undefined" alert as the page is loading.
I also get the same error when I try and change the order status from the same page and it yields no results.
It also produces no errors in the error log.
I can however change the order status from the edit order page but this is very inconvenient.
If anyone knows a common solution or maybe pointers as to how to start diagnosing the issue please post them here. I've been hunting for answers most of the day and have had no luck with any solutions.
ty in advance.
if you are using SSL Tyr this at upload/admin/controller/sale/order.php
After
$data['store_name'] = $order_info['store_name'];
Remove
$data['store_url'] = $this->request->server['HTTPS'] ? preg_replace("/^http:\/\//", "https://", $order_info['store_url']) : $order_info['store_url'];
Add
$data['store_url'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG;
Unfortunately OpenCart 2.2.0.0 is known to be a bit buggy.
Best thing would be to start using 2.3.0.2 (avoid 2.3.0.0 and 2.3.0.1) if possible.

Getting error in sqlmock for GoLang

I am writing test cases for a GoLang application and i am using sqlmock for mocking the SQL queries but i am getting following error while executing go test
Params: [ call to query , was not expected, next expectation is: ExpectedBegin => expecting database transaction Begin]
Any idea on this?
sqlmock expected a begin, but instead got something else. Show the function and test here for more info.
The error message means some SQL query was called which was not mocked.
I had same issue, because I used NamedExec (not NamedQuery) to perform my update, but was mocking ExpectQuery in test
So,
if you have expression (i.e. use UPDATE or INSERT), you should use ExpectExec
if you have query (i.e. use SELECT), you should use ExpectQuery
It's obvious, but I stuck with it for couple of hours

django + confusion with the ORM

I am getting a strange error despite following the documentation. I have the following model:
class UserToken(models.Model):
token = models.CharField(max_length=100)
user = models.ForeignKey(User)
Whenever I do UserToken.objects.get(token=tokenValue) (tokenValue is the value I am looking for) locally for MySQL, everything works. I get the value as expected. But when I do the same on my MySQL instance in Amazon RDS, I keep getting the following error:
ERROR Unknown exception: UserToken matching query does not exist.
Is there anything I am missing here? Why would a statement like this not work in RDS?
[EDIT]
Just to clarify, the token values do indeed exist. I checked the database just to make sure. Also I tried the following:
ut = UserToken.objects.raw("select * from user_token") (just to test..there was only one entry in the table) and i'm getting the following error: Unknown exception: 'RawQuerySet' object has no attribute 'token'. Is there a reason for this? The token field does exist.
I'm really not sure how this is different...but previously I was doing request.raw_post_data to get the json message that the user was sending me. I changed that to request.POST and request.body and somehow that fixed the issue. Just in case anybody else faces this hard-to-debug issue!