Many thanks to all of you. I learned a lot from your samples. This is my very first contribution to this forum.
I wrote this composer library to support object oriented programming with sql statements.
This first version has following features:
- support of DQL and DML statements (select, insert, update, delete)
- it handles joins and complex nested conditions
This library does not execute and handle data access. It only composes
sql statements. The advantage of this library is, that you can write complex statements in an object oriented way. Sql commands may be arranged in any order. This is different to common sql string handling.
The library comes along with a fluent design. SqlObject library has a dialect class which generates sql statements. In future releases further dialects could be supported.
I have seen some DB Wrappers. You can use this library with these wrappers easily.
e.g.
in JAVA
in b4a:
output:
I wrote this composer library to support object oriented programming with sql statements.
This first version has following features:
- support of DQL and DML statements (select, insert, update, delete)
- it handles joins and complex nested conditions
This library does not execute and handle data access. It only composes
sql statements. The advantage of this library is, that you can write complex statements in an object oriented way. Sql commands may be arranged in any order. This is different to common sql string handling.
The library comes along with a fluent design. SqlObject library has a dialect class which generates sql statements. In future releases further dialects could be supported.
I have seen some DB Wrappers. You can use this library with these wrappers easily.
e.g.
in JAVA
B4X:
SqlSelect s = new SqlSelect();
s.from("users").column("username");
s.where(
SqlObject.Or()
.add(
SqlObject.And()
.add(SqlObject.EQ("is_deleted", 1))
.add(SqlObject.EQ("is_super", 0))
)
.add(SqlObject.EQ("id",1))
);
in b4a:
PHP:
Dim stmt As SqlObject
Dim s As SqlSelect
stmt.Select() _
.column("username") _
.from("users") _
.where( stmt.Or() _
.add(stmt.And() _
.add(stmt.EQ("is_super", 1)) _
.add(stmt.Like("is_deleted", 0)) _
) _
.add(stmt.EQ("id", 1)) _
)
output:
B4X:
SELECT username FROM users WHERE (is_super=1 AND is_deleted=0) or (id=1)
Attachments
Last edited: