What's the difference between getScalarResult and getArrayResult in Doctrine [closed] - doctrine-orm

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
What's the difference in using: getScalarResult() and getArrayResult()
when running a query with QueryBuilder in Doctrine:
$query = $this->em->createQueryBuilder();
$query->select(self::SHORT_LIST)
->from(DataSetting::class, 'ds')
->andWhere('ds.'.$field.' LIKE :searchField')
->setParameter('searchField', $value . '%')
->setMaxResults($filters->getLength());
$query->getQuery()->getScalarResult()
and
$query->getQuery()->getArrayResult()
Since this is not well documented on Doctrine I would like to understand the conceptual difference.

Superficially both getArrayResult() and getScalarResult() will return similar or same results in your query. Essentially all they change is how the result will be hydrated:
ArrayHydrator -- produces a nested array "graph" that is often (not always) interchangeable with the corresponding object graph for read-only access.
ScalarHydrator -- Hydrator that produces flat, rectangular results of scalar data.
Their corresponding test files show what kind of output they produce, but it might still be a bit unclear.
In simple terms, the ScalarHydrator will return a list of field value mappings with only scalar values. The ArrayHydrator can return a multitude of arrays, a list of associative arrays (key value maps, similar to the ScalarHydrator), but it can also contain objects and the list can be indexed in a certain way and can be nested.
In some cases, especially with simple queries, both hydrators might return the same result. In that case ScalarHydrator likely has less overhead, but whether it actually impacts performance I can't really tell.

Related

Which linq method is most suitable for judging whether there are elements in the set? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
var list = new List<object>();
if (list.Any())
if (list.Count > 0)
if (list.FirstOrDefault() != null)
I can think of three reasons why Any is better than the other 2 options:
Any conveys the intent most cleanly
If the collection is not an ICollection<T>, which has a built-in Count property, then Count() will traverse the whole collection. Any() will at worst stop iterating if, well, any element is found.
FirstOrDefault() == null only works on collections of types where the default is actually null. It will not work on, say, a list of integers
There could also be edge cases which make the third option give wrong results. FirstOrDefault() == null could return true if there's some bizarre equality operator overload that returns true if an object is "equivalent" to null. That seems unlikely, but it could give a false positive for an "empty" collection.
If the collection is not an ICollection, then there should not be any meaningful performance difference between the three. The only other reason there would be a difference is if the collection implements ICollection<T> but has a strange override of GetEnumerator that does significantly more work even to just see if there is one item. That seems unlikely enough that I would only use Count in very specific circumstances with a significant, measurable performance benefit overall (not just compared to Any)

Clojure vs. Lisp: Why not concrete dotted pair in Clojure? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
In this discussion, a poster (mikera) says
There's no dotted pair in Clojure.
A philosophical reason for this is that Clojure avoids the use of a
concrete "pair" data structure and instead emphasises abstract
"sequences" which can have may possible concrete implementations.
Can someone elaborate or point me to some literature on what this means? Is this a more elegant or mathematically pure approach?
Here is a link to a handy list of questions that Rich has answered about his design decisions https://gist.github.com/reborg/dc8b0c96c397a56668905e2767fd697f
While this list doesn't explicitly explain why there is no concrete "pair" data structure it might give you some insight into Rich's preference for practical, general design.
I remember there was a time when there was a discussion about introducing a "tuple" which would have been like a vector that only has two elements to avoid the needless memory allocation that occurs when using a two element vector.
Introducing these things has a complexity cost and so you can assume that the cost/benefit analysis did not warrant adding it to the code base.
Check out this discussion on Clojure's Jira project about adding tuples and you'll see how any idea gets put through its paces:
https://dev.clojure.org/jira/browse/CLJ-1517

How can I create an internal database in a c++ program? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
During the run of my c++ program I have an amount of data that I will use.
I want to be able to use some of it depending on some criterion. In other words, a kind of data base with request instructions.
Is it possible to create an internal database and use it with DB request instructions?
I don't need to save the data either before or after the run.
Edit:
It won't be feasable in my case to add other C libraries, I'll have to work with what i'm provided with.
You may like to have a look at SQLite in-memory database.
Alternatively, use a container with one or more indexes, e.g. boost::multi_index.
You can use some database theory:
1. Store all the records into std::vector.
2. Use std::map to build search / index tables.
The index tables will give you quicker search times on keys without having to sort all the data. The index table will be of the form std::map<Key_Type, unsigned int>, where the unsigned int is the index into the std::vector database.
You can use a in memory structure, depending on how big this database needs to be. Is it a collection of Structs or is it a proper relational database or just tons of unstructured data?

Does it make sense to create a class to represent the stock of a store? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm new to OOP and I'm trying to create a program. Basically it's a store and it has products and clients and all that stuff. However, I'm struggling with a question.
When it comes to OOP, does it make sense to create a class to represent the stock of the products? Something like:
class Stock
{
private:
Product *_product;
int _nrOfProducts;
...
};
I'm asking because initially I had thought about it being an atribute of the product but then I started wondering things like "What if I delete a product? All of its information will be lost - including the stock, which I still need".
Thanks in advance!
A lot of tutorials will tell you otherwise, but in general objects are better at modeling abstractions in your software that capture behavior rather than modelling objects in the physical world. That's just data, whereas an object or better yet an interface is about capturing and abstracting behavior that can vary depending upon the situation.
As to the decision to cache the number of products v.s. not. The typical answer is, "It depends." Frequently you won't need to, because you'll be using a more sophisticated collection type that gives you an easy "count" operation. You might need that stored separately for some other reason though.

Declaring certain elements as const in an array c++, sudoku solver [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is it possible for me to take an existing array and make certain values (not all) constant? I'm trying to build a sudoku solver and my idea is to have the user enter values, so I would like to have those values remain constant as I change the empty spaces. Any tips or advice with the solver would also be appreciated. This is my first quarter working with c++. Thanks!
No. Const is essentially a compile-time idea. It's not something that can be toggled as a program is running.
If you need certain values to remain untouched while others are changed, then you need to put that into your data and logic. For instance, each value might have an associated boolean that indicates whether or not it can be changed. Then write your logic to respect that boolean.