Issue #26 resolved
Anonymous created an issue

this is more a question probably than an issue. I was trying to write the code for a login, and i came across "Criteria", i needed two equal conditions joined with an AND condition: username and password, to verificate the user.

I played a little with AND Junctions but there is no trace of equal condition, there is only like condition that obviously doesn't fit my needs.

So i tried simply this:

var _authCrt : Criteria = ev.data as Criteria;
_authCrt.addEqualsCondition("username", username)
          .addEqualsCondition("password", password);    

And works! So the question is: what's the difference between using AND Junction and the code above? And why there is no equal condition in Junction?

Comments (3)

  1. Robert Lieske

    Above code produces a parameterised SQL query (prepared statement), whereas junction.addLikeCondition() would produce simple SQL. So far parameterised SQL is not supported by Junction. There is no code in Junction.as yet because EqualsCondition is a ParameterisedCondition (thats why it should be better named ParameterisedEqualsCondition - this would break existing applications however), so it would require additional effort to implement.

    However you can add

            public function addEqualCondition(property:String, str:String):Junction
            {
                var column:Object = _entity.getColumn(property);
    
                if (column)
                {
                    _filters.push(new EqualCondition(column.table, column.column, str));
                }
                return this;
            }
    

    to Junction.as

    and provide EqualCondition (without 's'):

    package nz.co.codec.flexorm.criteria
    {
    
        public class EqualCondition extends Condition
        {
            private var _str:*;
    
            public function EqualCondition(table:String, column:String, str:*)
            {
                super(table, column);
                _str = str;
            }
    
            override public function toString():String
            {
                var res:String = column + " = ";
    
                if (_str is String)
                {
                    res += "'" + _str + "'";
                }
                else
                {
                    res += _str;
                }
                return res;
            }
        }
    }
    

    Be aware of SQL injections with simple SQL generated by Junction.

  2. Log in to comment