18 using System.Collections.Generic;
24 namespace Deveel.Data.Sql.Expressions {
33 if (expression == null) {
34 writer.Write((byte)0);
38 var expType = expression.GetType();
39 var expTypeName = expType.FullName;
42 if (serializer == null)
43 throw new InvalidOperationException(String.Format(
"Cannot find a valid binary serializer for expression of type '{0}'", expType));
45 writer.Write((byte)1);
46 writer.Write(expTypeName);
52 var status = reader.ReadByte();
56 var typeName = reader.ReadString();
58 var type =
Type.GetType(typeName,
true);
60 var type =
Type.GetType(typeName,
true,
true);
64 if (serializer == null)
65 throw new InvalidOperationException(String.Format(
"Cannot find a valid binary serializer for expression of type '{0}'", type));
70 #region SqlExpressionSerializerResolver
73 protected override void Init() {
74 Register<SqlConstantExpression, SqlConstantExpressionSerializer>();
75 Register<SqlReferenceExpression, SqlReferenceExpressionSerializer>();
76 Register<SqlVariableReferenceExpression, SqlVariableReferenceExpressionSerializer>();
77 Register<SqlAssignExpression, SqlAssignExpressionSerializer>();
78 Register<SqlFunctionCallExpression, SqlFunctionCallExpressionSerializer>();
79 Register<SqlUnaryExpression, SqlUnaryExpressionSerializer>();
80 Register<SqlBinaryExpression, SqlBinaryExpressionSerializer>();
81 Register<SqlQueryExpression, SqlQueryExpressionSerializer>();
82 Register<SqlConditionalExpression, SqlConditionalExpressionSerializer>();
83 Register<SqlTupleExpression, SqlTupleExpressionSerializer>();
89 #region SqlExpressionSerializer
97 var expCount = expressions == null ? 0 : expressions.Length;
99 writer.Write(expCount);
101 if (expressions != null) {
102 for (
int i = 0; i < expCount; i++) {
103 WriteExpression(expressions[i], writer);
113 var expCount = reader.ReadInt32();
116 for (
int i = 0; i < expCount; i++) {
117 exps[i] = ReadExpression(reader);
126 #region SqlConstantExpressionSerializer
141 #region SqlReferenceExpressionSerializer
156 #region SqlVariableReferenceExpressionSerializer
164 var varName = reader.ReadString();
171 #region SqlAssignExpressionSerializer
189 #region SqlFunctionCallExpressionSerializer
194 WriteExpressions(expression.
Arguments, writer);
200 var args = ReadExpressions(reader);
208 #region SqlUnaryExpressionSerializer
213 WriteExpression(expression.
Operand, writer);
218 var exp = ReadExpression(reader);
226 #region SqlBinaryExpressionSerializer
230 WriteExpression(expression.
Left, writer);
232 WriteExpression(expression.
Right, writer);
236 var left = ReadExpression(reader);
238 var right = ReadExpression(reader);
246 #region SqlQueryExpressionSerializer
252 writer.Write(expression.
Distinct ? (byte)1 : (byte)0);
255 writer.Write((byte) 1);
258 writer.Write((byte)0);
262 writer.Write((byte) 1);
265 writer.Write((byte)0);
268 if (expression.
GroupBy != null) {
269 throw new NotImplementedException();
273 writer.Write((byte) 1);
276 writer.Write((byte)0);
280 writer.Write((byte) 1);
283 writer.Write((byte)0);
290 var list = selectColumns == null ?
new List<SelectColumn>() : selectColumns.ToList();
291 writer.Write(list.Count);
292 for (
int i = 0; i < list.Count; i++) {
293 var column = list[i];
299 var selectColumns = DeserializeSelectColumns(reader);
303 var isDistinct = reader.ReadByte() == 1;
304 queryExp.Distinct = isDistinct;
306 var hasFrom = reader.ReadByte() == 1;
308 queryExp.FromClause =
FromClause.Deserialize(reader);
311 var hasWhere = reader.ReadByte() == 1;
315 var hasGroupMax = reader.ReadByte() == 1;
319 var hasHaving = reader.ReadByte() == 1;
327 var count = reader.ReadInt32();
329 for (
int i = 0; i < count; i++) {
339 #region SqlConditionalExpressionSerializer
349 var testExp = ReadExpression(reader);
350 var trueExp = ReadExpression(reader);
351 var falseExp = ReadExpression(reader);
359 #region SqlTupleExpressionSerializer
367 var exps = ReadExpressions(reader);
static void Serialize(SqlExpression expression, BinaryWriter writer)
override SqlExpressionType ExpressionType
override SqlUnaryExpression Deserialize(BinaryReader reader)
IEnumerable< SelectColumn > SelectColumns
ObjectName ReferenceName
Gets the name of the object referenced by the expression.
SqlExpression Operand
Gets the operand expression that is computed.
SqlExpression ValueExpression
An expression that references an object within a context.
Handles expressions computed against an unary operator.
static SqlExpression ReadExpression(BinaryReader reader)
override void Serialize(SqlQueryExpression expression, BinaryWriter writer)
override SqlTupleExpression Deserialize(BinaryReader reader)
static SqlExpression[] ReadExpressions(BinaryReader reader)
override void Serialize(SqlConstantExpression expression, BinaryWriter writer)
static void Serialize(ObjectName objectName, Stream stream)
override void Serialize(SqlAssignExpression expression, BinaryWriter writer)
override void Serialize(SqlConditionalExpression expression, BinaryWriter writer)
static SqlTupleExpression Tuple(SqlExpression[] expressions)
static SqlVariableReferenceExpression VariableReference(string varName)
Describes the name of an object within a database.
static void Serialize(DataObject obj, BinaryWriter writer)
static ObjectName Deserialize(Stream stream)
static SqlAssignExpression Assign(SqlExpression reference, SqlExpression valueExpression)
IEnumerable< SqlExpression > GroupBy
static SqlConditionalExpression Conditional(SqlExpression testExpression, SqlExpression ifTrue)
static void Serialize(SqlExpression expression, BinaryWriter writer)
SqlExpressionType
All the possible type of SqlExpression supported
static SqlExpressionSerializers()
static void WriteExpressions(SqlExpression[] expressions, BinaryWriter writer)
SqlExpression TestExpression
DataObject Value
Gets the constant value of the expression.
SqlExpression FalseExpression
override void Serialize(SqlFunctionCallExpression expression, BinaryWriter writer)
A user-defined TYPE that holds complex objects in a database column.
static SqlExpression Deserialize(BinaryReader reader)
A container for the FROM clause of a select statement.
override SqlConditionalExpression Deserialize(BinaryReader reader)
override SqlReferenceExpression Deserialize(BinaryReader reader)
static SqlExpression Deserialize(BinaryReader reader)
SqlExpression[] Arguments
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
override void Serialize(SqlReferenceExpression expression, BinaryWriter writer)
Represents a column selected to be in the output of a select statement.
override void Serialize(SqlBinaryExpression expression, BinaryWriter writer)
void Serialize(object obj, BinaryWriter writer)
override SqlQueryExpression Deserialize(BinaryReader reader)
An expression that holds a constant value.
override SqlVariableReferenceExpression Deserialize(BinaryReader reader)
override SqlAssignExpression Deserialize(BinaryReader reader)
static SqlReferenceExpression Reference(ObjectName objectName)
SqlExpression TrueExpression
override void Serialize(SqlTupleExpression expression, BinaryWriter writer)
static DataObject Deserialize(BinaryReader reader, ITypeResolver resolver)
override SqlExpressionType ExpressionType
void SerializeSelectColumns(IEnumerable< SelectColumn > selectColumns, BinaryWriter writer)
SqlExpression[] Expressions
static SqlBinaryExpression Binary(SqlExpression left, SqlExpressionType expressionType, SqlExpression right)
IEnumerable< SelectColumn > DeserializeSelectColumns(BinaryReader reader)
override SqlBinaryExpression Deserialize(BinaryReader reader)
override SqlFunctionCallExpression Deserialize(BinaryReader reader)
Defines the base class for instances that represent SQL expression tree nodes.
override void Serialize(SqlVariableReferenceExpression expression, BinaryWriter writer)
static SqlConstantExpression Constant(object value)
static SqlFunctionCallExpression FunctionCall(ObjectName functionName)
object Deserialize(BinaryReader reader)
override void Serialize(SqlUnaryExpression expression, BinaryWriter writer)
SqlExpression HavingExpression
static void WriteExpression(SqlExpression expression, BinaryWriter writer)
SqlExpression WhereExpression
static SqlUnaryExpression Unary(SqlExpressionType expressionType, SqlExpression operand)
SqlExpression ReferenceExpression
override SqlConstantExpression Deserialize(BinaryReader reader)