Exemplo n.º 1
0
 public override string Query()
 {
     if (Value == null)
     {
         return("NULL");
     }
     return(SqlCSharp.SqlValue(Value, SqlType, InList));
 }
Exemplo n.º 2
0
        private string InsertQuery(ClassProxy _proxy)
        {
            List <FieldValue> _fieldsValues = FieldsValues(_proxy.Properties(), _proxy);
            string            _query        = "INSERT INTO " + _proxy.TypeName.ToLower() +
                                              "(objectrepresentation," + Fields(_fieldsValues) + ") " +
                                              "VALUES (" + "'" + SqlCSharp.ObjectRepresentaition(_proxy.Entity) + "'" + "," + Values(_fieldsValues) + ");";

            return(_query);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retourne une chaine comme 'col1 int2,col2 text,col3 uuid ...',
        /// Utile pour la requete 'CREATE TABLE IF NOT EXISTS tablename (col1 int2,col2 text,col3 uuid...);.
        /// </summary>
        private string ColumnNames_types(Type _type)
        {
            string _columns = "";

            foreach (PropertyInfo _prInfo in _type.GetProperties())
            {
                string _columnName = SqlCSharp.ColumnName(_prInfo).ToLower();
                if (_columnName == "id")
                {
                    continue;
                }

                //ne répond pas aux conditions pour être mappée
                if (_columnName == "")
                {
                    continue;
                }

                string  _typestr = "";
                SqlType _sqlType = SqlCSharp.GetSqlType(_prInfo.PropertyType);

                if (_sqlType == SqlType.CLASS)
                {
                    _typestr = SqlCSharp.GetSqlTypeStr(SqlCSharp.GetSqlType(typeof(string)));
                }
                else
                if (_sqlType == SqlType.ENUM)
                {
                    _typestr = SqlCSharp.GetSqlTypeStr(SqlCSharp.GetSqlType(typeof(int)));
                }
                else
                if (_sqlType == SqlType.LIST)
                {
                    _typestr = SqlCSharp.GetSqlTypeStr(SqlCSharp.GetSqlType(typeof(string)));
                }
                else
                {
                    _typestr = SqlCSharp.GetSqlTypeStr(_sqlType);
                }

                if (_typestr == "")
                {
                    throw new Exception("Un type de propriété n'a pas sa correspondance sql. \n" +
                                        "propriété " + _prInfo.Name + " de type " + _prInfo.PropertyType.Name + "\n" +
                                        "dans l'objet de type " + _type.Name);
                }

                if (_columns != "")
                {
                    _columns += ",";
                }

                _columns += _columnName + " " + _typestr;
            }
            return(_columns);
        }
Exemplo n.º 4
0
        private string UpdateQuery(IEnumerable <PropertyProxy> _changes, ClassProxy _classAndProxy)
        {
            List <FieldValue> _fieldsValues = FieldsValues(_changes, _classAndProxy);

            return("UPDATE " + _classAndProxy.TypeName.ToLower() +
                   " SET " + FieldsEqualValues(_fieldsValues, _classAndProxy) +
                   " WHERE " + _classAndProxy.TypeName.ToLower() + ".id = " +
                   SqlCSharp.SqlValue(_classAndProxy.Entity, TypeHelper.Property(_classAndProxy.Entity.GetType(), "ID")) +
                   ";");
        }
Exemplo n.º 5
0
 /// <summary>
 /// <see cref="FieldValue"/> est utilisé par <see cref="DBSaveChanges"/> pour
 /// faciliter la représentation d'une propriété CSharp en champs d'une table et constituer une liste
 /// des champs à update.
 /// </summary>
 public FieldValue(object _class, PropertyInfo _prInfo)
 {
     Class        = _class;
     PrInfo       = _prInfo;
     SqlValueType = SqlCSharp.GetSqlType(_prInfo.PropertyType);
 }
Exemplo n.º 6
0
        private void BuildQuery()
        {
            if (Path != null)
            {
                __query = MemberExpression(Path);
            }

            foreach (object _element in __expression)
            {
                if (_element is DBMemberExpressionComparison other)
                {
                    if (Path != null && Path.Count > 1)
                    {
                        if (__lastOperatorLogicPos != -1)
                        {
                            if (other.Path != null)
                            {
                                int _parenthesis = Path.Count - Path.CommonMembersWith(other.Path) - 1;

                                if (_parenthesis > 0) // dans le cas ou Path et other.Path expriment le mêmes objets, _parenthesis == -1
                                {
                                    __query              = __query.Insert(__lastOperatorLogicPos, new string(')', _parenthesis));
                                    __openedParenthesis -= _parenthesis;
                                }
                            }
                            __lastOperatorLogicPos = -1;
                        }
                        other.Path = RemoveCommonMembers(other.Path);
                    }
                    __query += other.Query();
                }
                else
                if (_element is MemberPath _path)
                {
                    __query += _path.LastPropertyName.ToLower() + " ";
                }
                else
                if (_element is string s)
                {
                    if (DBExpressionBuilder.IsOperatorLogic(ref s))
                    {
                        __lastOperatorLogicPos = __query.Length;
                        __query += s + " ";
                    }
                    else
                    if (DBExpressionBuilder.IsSymbol(ref s))
                    {
                        __query += s + " ";
                        if (s == "(")
                        {
                            ++__openedParenthesis;
                        }
                        else
                        if (s == ")")
                        {
                            --__openedParenthesis;
                        }
                    }
                    else
                    {
                        __query += SqlCSharp.SqlValue(_element) + " ";
                    }
                }

                else
                {
                    __query += SqlCSharp.SqlValue(_element) + " ";
                }
            }
            __query += new string(')', __openedParenthesis);
        }