-
Notifications
You must be signed in to change notification settings - Fork 16
Dynamic parts
Usually, queries are defined at compile time with DAO's method annotated with @BindSqlSelect
. The only thing that you can pass to queries are the parameters.
In some cases, it can be very useful to modify SQL at runtime, just to reduce the number of methods to define SQL SELECT. Kripton allows defining SQL queries specifying that a part of SELECT will be defined at runtime.
Just remember, at compile time Kripton work with JQL, at runtime with SQL.
@BindSqlSelect(jql="select * from person where id=${id} #{ DYNAMIC_WHERE } #{DYNAMIC_ORDER_BY}")
List<Person> select(long id, @BindSqlDynamicWhere String where, @BindSqlDynamicOrderBy String orderBy);
The dynamic parts can be defined with #{DYNAMIC_WHERE}
and #{DYNAMIC_ORDER_BY}
. The first one defines where conditions. The second one, the ORDER BY statement. It is possible to use them both in compact and explicit queries.
{
...
List<Person> list = dataSource.getPersonDAO().selectOne("nam", "name like 'name%'", "name asc");
}
You can use @BindSqlDynamicWhereParams to define arguments. In this case, if you need to pass to dynamic parts some arguments, in SQL just use ?
. Remember that only String[] parameter can be marked as BindSqlDynamicWhereParams
.
If you are planning to use dynamic parts
, just remember that is not a good idea to take info from UI and pass them directly to SQL. This is to prevent SQL injection.
- Introduction
- Goals & Features
- Kotlin
- Immutable or Mutable Pojo
- Annotation Processor Args
- Credits
- Articles
- Benchmarks
- Setup
- Tutorial
- Usage
- Dependencies and inspirations
- Stackoverflow
- Documentation
- SQL logging
- Data source options
- Indices
- SQL Type adapter
- Global SQL Type adapter
- Constraints
- Live data: welcome Architectural components!!
- Paged Live data
- Dynamic parts
- Transactional and batch operations
- Async Transactional and batch operations
- Global transaction
- Support for immutable POJO
- Generate Content provider
- Generate Database schema generation
- Database migration
- BindSqlColumn
- BindContentProvider
- BindContentProviderEntry
- BindContentProviderPath
- BindDao
- BindDaoMany2Many
- BindDataSource
- BindDataSourceOptions
- BindDataSourceUpdateTask
- BindIndex
- BindSqlRelation
- BindSqlAdapter
- BindSqlChildSelect
- BindSqlDelete
- BindSqlDynamicOrderBy
- BindSqlDynamicWhere
- BindSqlDynamicWhereParams
- BindSqlInsert
- BindSqlPageSize
- BindSqlParam
- BindSqlSelect
- BindSqlUpdate
- BindSqlType
- BindSqlTransaction