I am working with Yii 2.0. Here is my field which has serialize value now i want to find that if 94 exist in this field than i need all values from this row.
post_parents: a:2:{i:0;s:1:"6";i:1;s:2:"94";}
All efforts will be appriciated & thanks in advance
This is a sql problem rather than Yii. Here is sam problem: Unserialize through query at database level itself
Build query like that:
$query->andWhere('your_field_here REGEXP '.*;s:[0-9]+:"your_value_here".*');
Related
I have a use case where i am mapping two tables to the same object.
In this object i have a string called source and I want to be able to set the table name or the database name to this variable.
Any ideas on how to achieve this?
I have thought about iterating over my list and manually setting it but this has the potential to waste a fair chunk of time.
I appreciate this is somewhat of an odd request so this may be the only way but am hoping for a solution that maps the source variable when hibernate is mapping everything else.
if i had understood correctly your issue , then your solution might be the MappedSuperClass , in which you must have an abstract class , which will have the common fields of the two tables and then you will extend that to the two entities you want , which will point to two different tables.
Check this link
You could try to achieve this with Load listener or Interceptors. In the listener/interceptor you can check what the data source is and populate the source field accordingly.
In the end i ended up using a formula to map my variable to a select statement which was sufficient for what i needed.
I can't solve this problem. I have a very large code for filters using a QueryBuilder instance
$qb = new QueryBuilder();
$qb->select('item)->from->("BundleExample:Item");
$qb->andWhere("item.idProvince = {$idProvinde");
if($price)
$qb->andWhere("price betwenn..");
Ok , there is too much lines.
Now i need to add a virtual column (distance) or overwrite a current field value.
$qb->select('item, COS(..) as distance')
As i understand , i need to create a ResultSetMapping , but i have to re-do all the filtering process and this is very annoying.
Any ideas?
thanks
You don't have to use native queries nor RSM, as Doctrine is capable of returning mixed/hybrid result sets: Pure and Mixed Results.
I have plan to sync from my parse.com data to my postgreSql local database with JS API. To do that, i have to get all data that have null value for Column last_sync (it's mean that data did not syncing with local database).
Please help me how to get all data that last_sync is null?
You're not stating what language you're using, but this is a solution for Android:
query.whereDoesNotExist("last_sync");
This will constrain the query to only those records that don't have a value set in last_sync
For JavaScript:
query.doesNotExist("last_sync");
For Objective-C:
[query whereKeyDoesNotExist:#"last_sync"];
Ive got a Zend_Db_Table
Now I want to get the maximum available value of a field.
Is there a way to get the MAX(number) value or do I need to use basic SQL?
Thanks!
Use
new Zend_Db_Expr('MAX(number)')
as one of the fields in the Zend_Db_Table_Select.
So I'm extremely new to Linq in .Net 3.5 and have a question. I use to use a custom class that would handle the following results from a store procedure:
Set 1: ID Name Age
Set 2: ID Address City
Set 3: ID Product Price
With my custom class, I would have received back from the database a single DataSet with 3 DataTables inside of it with columns based on what was returned from the DB.
My question is how to I achive this with LINQ? I'm going to need to hit the database 1 time and return multiple sets with different types of data in it.
Also, how would I use LINQ to return a dynamic amount of sets depending on the parameters (could get 1 set back, could get N amount back)?
I've looked at this article, but didn't find anything explaining multiple sets (just a single set that could be dynamic or a single scalar value and a single set).
Any articles/comments will help.
Thanks
I believe this is what you're looking for
Linq to SQL Stored Procedures with Multiple Results - IMultipleResults
I'm not very familiar with LINQ myself but here is MSDN's site on LINQ Samples that might be able to help you out.
EDIT: I apologize, I somehow missed the title where you mentioned you wanted help using LINQ with Stored Procedures, my below answer does not address that at all and unfortunately I haven't had the need to use sprocs with LINQ so I'm unsure if my below answer will help.
LINQ to SQL is able hydrate multiple sets of data into a object graph while hitting the database once. However, I don't think LINQ is going to achieve what you ultimately want -- which as far as I can tell is a completely dynamic set of data that is defined outside of the query itself. Perhaps I am misunderstanding the question, maybe it would help if you provide some sample code that your existing application is using?
Here is a quick example of how I could hydrate a anonymous type with a single database call, maybe it will help:
var query = from p in db.Products
select new
{
Product = p,
NumberOfOrders = p.Orders.Count(),
LastOrderDate = p.Orders.OrderByDescending().Take(1).Select(o => o.OrderDate),
Orders = p.Orders
};