Ejemplo n.º 1
0
        /// <summary>
        /// Converts an array of <see cref="string"/> values to the desired query fragment format.
        /// </summary>
        /// <param name="format">The format to use for the query fragment.</param>
        /// <param name="values">The values to be generated in the specified format for the query fragment.</param>
        /// <param name="distinct">if set to <c>true</c>, <paramref name="values"/> will be filtered for doublets.</param>
        /// <returns>A query fragment in the desired format.</returns>
        public static string GetQueryFragment(QueryFormat format, string[] values, bool distinct)
        {
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }
            if (values.Length == 0)
            {
                throw new ArgumentException("Value cannot be empty.", nameof(values));
            }
            if (distinct)
            {
                values = new List <string>(values.Distinct()).ToArray();
            }
            switch (format)
            {
            case QueryFormat.Delimited:
                return(StringConverter.ToDelimitedString(values));

            case QueryFormat.DelimitedString:
                return(StringConverter.ToDelimitedString(values, ",", "'{0}'"));

            case QueryFormat.DelimitedSquareBracket:
                return(StringConverter.ToDelimitedString(values, ",", "[{0}]"));

            default:
                throw new ArgumentOutOfRangeException(nameof(format), string.Format(CultureInfo.InvariantCulture, "The specified query format value, {0}, is unsupported.", format));
            }
        }
Ejemplo n.º 2
0
        /* ------------------------------------------- */

        #region [ Insert method ]

        /// <summary>
        /// Insert the record to table with table_name with given fields.
        /// </summary>
        /// <param name="table_name">table name</param>
        /// <param name="fields">column and values</param>
        /// <returns>Returns exec result of Insert.</returns>
        public virtual int Insert(string table_name, Hashmap fields)
        {
            int result = -100;

            try
            {
                if (string.IsNullOrWhiteSpace(table_name))
                {
                    throw new Exception("Table Name can not be null or empty.");
                }

                if (table_name.Contains("drop") || table_name.Contains("--"))
                {
                    throw new Exception(
                              "Table Name can not be contain restricted characters and text.");
                }

                if (fields == null)
                {
                    throw new Exception(
                              "Column list can not be null.");
                }

                if (fields.IsEmpty())
                {
                    throw new Exception(
                              "Column list can not be empty.");
                }

                QueryFormat qf   = new QueryFormat(QueryTypes.Insert);
                QueryAdds   adds = new QueryAdds(this.conn_type);

                string query = "", cols = "", vals = "";

                Hashmap h = new Hashmap();

                foreach (var field in fields.Keys())
                {
                    cols = string.Format("{0}, {1}{2}{3}", cols, adds.Prefix, field, adds.Suffix);

                    vals = string.Format("{0}, {1}{2}", cols, adds.ParameterPrefix, field);

                    h.Set(string.Format("{0}{1}", adds.ParameterPrefix, field), fields.Get(field));
                }

                cols  = cols.TrimStart(',').TrimStart();
                vals  = vals.TrimStart(',').TrimStart();
                query = string.Format(qf.Format, table_name, cols, vals);

                result = this.Execute(query, CommandType.Text, h);
            }
            catch (Exception)
            {
                throw;
            }

            return(result);
        }
Ejemplo n.º 3
0
        public void Deserialize(byte[] objBytes)
        {
            var queryString  = Encoding.ASCII.GetString(objBytes);
            var elementParts = queryString.Split('|');

            Format     = (QueryFormat)Enum.Parse(typeof(QueryFormat), elementParts[0]);
            Name       = elementParts[1];
            TargetType = elementParts[2];
        }
Ejemplo n.º 4
0
 public RemoteElementQuery(
     QueryFormat format,
     string name,
     string targetType
     )
 {
     Format     = format;
     Name       = name;
     TargetType = targetType;
 }
Ejemplo n.º 5
0
        public override void GetQueryFormat(IReadOnlyEntity entity, QueryFormat format)
        {
            var fileInfo = entity.GetComponent(FileInfo.TypeCode);

            if (fileInfo == null)
            {
                return;
            }

            format.AddParameter(Parameters.FileName);
            format.AddParameter(Parameters.HashMD5);
            format.AddParameter(Parameters.HashSHA1OfMD5);
        }
Ejemplo n.º 6
0
        public virtual int Delete(string table_name, string where_column, object where_value)
        {
            int result = -1;

            try
            {
                if (string.IsNullOrWhiteSpace(table_name))
                {
                    throw new Exception("Table Name can not be null or empty.");
                }

                if (table_name.Contains("drop") || table_name.Contains("--"))
                {
                    throw new Exception(
                              "Table Name can not be contain restricted characters and text.");
                }


                if (string.IsNullOrWhiteSpace(where_column))
                {
                    throw new Exception("Where Column Name can not be null or empty.");
                }

                if (where_column.Contains("drop") || where_column.Contains("--"))
                {
                    throw new Exception(
                              "Table Name can not be contain restricted characters and text.");
                }

                QueryFormat qf = new QueryFormat(QueryTypes.Delete);
                QueryAdds   qo = new QueryAdds(this.conn_type);

                string query = "", vals = "";
                vals  = string.Format("{0}{1}{2}={3}{1}", qo.Prefix, where_column, qo.Suffix, qo.ParameterPrefix);
                query = string.Format(qf.Format, table_name, vals);

                Hashmap p = new Hashmap();
                p.Set(string.Format("{0}{1}", qo.ParameterPrefix, where_column), where_value);

                result = this.ExecuteQuery(query, p);
            }
            catch (Exception)
            {
                throw;
            }

            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the CommandText formatted with specified format
        /// </summary>
        /// <param name="format">Use Text to format as Simple SQL Query or use HTML to format as Colored SQL Query.</param>
        /// <returns>Formatted query</returns>
        public virtual string GetSqlFormatted(QueryFormat format)
        {
            switch (format)
            {
            case QueryFormat.Text:
                return(this.GetQueryFormattedAsText(_dbCommand));

            case QueryFormat.Html:
                return(this.GetQueryFormattedAsHtml(_dbCommand));

            case QueryFormat.Variables:
                return(this.GetQueryFormattedAsVariables(_dbCommand));

            default:
                return(string.Empty);
            }
        }
Ejemplo n.º 8
0
        public T GetObjectById <T>(int Id) where T : new()
        {
            T result = default(T);

            try
            {
                T t = (T)Activator.CreateInstance(typeof(T));

                string id_col = string.Format("{0}", t.GetType().GetMethod("GetIdColumn").Invoke(t, null));

                if (string.IsNullOrWhiteSpace(id_col))
                {
                    throw new Exception("Id Column can not be empty.");
                }

                string tableName = string.Format("{0}", t.GetType().GetMethod("GetTableName").Invoke(t, null));
                if (string.IsNullOrWhiteSpace(tableName))
                {
                    throw new Exception("TableName can not be empty.");
                }

                IQueryFormat qformat = new QueryFormat(QueryTypes.SelectWhereId);
                IQueryAdds   adds    = new QueryAdds(conn_type);
                string       q       = qformat.Format;

                q = q.Replace("#TABLE_NAME#", tableName);
                q = q.Replace("#VALS#", string.Format("{0}={1}{0}", id_col, adds.ParameterPrefix));

                Hashmap h = new Hashmap();
                h.Set(string.Format("{0}{1}", adds.ParameterPrefix, id_col), Id);

                DataSet   ds = this.GetResultSet(q, CommandType.Text, h);
                DataTable dt = ds.Tables[0];

                List <T> listT = dt.ToList <T>(true);

                result = listT[0];
            }
            catch (Exception)
            {
                throw;
            }

            return(result);
        }
        public override void GetQueryFormat(IReadOnlyEntity entity, QueryFormat format)
        {
            var card = entity.GetComponent(KoikatuCharacterCard.TypeCode);

            if (card == null)
            {
                return;
            }

            format.AddParameter(Parameters.Name);
            format.AddSelectableValue(Parameters.Sex, card.Sex);
            format.AddSelectableValue(Parameters.Personality, card.Personality);
            format.AddSelectableValue(Parameters.ClubActivities, card.ClubActivity);
            format.AddSelectableValue(Parameters.BloodType, card.BloodType);

            format.AddSelectableValue(Parameters.TeethType, card.TeethType);

            format.AddSelectableValue(Parameters.HeightType, card.HeightType);
            format.AddSelectableValue(Parameters.BustSizeType, card.BustSizeType);
            format.AddSelectableValue(Parameters.SkinType, card.SkinType);
            foreach (var adjective in Palettes.Skin.GetAdjectives(card.SkinColor))
            {
                format.AddSelectableValue(Parameters.SkinColorType, adjective);
#if DEBUG
                format.AddSelectableValue(Parameters.InverseSkinColorType, adjective);
#endif
            }

            format.AddSelectableValue(Parameters.HairStyle, card.HairStyle);
            foreach (var adjective in card.HairColors.Select(i => Palettes.Hair.GetAdjectives(i)).SelectMany(i => i))
            {
                format.AddSelectableValue(Parameters.HairColorType, adjective);
#if DEBUG
                format.AddSelectableValue(Parameters.InverseHairColorType, adjective);
#endif
            }
        }
Ejemplo n.º 10
0
        public void Read(TProtocol iprot)
        {
            TField field;

            iprot.ReadStructBegin();
            while (true)
            {
                field = iprot.ReadFieldBegin();
                if (field.Type == TType.Stop)
                {
                    break;
                }
                switch (field.ID)
                {
                case 1:
                    if (field.Type == TType.String)
                    {
                        this.guid         = iprot.ReadString();
                        this.__isset.guid = true;
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                case 2:
                    if (field.Type == TType.String)
                    {
                        this.name         = iprot.ReadString();
                        this.__isset.name = true;
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                case 3:
                    if (field.Type == TType.String)
                    {
                        this.query         = iprot.ReadString();
                        this.__isset.query = true;
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                case 4:
                    if (field.Type == TType.I32)
                    {
                        this.format         = (QueryFormat)iprot.ReadI32();
                        this.__isset.format = true;
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                case 5:
                    if (field.Type == TType.I32)
                    {
                        this.updateSequenceNum         = iprot.ReadI32();
                        this.__isset.updateSequenceNum = true;
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                default:
                    TProtocolUtil.Skip(iprot, field.Type);
                    break;
                }
                iprot.ReadFieldEnd();
            }
            iprot.ReadStructEnd();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Update records with given parameters.
        /// </summary>
        /// <param name="table_name">table name</param>
        /// <param name="where_column">id column name, if null or empty value will be "id"</param>
        /// <param name="where_value">id column value</param>
        /// <param name="fields">column and values</param>
        /// <returns>Returns exec result of Update.</returns>
        public virtual int Update(string table_name, string where_column, object where_value, Hashmap fields)
        {
            int result = -1;

            try
            {
                if (string.IsNullOrWhiteSpace(table_name))
                {
                    throw new Exception("Table Name can not be null or empty.");
                }

                if (table_name.Contains("drop") || table_name.Contains("--"))
                {
                    throw new Exception(
                              "Table Name can not be contain restricted characters and text.");
                }

                if (fields == null)
                {
                    throw new Exception(
                              "Column list can not be null.");
                }

                if (fields.IsEmpty())
                {
                    throw new Exception(
                              "Column list can not be empty.");
                }


                if (string.IsNullOrWhiteSpace(where_column))
                {
                    throw new Exception("Table Name can not be null or empty.");
                }

                if (where_column.Contains("drop") || where_column.Contains("--"))
                {
                    throw new Exception(
                              "Table Name can not be contain restricted characters and text.");
                }


                QueryFormat qf = new QueryFormat(QueryTypes.Update);
                QueryAdds   qo = new QueryAdds(this.conn_type);

                string query = "", cols = "", vals = "";
                //query = qf.Format;
                Hashmap       h = new Hashmap();
                FreeParameter fp;
                foreach (var field in fields.Keys())
                {
                    cols = string.Format("{0}, {1}{2}{3}={4}{2}", cols, qo.Prefix, field, qo.Suffix, qo.ParameterPrefix);
                    fp   = new FreeParameter
                    {
                        Name  = string.Format("{0}{1}", qo.ParameterPrefix, field),
                        Value = fields.Get(field)
                    };
                    h.Set(string.Format("{0}{1}", qo.ParameterPrefix, field), fields.Get(field));
                }

                h.Set(string.Format("{0}{1}", qo.ParameterPrefix, where_column), where_value);

                cols  = cols.TrimStart(',').TrimStart();
                vals  = string.Format("{0}{1}{2}={3}{1}", qo.Prefix, where_column, qo.Suffix, qo.ParameterPrefix);
                query = string.Format(qf.Format, table_name, cols, vals);

                result = this.ExecuteQuery(query, h);
            }
            catch (Exception)
            {
                throw;
            }

            return(result);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Converts an array of <see cref="long"/> values to the desired query fragment format.
 /// </summary>
 /// <param name="format">The format to use for the query fragment.</param>
 /// <param name="values">The values to be generated in the specified format for the query fragment.</param>
 /// <param name="distinct">if set to <c>true</c>, <paramref name="values"/> will be filtered for doublets.</param>
 /// <returns>A query fragment in the desired format.</returns>
 public static string GetQueryFragment(QueryFormat format, long[] values, bool distinct)
 {
     return(GetQueryFragment(format, StringConverter.ToDelimitedString(values).Split(','), distinct));
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Converts an array of <see cref="long"/> values to the desired query fragment format.
 /// </summary>
 /// <param name="format">The format to use for the query fragment.</param>
 /// <param name="values">The values to be generated in the specified format for the query fragment.</param>
 /// <returns>A query fragment in the desired format.</returns>
 public static string GetQueryFragment(QueryFormat format, long[] values)
 {
     return(GetQueryFragment(format, values, false));
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Converts sequence of <see cref="long"/> values to the desired query fragment format.
 /// </summary>
 /// <param name="format">The format to use for the query fragment.</param>
 /// <param name="values">The values to be generated in the specified format for the query fragment.</param>
 /// <param name="distinct">if set to <c>true</c>, <paramref name="values"/> will be filtered for doublets.</param>
 /// <returns>A query fragment in the desired format.</returns>
 public static string GetQueryFragment(QueryFormat format, IEnumerable <long> values, bool distinct)
 {
     return(GetQueryFragment(format, values.ToArray(), distinct));
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Converts a sequence of <see cref="long"/> values to the desired query fragment format.
 /// </summary>
 /// <param name="format">The format to use for the query fragment.</param>
 /// <param name="values">The values to be generated in the specified format for the query fragment.</param>
 /// <returns>A query fragment in the desired format.</returns>
 public static string GetQueryFragment(QueryFormat format, IEnumerable <long> values)
 {
     return(GetQueryFragment(format, values.ToArray()));
 }
Ejemplo n.º 16
0
 public void Read(TProtocol iprot)
 {
     TField field;
       iprot.ReadStructBegin();
       while (true)
       {
     field = iprot.ReadFieldBegin();
     if (field.Type == TType.Stop) {
       break;
     }
     switch (field.ID)
     {
       case 1:
     if (field.Type == TType.String) {
       this.guid = iprot.ReadString();
       this.__isset.guid = true;
     } else {
       TProtocolUtil.Skip(iprot, field.Type);
     }
     break;
       case 2:
     if (field.Type == TType.String) {
       this.name = iprot.ReadString();
       this.__isset.name = true;
     } else {
       TProtocolUtil.Skip(iprot, field.Type);
     }
     break;
       case 3:
     if (field.Type == TType.String) {
       this.query = iprot.ReadString();
       this.__isset.query = true;
     } else {
       TProtocolUtil.Skip(iprot, field.Type);
     }
     break;
       case 4:
     if (field.Type == TType.I32) {
       this.format = (QueryFormat)iprot.ReadI32();
       this.__isset.format = true;
     } else {
       TProtocolUtil.Skip(iprot, field.Type);
     }
     break;
       case 5:
     if (field.Type == TType.I32) {
       this.updateSequenceNum = iprot.ReadI32();
       this.__isset.updateSequenceNum = true;
     } else {
       TProtocolUtil.Skip(iprot, field.Type);
     }
     break;
       default:
     TProtocolUtil.Skip(iprot, field.Type);
     break;
     }
     iprot.ReadFieldEnd();
       }
       iprot.ReadStructEnd();
 }
Ejemplo n.º 17
0
 public virtual void GetQueryFormat(IReadOnlyEntity entity, QueryFormat format)
 {
 }