Can make a query without using $ this->query()? - mysql

I have more queries in mysql, but i not use the $this->query(), because I do not need to create arrays. in cakephp there any way? the function this->query force to go through the model.
thanks

You can try with DboSource query method

Related

suggest an alternative query for this type of condition in SQL

suggest an alternative query for this type of condition in sql
select v_sdi_previous_id,v_sdi_settlement_flag,v_sdi_studentid
from schooldev."STUDENT_DETAILS_INFO"
where (upper(v_sdi_studentid)=upper('BS15B016') or (upper(v_sdi_previous_id)=('BS15B016')) )
and n_sdi_schoolid='1' and v_sdi_active_flag='Y'
It is pretty simple query. What alternative you want ?
You may use IN instead of multiple OR like-
where upper(v_sdi_studentid) IN ('BS15B016', 'BS15B016')
and n_sdi_schoolid='1' and v_sdi_active_flag='Y'.
Nothing much is needed with this query unless you are not getting the output as per your need.
select v_sdi_studentid as new_id,v_sdi_previous_id,v_sdi_settlement_flag from schooldev."STUDENT_DETAILS_INFO" where upper(v_sdi_previous_id) IN ('BS15B016') and n_sdi_schoolid='1' and v_sdi_active_flag='Y'

Using "Point"-Datatype in Phinx-Migration (in CakePhp)

I'm creating an API for POIs and use the POINT-Type to store the coordinates.
As my company uses CakePHP I have to write a migration-script with Phinx.
But I don't have any Idea how to correctly create a column with the POINT-Type.
Sure, I just could make an "ALTER TABLE ..." in a handwritten Query, but maybe there is a better way?
Versions:
Cake: 3.4.7
Phinx: 0.6.5
MySQL: 5.7.18
Phinx Does not provide an adapter for POINT yet.
You should create your query manually.
See also Unable to seed data with POINT datatype #999
Just use "point" as you would use any other datatype as the second parameter of addColumn().
It's just not documented yet.
Credits for this solution are going to #ndm;
I just think it's worth putting this as answer instead as a comment.
Looks like Phinx supports point types for quite some time now (the docs are not up to date)... try to use \Phinx\Db\Adapter\AdapterInterface::PHINX_TYPE_POINT as the type

CakePHP 2: How to generate an sql insert script from an array

Can I generate an sql insert statement from an array returned by find methods?
Thanks.
Yes, You can.
After performing the find() operation iterate your data using foreach loop and make a string based insert query with ";" as separator after each insert query. Create a file with extension as .sql and use force download component to download it.
I have some sort of code that can help you. I'll try to give you the code soon.

use mysql inbuilt functions with cakePHP find()

can any one help me to use the mysql inbuilt function in cakePHP?????
If you don't want to use
$this->Model->query($yoursql);
Then there's still another way for some mysql functions such as concat,date_format
$this->Model->find($findtype,array('fields'=>array('concat (column1,column2,...) as con','date_format(...) as mydate'),'conditions'=>...));
There is an example of how to use CONCAT in the book. I imagine you would be able to extend the syntax to use the other MySql functions as required.

How to get an array of table names in ruby

I'm trying to get the output of the query 'SHOW TABLES FROM database_name' into an array using the ActiveRecord database connection. I can't seem to figure out how to do this. can someone please enlighten me?
-C
Use what ActiveRecord gives you out of the box:
ActiveRecord::Base.connection.tables
I tried
ActiveRecord::Base.connection.execute("DESCRIBE TABLE table_name")
and was told to check my SQL manual. Doing so, I found that
ActiveRecord::Base.connection.execute("DESCRIBE table_name").each{|r| p r }
worked. Put whatever actual logic you need in the block.