How can I access the LIMIT clause on a SELECT statement in Cassandra? Suppose that I have the following SELECT statement
Select select = QueryBuilder.select().all().from("test","users");
select.limit(10);
Then somewhere else in the code I want to get the LIMIT clause(in this example 10). Is there an API through which I could access it?
You can use select.getQueryString to get the full query string and then filter the string to get what you need.
Related
I use spring boot, and I want to add 1 year to a specific column in mysql database
String queryRecherche = "UPDATE myTable t SET t.dateDebut = DATE_ADD(t.dateDebut, INTERVAL 1 YEAR) WHERE.id = 3 ";
Query query = em.createQuery(queryRecherche);;
query.executeUpdate();
But I get the folowing error :
org.hibernate.query.sqm.ParsingException: line 1:66 no viable alternative at input 'DATE_ADD(t.dateDebut,INTERVAL1'
Have you please any suggestions to do this.
You're using Hibernate 6 (I can tell by the error message), so the correct HQL syntax to use is:
UPDATE MyEntity t SET t.dateDebut = t.dateDebut + 1 year WHERE t.id = 3
You had three errors in your query:
You referred to the name of a table instead of the name of an entity class in the UPDATE clause.
You used the unportable MySQL DATE_ADD function instead of the portable HQL date/time arithmetic described here.
The syntax of your WHERE clause was garbled.
Perhaps you meant for this to be a native SQL query, in which case you called the wrong method of Session. But there's no need to use native SQL for the above query. As you can see, HQL is perfectly capable of expressing that query.
You can use SQL directly, via createNativeQuery, or register a new function as shown in this example to call it from HQL
I would like to launch simple code:
SelectQuery query = dsl.select(field ("id"), field("title")).from("dict.models").getQuery();
if (modelId > 0) query.addConditions(field("model_id", SQLDataType.INTEGER).equal(modelId));
But infortunately in getSQL() I can only see:
select id, title from dict.models where model_id = ?
Where is a mistake?
Thanks.
Query.getSQL() generates the SQL statement as it would be generated if you let jOOQ execute a PreparedStatement - with bind variables. The bind variables can be extracted in the right order via Query.getBindValues()
If you want to inline all bind values into the generated SQL, you have various options through the jOOQ API (all equivalent):
Using Query.getSQL(ParamType) with ParamType.INLINE
Using dsl.renderInlined(QueryPart)
Using StatementType.STATIC_STATEMENT in your Settings
I am trying to build a query using jOOQ, this is my test code:
DSLContext create = DSL.using(SQLDialect.DERBY);
String query = create.select().from(TABLE).limit(1).offset(0).getSQL()
I get as query:
select field1, field2...fieldN etc from TABLE offset ? rows fetch next ? rows only
the problem is ? in ? rows fetch next ? rows only it seems to ignore the values that i used in limit and offset to build the query, why?
I am trying to select the first row from the results and I am using jooq 3.4.1
Thanks for the help
Query.getSQL() returns your SQL string with ? as placeholders for your bind variables. The idea is that you can feed this statement to a PreparedStatement and then explicitly bind all variables, which are available through Query.getBindValues().
You can also have jOOQ inline all your bind variables, by calling Query.getSQL(ParamType) as such:
String sql = query.getSQL(ParamType.INLINED);
I'm using Mysql database. I got stored data for certain columns with value of a\"a. I used following query to select but it failed:
select * from table_name where coloum_name like "%a\"%";
I spend some hours to find a query to select and the following one is working:
select * from table_name where coloum_name like "%a\\\\\\\\""%";
I'm using hibernate in my application, so I used:
criteria.add(Restrictions.ilike("coloum_name","%a\\\\\\\\""%"));
but it's not working. Any possible way to select via criteria??
Check this one. Hope this will help for you.
http://levanhuy.wordpress.com/2009/02/19/providing-an-escape-sequence-for-criteria-queries/
How to get specific row count in Java from Object DB ?
I need to get result for query like :
SELECT COUNT(id) FROM Users WHERE banned=true
Try using * as field:
SELECT COUNT(*) as count FROM Users WHERE banned = false
OrientDB does support SQL like queries and also supports the count(<field>|*) function according to the documentation: http://code.google.com/p/orient/wiki/SQLWhere#Functions