How to convert PQL query in to JSON? - json

I'm trying to convert the below PQL query (Publisher's Query Language) in to JSON format.
StatementBuilder statementBuilder =
new StatementBuilder()
.where("CUSTOM_CRITERIA LIKE '%permutive'")
.withBindVariableValue("orderId", orderId);
Can any one help with this ?
Thanks in advance !

Related

Find in array type field Doctrine and Mysql

I created a field "array" on the mysql DB, following this response: Link
when persist the data look this:
{i:0;s:4:"3410";i:1;s:4:"3415";i:2;s:4:"3459";i:3;s:4:"3460";i:4;s:4:"3492";}
But don't find in sql query, I tried some things, but I still can not get it
SELECT *
FROM classified_zones cz
WHERE cz.locations_ids IN ( 3492 )
You can build dynamically a doctrine query similar to:
$qb->select('cz')
->from('myBundle:ClassifiedZones', 'cz')
->where('cz.locationsIds LIKE :id')
->setParameter('id', '%:'.strlen($id).':"' . $id . '"%' );
The final sql query should be similar to Ɓukasz's response.
Following query should work:
SELECT *
FROM classified_zones cz
WHERE cz.locations_ids LIKE '%s:4:"3492";%'
Don't use "unfamiliar formats", MySQL supports a native JSON data type.
See: https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#function_json-contains
For example:
locations_ids = "[1,2,3,3492]"
SELECT cz.* FROM classified_zones cz WHERE JSON_CONTAINS(cz.locations_ids, 3492)

Accessing JSON Object with a datetype like key

Please Help me. I have JSON data like this :
The JSON was generated by nodeJS client.query multiple statement and the result stored in rows_final
I try to access the key, for example 2012-01-01 so I write my code like this :
JSON.stringify(rows_final[3][0].2012-01-01)
The result is error like this :
But if I try to access the other key, for example the nip key, there is no problem
How to access that key in a proper way ?
2012-01-01 is an invalid name for a javascript variable. Trying access it like so:
JSON.stringify(rows_final[3][0]['2012-01-01'])
Here is a simpler example:
var s = '{"x":1,"2012-01-01":2}';
var o = JSON.parse(s);
console.log(o.x);
console.log(o['2012-01-01']);
Output:
1
2

Issue with BigDecimal value in groovy : Retrieving diff value

I am using Groovy/Grails framework, I am fetching the Bigdecimal value from the mysql DB using the
Query = "select d.quantitativeData FROM MyTable d where d.segment.id = " + segmentid +
" and d.sustainabilityIndicatorSubQuestion.id = "+questionid+" and d.tenantId= " +
TenantUtils.getCurrentTenant()+" order by d.id desc",[max:1]"
quantitativeData is a Bidgecimal variable.
But the value is retrieved from this query is like "0E-20" format, but the value in the database like '121.00000000000' , How to resolve this, can anybody help me out.
Thanks in advance.
The BigDecimal is being converted to the string "0E-20", because you're constructing the query by concatenating strings together, rather than by using ? query placeholders.
If you use placeholders instead of string concatenation it will resolve this problem and also make you immune to SQL injection attacks.

ZF2 Query WHERE clause with DATE() for datetime column

I have a column with datetime data type and I want to build a SQL query in Zend Framework2 which compare date part with user input date.
Need to build similar part as DATE(datetime column) = '2014-09-16' with;
$select->where();
would be very grateful if someone could help on this.
Use like this:
$date = '2014.05.24';
$select->where('date(expecting_date) = "'.$date.'"');
You should use predicate expression for these kind of conditions, like :
$select = new \Zend\Db\Sql\Select(table name);
$select->where(new \Zend\Db\Sql\Predicate\Expression('DATE(datetime) = ?', '2014-09-16'));

How can I find the datatypes of data fields using pdo?

try {
$q = $conn->prepare("DESCRIBE delete_subscriber");
$q->execute();
$tableFieldDS = $q->fetchAll(PDO::FETCH_COLUMN);
}
This code is to fetch the column name , so i am wondering are there any similar function i can use to get an array of the column data type? Thank you.