Arbitrary Selects in EoD SQL

Sometimes, when writing database driven applications, you need to break the PreparedStatement rule, and do a completely arbitrary select. I find I use such queries a lot when dealing with tags, since you never know how many you’re going to be working with, and some databases don’t support arrays as parameters (for “IN”).

In EoD SQL (as with the EoD RI), you construct your queries as interfaces with your query strings in annotations. This doesn’t allow you to change the SQL query at runtime, it’s fixed at compile time. So to plug this little annoyance, I decided to add a method. It looks like this:

public static <T> DataSet<T> select(Class<T> type, String query, Object... parameters)

Imaging a class User with some fields that are bound to a “users” table in the database. To select all users with a specific first name, you could:

DataSet<User> users =, "SELECT * FROM users WHERE first_name LIKE ?1", firstName);
for(User u : users) {
// do something with "u"


Currently the code is available in Subversion, but it will be included in the upcoming 1.0 release of EoD SQL. There are several other improvements waiting to be developed, but they will wait until after the 1.0 release.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: