Create text in query builder, select - cakephp-3.8

I need to add text in Query builder select.
SELECT '5 a 8 lugares' as 'lugares', count(*) AS 'livres' FROM salas S;

I solved the problem
$lugares_3_4->select(['lugar' => $lugares_3_4->func()->concat(['3 a 4
lugares']),'livres'=>'count(Salas.id)'])

Related

Modify format of sqllite select columns

I am pretty new to SqlLite db. I have the following table along with its data. I want to modify the columns data which appears as output.
CREATE TABLE students (studentId TEXT, firstName TEXT, studentNo TEXT);
INSERT INTO students VALUES ("6b975012-ec43-496e-b1df-44a214437287" ,"Virat" ,"530642685”);
The following select query should return
SELECT studentNo from students;
XXXXX2685
I have tried using built in functions available with SqlLite without any luck.
SELECT REPLACE(studentNo, '', 'X') as Student_SSN from students;
Could anyone please let me know how to achieve this.
thanks
select studentNo,
format('%.*c', length(studentNo)-4, 'X') || substr(studentNo,-4,4) as student_SSN
from students;
Result:
studentNo|student_SSN|
---------+-----------+
530642685|XXXXX2685 |
If the number of 'X' is not important, use a string literal:
select studentNo,
'XXXXX' || substr(studentNo,-4,4) as student_SSN
from students;

APEX 5, change value of select list by button e text

I just start using apex from few time. So I hope you'll forgive me if I ask things that are very simple.
I have a select list populated by a SQL Query, my SQL instruction is SELECT NUM, ID FROM TABLE.
I'd like to change the query dynamically adding a " WHERE NUM LIKE %myVar%", where "MyVar" is the test of a text Item, so I'd like to change the content of the select list pressing the button.
Is it possible?
thanks in advance for any answer.
I find a partial solution. I bind to select list a PL/SQL function returning a SQL Script and I add an text item called filter.
My function is:
declare
q varchar2(4000);
begin
q:='select numero, ';
q:=q||'id from t_doc ';
q:=q||'where numero = :FILTROPT';
return q;
end;
But if I use like with a percent in the function instead of "=", apex raise me an error.
Any suggestion?

Drupal Views: Join file_managed with custom table

I have a custom table with a file id that I want to join with the file_managed table.
My query looks like this:
SELECT ofertias_producto.sku AS sku
FROM
{ofertias_producto} ofertias_producto
INNER JOIN {file_managed} file_managed_ofertias_producto
ON ofertias_producto.id_imagen = file_managed_ofertias_producto.fid
LIMIT 10 OFFSET 0
The join is done right. The problem is that I'm not seeing any fields of the file managed table.
Could you tell me what I'm doing wrong? Thanks!
You did not SELECT any field from file_managed table
SELECT ofertias_producto.sku AS sku, file_managed_ofertias_producto.some_field as some_field
FROM
{ofertias_producto} ofertias_producto
INNER JOIN {file_managed} file_managed_ofertias_producto
ON ofertias_producto.id_imagen = file_managed_ofertias_producto.fid
LIMIT 10 OFFSET 0
Change some_field with appropriate field name of file managed table

Recursive Query CTE in SQL Lite

I have the Following table Structure. (I am new to SQL Lite)
create table Relations
(
Code int,
ParentCode int ,
fname text
)
GO
insert into Relations values(1,null,'A');
insert into Relations values(2,null,'B');
insert into Relations values(3,2,'C');
insert into Relations values(4,3,'D');
I want to get the initial parent of Code =4 :
i.e. values 2 null B
I am not able to figure out how to write a recursive query in sqllite.
Thanks in Advance..
Was a version issue..
This query was not working & was getting a syntax Error.
I upgraded From 3.7.17 To 3.8.7.4 version & it worked..
WITH RECURSIVE
works(Code,Parent) AS (
Select Code,ParentCode from Relations a where a.Code=4
UNION
SELECT Relations.Code, Relations.ParentCode FROM Relations , works
WHERE Relations.Code=works.Parent
)
SELECT * FROM works where Parent is null

Previous/next navigation that uses ordering/sorting different than node id (n.nid)

I am trying to create "previous/next node" navigation on my nodes in order to show 2 previous and 2 following nodes in the term currently being viewed. Here is the code that displays 2 prev and 2 next nodes, but it is not taxonomy aware, i. e. it sorts nodes according to their IDs:
Prev/Next node navigation with a thumbnail in a full node
If I add a node in the term after some time, it will display this node as the last one, not as a "neighbour" of a node uploaded e.g. 3 months ago.
I have tried with "n.title", but it doesn't change anything. Ideally, it should order them either by titles or url aliases.
Thank you in advance!
it's not querying the taxonomy tables in the database query. You probably want to add a variable to the function as such dad_prev_next($current_node = NULL, $op = 'p', $tid) to pass it the term ID and then add that to your query through an inner join
SELECT n.nid, n.title
FROM {node} n
INNER JOIN {taxonomy_index} t
ON n.nid = t.nid
WHERE n.nid $sql_op :nid
AND t.tid = :tid
AND type IN ('photos')
AND status = 1
ORDER BY n.nid $order
LIMIT 1
I think that should be pretty close, then just pass that at the end of db_query db_query($sql, array(':nid' => $current_node -> nid, ':tid' => $tid));
Newer version of Previous/Next module has multiple options for sorting prev/next nodes. You can use the workaround to get thumbnails too:
http://drupal.org/project/prev_next
http://drupal.org/node/1790290

Resources