Exemplo n.º 1
0
 public Where Or(Where where)
 {
     if(_andData.Count!=0)
     {
         _orData.Add(_andData);
         _andData = new List<Where>();
     }
     return this;
 }
Exemplo n.º 2
0
        public override NameValueCollection[] Find(string tableName, Where.Where where)
        {
            var collections = new List<NameValueCollection>();

            var conn = new SQLiteConnection(_connectionStringBuilder.ToString());
            conn.Open();
            var cmd = conn.CreateCommand();
            cmd.CommandText = "SELECT * FROM `" + tableName + "` WHERE " + GetWhereSQL(where);

            var reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                collections.Add(reader.GetValues());
            }
            reader.Close();
            conn.Close();

            return collections.ToArray();
        }
Exemplo n.º 3
0
        private string GetWhereSQL(Where.Where where)
        {
            var writer = new StringWriter();
            where.Or(null);
            foreach (var ordata in where.GetOrData())
            {
                writer.Write("(");
                foreach (var anddata in ordata)
                {
                    if(anddata is ModelWhere)
                    {
                        writer.Write("(");
                        foreach (var field in ((ModelWhere)anddata).GetModel().GetFieldData())
                        {
                            var value = field.GetInfo().GetValue(((ModelWhere) anddata).GetModel());

                            if (value == null)
                                continue;
                            if(value is long && ((long)value) == 0)
                                continue;

                            writer.Write("{0} = '{1}' and ", field.GetInfo().Name.ToLower(), value);
                        }
                        writer.Write("true)");
                    }
                    else if (anddata is StringWhere)
                    {

                    }
                    else
                    {
                        writer.Write(GetWhereSQL(anddata));
                    }
                    writer.Write(" and ");
                }

                writer.Write("true) or ");
            }
            writer.Write("false");

            return writer.ToString().Replace(" or false","").Replace(" and true","");
        }