query-builder

Codeigniter model with multiple update conditions using manual where statement

廉价感情. 提交于 2019-12-02 01:23:00
问题 I have this code in model that returns data $this->db->select('title, content, date'); $where = "name='Joe' AND status='boss'"; $this->db->where($where); $query = $this->db->get('mytable'); return $query->result(); I am using a manual where and i wanted to know whether the concept of manual where in updates and possibly in deletes is allowed. This code updates a table based on a single where condition $data = array( 'title' => $title, 'name' => $name, 'date' => $date ); $this->db->where('id',

Passing parameter to SQL select statement IN clause acts weird.

。_饼干妹妹 提交于 2019-12-02 00:42:15
I've got the following query that returns 2 records (in DataSet's query builder) SELECT EmpID, Name, id FROM Users WHERE (CAST(id AS Varchar(20)) IN ('5688','5689')) Now if I do the same query passing the parameter instead from code behind: String param = "'5688','5689'"; it returns null. WHERE (CAST(id AS Varchar(20)) IN (@param)) I tried taking off the very first and last ', but that did not make a diffrence. !!!id is a unique PK!!! Anyone's got a clue? The solution I found is quite simple, this works like a charm and there's no need for sps or other functions; SQL: SELECT whatever FROM

How to compare two fields/columns in a condition?

巧了我就是萌 提交于 2019-12-02 00:12:38
I am having a hard time trying to figure out how to get a sub-query working. Imagine I have: $schools ->select($this->Schools) ->select([ 'pupilcount' => $this->Pupils ->find() ->select([ $this->Pupils->find()->func()->count('*') ]) ->where([ 'Pupils.school_id' => 'Schools.id', ]), The problem I am experiencing (I think) is that Schools.id is always 0 and so the count is returned as 0. I can pull out the Pupils join and it shows Pupils there. I tried changing my code to add a: ->select(['SCID' => 'Schools.id']) and reference that in the sub-query but doesn't work, it will always return 0 for

Codeigniter model with multiple update conditions using manual where statement

匆匆过客 提交于 2019-12-01 22:25:53
I have this code in model that returns data $this->db->select('title, content, date'); $where = "name='Joe' AND status='boss'"; $this->db->where($where); $query = $this->db->get('mytable'); return $query->result(); I am using a manual where and i wanted to know whether the concept of manual where in updates and possibly in deletes is allowed. This code updates a table based on a single where condition $data = array( 'title' => $title, 'name' => $name, 'date' => $date ); $this->db->where('id', $id); $this->db->update('mytable', $data); Is doing this allowed in codeigniter $data = array( 'title'

How to join multiple entities on a foreign ID in Symfony 4 using a query builder?

孤者浪人 提交于 2019-12-01 22:20:43
问题 I'm trying to learn Symfony. Today I was following The associations tutorial. I decided to make a small application that a House, Kitchens, Bedrooms, and cabinets. I (tried to ;-) ) make a small Class diagram using draw.io to give you a better idea. So basically a House can have multiple Bedrooms and multiple Kitchens. Each kitchen can have multiple cabinets. The House has an id and a name. The Bedroom and Kitchen as well. The cabinet has id, shopUrl and is also linked via a foreign key (

How to join multiple entities on a foreign ID in Symfony 4 using a query builder?

 ̄綄美尐妖づ 提交于 2019-12-01 20:23:33
I'm trying to learn Symfony. Today I was following The associations tutorial. I decided to make a small application that a House, Kitchens, Bedrooms, and cabinets. I (tried to ;-) ) make a small Class diagram using draw.io to give you a better idea. So basically a House can have multiple Bedrooms and multiple Kitchens. Each kitchen can have multiple cabinets. The House has an id and a name. The Bedroom and Kitchen as well. The cabinet has id, shopUrl and is also linked via a foreign key ( account_id ) to its parent Kitchen. I also link the Kitchen and the Bedroom to the House using a foreign

How to select a specific field additionally to a tables default fields?

[亡魂溺海] 提交于 2019-12-01 19:51:45
I an looking to use a JOIN to select data from a table and a view in CakePHP like so : $this->Annonces->find('all') ->where($arrFiltres) ->order($arrOrder) ->join([ 'table' => 'annonces_suivis', 'alias' => 'AnnoncesSuivis', 'conditions' => [...], ]); And would like to be able to select all the fields from the first table and som of the jointed table like so : ->select(['Annonces.*', 'AnnoncesSuivis.id']); But this creates a faulty SQL query. .* isn't supported by the ORM Query, it will convert this to Annonces.* AS Annonces__* which is invalid SQL. It would work with the lower level Database

How to build query with selecting by value of foreign object's field

半世苍凉 提交于 2019-12-01 18:49:39
What is the best way for querying by using the value of foreign object's field? Suppose I have these three classes. UnitResult class which describes amount of Units: @DatabaseTable public class UnitResult { public static final String ID_FIELD_NAME = "id"; public static final String UNIT_COLUMN_NAME = "unit"; public static final String RESULT_COLUMN_NAME = "result"; @DatabaseField(generatedId = true, columnName = ID_FIELD_NAME) public Integer id; @DatabaseField(foreign = true, canBeNull = false, columnName = UNIT_COLUMN_NAME) public Unit unit; @DatabaseField(canBeNull = true, columnName =

Missing insert() method on Doctrine DBAL Query Builder

青春壹個敷衍的年華 提交于 2019-12-01 18:34:53
I feel like I'm having a moment where I'm missing something small here; I've been having issues using the insert() method on the QueryBuilder component on Dotrine DBAL 2.2.x / 2.3.x. I did some investigation and here's the snippet from the QueryBuilder page from the DBAL Documantation The \Doctrine\DBAL\Query\QueryBuilder supports building SELECT, INSERT, UPDATE and DELETE queries. Which sort of query you are building depends on the methods you are using. It goes on further to explain code examples, such that I can simply do: $builder = $connection->createQueryBuilder(); $result = $builder -

Trying to update one table after inserting into another one with Symfony2 and Doctrine2

烈酒焚心 提交于 2019-12-01 13:52:51
I wrote a function in BudgetRepository that is called when inserting new data into Budget table. The function is: public function addBudgetToClient($clientId, $budgetId) { return $this->createQueryBuilder('b') ->update('PanelBundle:Client', 'c') ->set('c.budget', $budgetId) ->where('c.id = ' . $clientId) ->getQuery() ->execute(); } And the BudgetController does this: public function addAction(Request $request) { $form = $this->createForm(new BudgetType()); $manager = $this->getDoctrine()->getManager(); $Budget = $manager->getRepository('PanelBundle:Budget'); $Client = $manager->getRepository(