query-builder

ORMLite - Parenthesis in join where clauses

百般思念 提交于 2019-12-07 18:52:15
问题 I would like to join three tables using QueryBuilder.join and QueryBuilder.joinor but I want parenthesis in the where clause something like this: WHERE first_table_where AND (second_table_where OR third_table_where) but it seems that is not possible. Perhaps I am missing something. Any help would be appreciated. 回答1: I guess that is a part of the doc you have been looking for... If you want to do complex queries linearly, you can even use Reverse Polish Notation (of all things). There is a

How to create an AND button that adds a AND statement to a query?

守給你的承諾、 提交于 2019-12-07 18:42:06
问题 I'm making some type of query builder and I want to implement a button to add a AND statement to my query. I made a version where I have 1 AND statement implemented but it's a bit devious and I want the user to have the ability to do more than one AND statement. This the code I have at the moment. UPDATED This is my .php file: <?php include "connect.php"; //Ophalen van de waarden uit de tabel(len) en veld(en) $table = $_GET['tableSelected']; $field = $_GET['fieldSelected']; $attribute = $_GET

Doctrine 2.5 Unexpected association fetch behavior [Symfony 3]

。_饼干妹妹 提交于 2019-12-07 16:29:12
问题 I have 3 entities associated this way: Don't worry, I've set associations using annotations, but I thought the following mix would be lighter/cleaner to expose my issue Post @ORM\ManyToOne(targetEntity="User", fetch="EAGER") - author User @ORM\OneToOne(targetEntity="Vip", mappedBy="user", fetch="EAGER") - vip Vip # Notice that the primary key of vip is a foreign key on User primary @ORM\id @ORM\OneToOne(targetEntity="User", inversedBy="peliqan", fetch="EAGER") @ORM\JoinColumn(name="user_id",

Entity field - queryBuilder->select()

六月ゝ 毕业季﹏ 提交于 2019-12-07 15:52:27
I have a problem with entity field, query builder and OneToOne relationship. When I created entity field with query_builder in form class and when I set select ('u.id, u.username') I get exception: >need array or object, integer given. When I set select('u') is fine but I get columns with OneToOne relationship and Doctrine generates x additional SELECT queries. What do I have to do? EDIT: MORE DETAILS For example I have two entity with oneToOne relation, User and Contact: <?php namespace Nuvola\UserBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * User * * @ORM\Table() * @ORM\Entity */

Laravel 5, Derived table in join clause?

本秂侑毒 提交于 2019-12-07 05:30:44
问题 I have this query: SELECT * FROM blog LEFT JOIN ( SELECT blog_id, AVG(value) as blog_rating FROM blog_ratings GROUP BY (blog_id) ) T ON T.blog_id = blog.id; I do not know how to write this with Eloquent. For Example: Blog::select("*")->leftJoin( /* Here goes derived table */ )->get() How do I accomplish this? 回答1: I'd personally just use the fluent query builder, try this out and see how it works out: DB::table('blog') ->select('*') ->leftJoin(DB::raw('(SELECT blog_id, AVG(value) as blog

Creating a mongodb query in Java with $or and $in

人走茶凉 提交于 2019-12-07 04:56:41
问题 I am trying to write a java code using mongodb api to create this mongodb query: { "$or": [{"prd" : {"$in" : ["1234", "0987"]}} , {"rsin" : "3228742"}]} Here's the code I am working with so far: QueryBuilder builder = new QueryBuilder(); if (builder == null) { builder = QueryBuilder.start(); } if (mongoKey.equals("prd")){ ArrayList<String> vals = new ArrayList<String>(); for (int i=0; i < prdList; i++){ vals.add(prdList.get(i)); } DBObject obj = new BasicDBObject (mongoKey, new BasicDBObject(

Symfony2 subquery within Doctrine entity manager

自闭症网瘾萝莉.ら 提交于 2019-12-07 03:22:36
问题 I need to perform this query: SELECT * FROM (SELECT * FROM product WHERE car = 'large' ORDER BY onSale DESC) AS product_ordered GROUP BY type In Symfony2 using the entity manager. My basic query builder would be : $query = $em->getRepository('AutomotiveBundle:Car') ->createQueryBuilder('p') ->where('pr.car = ?1') ->andWhere('pr.status = 1') ->orderBy('pr.onSale', 'DESC') ->setParameter(1, $product->getName()) ->groupBy('p.type') ->getQuery(); But I cannot work out how to add in a subquery to

Runtime SQL Query Builder

浪子不回头ぞ 提交于 2019-12-06 13:16:28
My question is similar to Is there any good dynamic SQL builder library in Java? However one important point taken from above thread: Querydsl and jOOQ seem to be the most popular and mature choices however there's one thing to be aware of: Both rely on the concept of code generation , where meta classes are generated for database tables and fields. This facilitates a nice, clean DSL but it faces a problem when trying to create queries for databases that are only known at runtime . Is there any way to create the queries at runtime besides just using plain JDBC + String concatenation? What I'm

How to injecting custom columns in Laravel query builder

风流意气都作罢 提交于 2019-12-06 11:02:52
I got a query with many joins, wheres, ect. And what I need to do is insert some maths into each result set as it will be feeding either a csv export or be displayed on page. Can later on even be sent back as API, so what I really want to do is prepare the data once, and then use it where ever. $result = DB::table('a') ->join('b') ->where('c') ->orderBy('d') ->select('e'); if ($paginate) { $query->paginate(); } else { $query->get(); } So the question is, can I somehow iterate through my results and do some maths as I get them? Like maybe a callback on each result? For example get difference

Laravel - named subquery using Query Builder

ε祈祈猫儿з 提交于 2019-12-06 09:18:28
In MySQL subqueries documentation there's an exmaple of subquery: SELECT ... FROM (subquery) [AS] name ... Here's the raw query which I want to transform: select SUBQUERY_NAME.* from (select id, name from items) AS SUBQUERY_NAME Is there any way to do this in Laravel Query Builder without using DB::raw() ? Unfortunatelly no. The Query Builder has its limitations and more complex queries are outside its scope, that's why DB::raw() is there. But, if you want to make it a little more elegant and generate the subquery using the Query Builder, you could do something like this this: $subquery = DB: