briangormanly / 4dflib

4DF (Fourth Dimensional Form) Library
http://www.4dflib.com
GNU Lesser General Public License v3.0
5 stars 4 forks source link

Adding optional constructor to WhereClause #27

Open blackjack26 opened 8 years ago

blackjack26 commented 8 years ago

When creating a WhereClause object, to make syntax shorter there could be an optional constructor in which you pass in some sort of string that sets the internal variables of the object.

Ex:

// Current Syntax
WhereClause wc = new WhereClause();
wc.name = "df";
wc.operator = WhereClause.Operators.NOT_EQUAL;
wc.value = "true";
wc.conditional = WhereClause.CONDITIONALS.AND;

// New Syntax
WhereClause wcNew = new WhereClause("AND df <> true");
Corls commented 8 years ago

That kinda defeats the point of WhereClause though...

Corls commented 8 years ago

oh oh oh! Here's one. Okay, instead of making it an optional constructor, we instead update the SqlStatement to contain a function "where(String clause)". This way you don't need to go SqlStatement.where(new WhereClause('AND df <> true')); but SqlStatement.where('AND df <> true'));

Corls commented 8 years ago

or make the optional constructor package-private so SqlStatement.where("AND df <> true"); reads where(String clause) { where.add(new WhereClause(clause); } taking that extra step out for the developer who is using this method, but also allows for the flexibility of needing the constructor after all, in which case you would add "public" in front of the optional constructor.

Corls commented 8 years ago

With either idea, we would be able to make the SqlStatement.where be able to create several where clauses at once, meaning someone could literally type out the whole where WHERE df <> true AND cf = true AND tid = 1 and it'd generate all 3 clauses.

Corls commented 8 years ago

I was just making a quick scratch up to see how this would look like and realized that these ideas have no way of conveying the valueDataType and thus puts the whole idea on hold until it is worked out a clean, non-obtrusive way to declare the type.

Corls commented 8 years ago

Meaning, the code for the constructor & function will be in there on my next commit, but are commented out.

Corls commented 8 years ago

Or, instead of a constructor, we could have a "parse" function, so it's like "WhereClause.parse(String clause)"