2 using System.Collections.Generic;
16 namespace Deveel.Data.Linq {
22 this.context = context;
25 public override object Convert(
object value, Type type) {
27 return TypeHelper.GetDefault(type);
30 type = TypeHelper.GetNonNullableType(type);
31 var vtype = value.GetType();
35 if (vtype == typeof (
string))
36 return Enum.Parse(type, (
string) value);
38 Type utype = Enum.GetUnderlyingType(type);
40 value =
System.Convert.ChangeType(value, utype);
42 return Enum.ToObject(type, value);
45 return System.Convert.ChangeType(value, type);
52 var query =
new SqlQuery(command.CommandText);
53 SetParameters(command, query, paramValues);
58 if (command.Parameters.Count > 0 && query.
Parameters.Count == 0) {
59 for (
int i = 0, n = command.Parameters.Count; i < n; i++) {
60 AddParameter(query, command.
Parameters[i], paramValues != null ? paramValues[i] : null);
62 }
else if (paramValues != null) {
64 for (
int i = 0, n = queryParams.Count; i < n; i++) {
65 var p = queryParams[i];
75 var sqlType = GetSqlType(queryParameter.Type);
76 var param =
new Sql.QueryParameter(queryParameter.
Name, sqlType, (
ISqlObject)value);
82 throw new NotImplementedException();
85 public override IEnumerable<T> Execute<T>(QueryCommand command, Func<FieldReader, T> fnProjector, MappingEntity entity,
object[] paramValues) {
86 var query = GetQuery(command, paramValues);
87 var queryResult = context.ExecuteQuery(query);
89 return Project(queryResult[0], fnProjector, entity);
92 private IEnumerable<T> Project<T>(
ITable result, Func<FieldReader, T> fnProjector, MappingEntity entity) {
94 while (reader.NextRow()) {
95 yield
return fnProjector(reader);
99 public override IEnumerable<int>
ExecuteBatch(QueryCommand query, IEnumerable<
object[]> paramSets,
int batchSize,
bool stream) {
100 throw new NotImplementedException();
103 public override IEnumerable<T> ExecuteBatch<T>(QueryCommand query, IEnumerable<object[]> paramSets, Func<FieldReader, T> fnProjector, MappingEntity entity,
104 int batchSize,
bool stream) {
105 throw new NotImplementedException();
108 public override IEnumerable<T> ExecuteDeferred<T>(QueryCommand command, Func<FieldReader, T> fnProjector, MappingEntity entity,
object[] paramValues) {
109 var query = GetQuery(command, paramValues);
110 var queryResult = context.ExecuteQuery(query);
112 return Project(queryResult[0], fnProjector, entity);
116 var sqlQuery = GetQuery(query, paramValues);
117 var result = context.ExecuteQuery(sqlQuery);
118 rowsAffected = result[0].RowCount;
122 public override int RowsAffected {
123 get {
return rowsAffected; }
126 #region TableFieldReader
130 private int rowOffset = -1;
139 if (++rowOffset >= table.RowCount)
142 row = table.GetRow(rowOffset);
147 var sqlType = row[ordinal].Type;
148 return sqlType.GetRuntimeType();
152 return row[ordinal].IsNull;
155 protected override T GetValue<T>(
int ordinal) {
156 var value = row[ordinal];
157 return (T) value.Type.ConvertTo(value.Value, typeof (T));
160 protected override byte
GetByte(
int ordinal) {
161 return GetValue<byte>(ordinal);
164 protected override char GetChar(
int ordinal) {
165 return GetValue<char>(ordinal);
169 return GetValue<DateTime>(ordinal);
173 throw new NotImplementedException();
177 return GetValue<double>(ordinal);
181 return GetValue<float>(ordinal);
184 protected override Guid
GetGuid(
int ordinal) {
185 throw new NotImplementedException();
189 return GetValue<short>(ordinal);
193 return GetValue<int>(ordinal);
197 return GetValue<long>(ordinal);
201 return GetValue<string>(ordinal);
204 protected override int FieldCount {
205 get {
return table.TableInfo.ColumnCount; }
override int ExecuteCommand(QueryCommand query, object[] paramValues)
override object Convert(object value, Type type)
override char GetChar(int ordinal)
Defines the contract to access the data contained into a table of a database.
override Guid GetGuid(int ordinal)
override decimal GetDecimal(int ordinal)
override DateTime GetDateTime(int ordinal)
override int GetInt32(int ordinal)
A single row in a table of a database.
TableFieldReader(ITable table)
override bool IsDBNull(int ordinal)
static readonly SqlNull Value
Defines the contract for a valid SQL Object
A user-defined TYPE that holds complex objects in a database column.
override float GetSingle(int ordinal)
override short GetInt16(int ordinal)
void SetParameters(QueryCommand command, SqlQuery query, object[] paramValues)
DeveelDbExecutor(IQuery context)
SqlQuery GetQuery(QueryCommand command, object[] paramValues)
Defines the properties of a specific SQL Type and handles the values compatible.
override IEnumerable< int > ExecuteBatch(QueryCommand query, IEnumerable< object[]> paramSets, int batchSize, bool stream)
override long GetInt64(int ordinal)
override string GetString(int ordinal)
void AddParameter(SqlQuery query, QueryParameter queryParameter, object value)
override Type GetFieldType(int ordinal)
override byte GetByte(int ordinal)
override double GetDouble(int ordinal)
ICollection< QueryParameter > Parameters
SqlType GetSqlType(Type type)