Exemplo n.º 1
0
 protected virtual void ValidateQuery(LinqServiceQuery query)
 {
     if (AllowUpdates == false && !query.Query.IsSelect)
     {
         throw new LinqException("Insert/Update/Delete requests are not allowed by the service policy.");
     }
 }
Exemplo n.º 2
0
		public object ExecuteScalar(LinqServiceQuery query)
		{
			ValidateQuery(query);

			using (var db = CreateDataContext())
			{
				var obj = db.SetQuery(new QueryContext { SqlQuery = query.Query, Parameters = query.Parameters });
				return db.ExecuteScalar(obj);
			}
		}
Exemplo n.º 3
0
        public object ExecuteScalar(LinqServiceQuery query)
        {
            ValidateQuery(query);

            using (var db = CreateDataContext())
            {
                var obj = db.SetQuery(new QueryContext {
                    SqlQuery = query.Query, Parameters = query.Parameters
                });
                return(db.ExecuteScalar(obj));
            }
        }
Exemplo n.º 4
0
		public LinqServiceResult ExecuteReader(LinqServiceQuery query)
		{
			ValidateQuery(query);

			using (var db = CreateDataContext())
			{
				var obj = db.SetQuery(new QueryContext { SqlQuery = query.Query, Parameters = query.Parameters });

				using (var rd = db.ExecuteReader(obj))
				{
					var ret = new LinqServiceResult
					{
						QueryID    = Guid.NewGuid(),
						FieldCount = rd.FieldCount,
						FieldNames = new string[rd.FieldCount],
						FieldTypes = new Type  [rd.FieldCount],
						Data       = new List<string[]>(),
					};

					for (var i = 0; i < ret.FieldCount; i++)
					{
						ret.FieldNames[i] = rd.GetName(i);
						ret.FieldTypes[i] = rd.GetFieldType(i);
					}

					var varyingTypes = new List<Type>();

					while (rd.Read())
					{
						var data  = new string  [rd.FieldCount];
						var codes = new TypeCode[rd.FieldCount];

						for (var i = 0; i < ret.FieldCount; i++)
							codes[i] = Type.GetTypeCode(ret.FieldTypes[i]);

						ret.RowCount++;

						for (var i = 0; i < ret.FieldCount; i++)
						{
							if (!rd.IsDBNull(i))
							{
								var code = codes[i];
								var type = rd.GetFieldType(i);
								var idx = -1;

								if (type != ret.FieldTypes[i])
								{
									code = Type.GetTypeCode(type);
									idx  = varyingTypes.IndexOf(type);

									if (idx < 0)
									{
										varyingTypes.Add(type);
										idx = varyingTypes.Count - 1;
									}
								}

								switch (code)
								{
									case TypeCode.Decimal  : data[i] = rd.GetDecimal (i).ToString(CultureInfo.InvariantCulture); break;
									case TypeCode.Double   : data[i] = rd.GetDouble  (i).ToString(CultureInfo.InvariantCulture); break;
									case TypeCode.Single   : data[i] = rd.GetFloat   (i).ToString(CultureInfo.InvariantCulture); break;
									case TypeCode.DateTime : data[i] = rd.GetDateTime(i).ToString(CultureInfo.InvariantCulture); break;
									default                :
										{
											if (ret.FieldTypes[i] == typeof(byte[]))
												data[i] = Convert.ToBase64String((byte[])rd.GetValue(i));
											else
												data[i] = (rd.GetValue(i) ?? "").ToString();

											break;
										}
								}

								if (idx >= 0)
									data[i] = "\0" + (char)idx + data[i];
							}
						}

						ret.Data.Add(data);
					}

					ret.VaryingTypes = varyingTypes.ToArray();

					return ret;
				}
			}
		}
Exemplo n.º 5
0
		protected virtual void ValidateQuery(LinqServiceQuery query)
		{
			if (AllowUpdates == false && !query.Query.IsSelect)
				throw new LinqException("Insert/Update/Delete requests are not allowed by the service policy.");
		}
        public LinqServiceResult ExecuteReader(LinqServiceQuery query)
        {
            var async = Channel.BeginExecuteReader(query, null, null);

            return(Channel.EndExecuteReader(async));
        }
        public object ExecuteScalar(LinqServiceQuery query)
        {
            var async = Channel.BeginExecuteScalar(query, null, null);

            return(Channel.EndExecuteScalar(async));
        }
        public int ExecuteNonQuery(LinqServiceQuery query)
        {
            var async = Channel.BeginExecuteNonQuery(query, null, null);

            return(Channel.EndExecuteNonQuery(async));
        }
 public IAsyncResult BeginExecuteReader(LinqServiceQuery query, AsyncCallback callback, object asyncState)
 {
     return(BeginInvoke("ExecuteReader", new object[] { query }, callback, asyncState));
 }
Exemplo n.º 10
0
 public LinqServiceResult ExecuteReader(LinqServiceQuery query)
 {
     return(Channel.ExecuteReader(query));
 }
Exemplo n.º 11
0
 public object ExecuteScalar(LinqServiceQuery query)
 {
     return(Channel.ExecuteScalar(query));
 }
Exemplo n.º 12
0
 public int ExecuteNonQuery(LinqServiceQuery query)
 {
     return(Channel.ExecuteNonQuery(query));
 }
Exemplo n.º 13
0
		protected override void ValidateQuery(LinqServiceQuery query)
		{
			//base.ValidateQuery(query);
		}
Exemplo n.º 14
0
        public LinqServiceResult ExecuteReader(LinqServiceQuery query)
        {
            ValidateQuery(query);

            using (var db = CreateDataContext())
            {
                var obj = db.SetQuery(new QueryContext {
                    SqlQuery = query.Query, Parameters = query.Parameters
                });

                using (var rd = db.ExecuteReader(obj))
                {
                    var ret = new LinqServiceResult
                    {
                        QueryID    = Guid.NewGuid(),
                        FieldCount = rd.FieldCount,
                        FieldNames = new string[rd.FieldCount],
                        FieldTypes = new Type  [rd.FieldCount],
                        Data       = new List <string[]>(),
                    };

                    for (var i = 0; i < ret.FieldCount; i++)
                    {
                        ret.FieldNames[i] = rd.GetName(i);
                        ret.FieldTypes[i] = rd.GetFieldType(i);
                    }

                    var varyingTypes = new List <Type>();

                    while (rd.Read())
                    {
                        var data  = new string  [rd.FieldCount];
                        var codes = new TypeCode[rd.FieldCount];

                        for (var i = 0; i < ret.FieldCount; i++)
                        {
                            codes[i] = Type.GetTypeCode(ret.FieldTypes[i]);
                        }

                        ret.RowCount++;

                        for (var i = 0; i < ret.FieldCount; i++)
                        {
                            if (!rd.IsDBNull(i))
                            {
                                var code = codes[i];
                                var type = rd.GetFieldType(i);
                                var idx  = -1;

                                if (type != ret.FieldTypes[i])
                                {
                                    code = Type.GetTypeCode(type);
                                    idx  = varyingTypes.IndexOf(type);

                                    if (idx < 0)
                                    {
                                        varyingTypes.Add(type);
                                        idx = varyingTypes.Count - 1;
                                    }
                                }

                                switch (code)
                                {
                                case TypeCode.Decimal: data[i] = rd.GetDecimal(i).ToString(CultureInfo.InvariantCulture); break;

                                case TypeCode.Double: data[i] = rd.GetDouble(i).ToString(CultureInfo.InvariantCulture); break;

                                case TypeCode.Single: data[i] = rd.GetFloat(i).ToString(CultureInfo.InvariantCulture); break;

                                case TypeCode.DateTime: data[i] = rd.GetDateTime(i).ToString(CultureInfo.InvariantCulture); break;

                                default:
                                {
                                    if (ret.FieldTypes[i] == typeof(byte[]))
                                    {
                                        data[i] = Convert.ToBase64String((byte[])rd.GetValue(i));
                                    }
                                    else
                                    {
                                        data[i] = (rd.GetValue(i) ?? "").ToString();
                                    }

                                    break;
                                }
                                }

                                if (idx >= 0)
                                {
                                    data[i] = "\0" + (char)idx + data[i];
                                }
                            }
                        }

                        ret.Data.Add(data);
                    }

                    ret.VaryingTypes = varyingTypes.ToArray();

                    return(ret);
                }
            }
        }