DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
ProcedureInfo.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Linq;
19 
20 using Deveel.Data;
21 using Deveel.Data.Sql;
23 
24 namespace Deveel.Data.Routines {
25  public sealed class ProcedureInfo : RoutineInfo {
26  public ProcedureInfo(ObjectName routineName)
27  : this(routineName, ProcedureType.Static) {
28  }
29 
30  public ProcedureInfo(ObjectName routineName, ProcedureType procedureType)
31  : this(routineName, procedureType, new RoutineParameter[0]) {
32  }
33 
34  public ProcedureInfo(ObjectName routineName, RoutineParameter[] parameters)
35  : this(routineName, ProcedureType.Static, parameters) {
36  }
37 
38  public ProcedureInfo(ObjectName routineName, ProcedureType procedureType, RoutineParameter[] parameters)
39  : base(routineName, parameters) {
40  ProcedureType = procedureType;
41  }
42 
43  public override RoutineType RoutineType {
44  get { return RoutineType.Procedure; }
45  }
46 
47  public ProcedureType ProcedureType { get; private set; }
48 
49  internal override bool MatchesInvoke(Invoke invoke, IQuery query) {
50  if (invoke == null)
51  return false;
52 
53  bool ignoreCase = true;
54  if (query != null)
55  ignoreCase = query.IgnoreIdentifiersCase();
56 
57  if (!RoutineName.Equals(invoke.RoutineName, ignoreCase))
58  return false;
59 
60 
61  var inputParams = Parameters.Where(parameter => parameter.IsInput).ToList();
62  if (invoke.Arguments.Length != inputParams.Count)
63  return false;
64 
65  for (int i = 0; i < invoke.Arguments.Length; i++) {
66  // TODO: support variable evaluation here? or evaluate parameters before reaching here?
67  if (!invoke.Arguments[i].IsConstant())
68  return false;
69 
70  var argType = invoke.Arguments[i].ReturnType(query, null);
71  var paramType = Parameters[i].Type;
72 
73  // TODO: verify if this is assignable (castable) ...
74  if (!paramType.IsComparable(argType))
75  return false;
76  }
77 
78  return true;
79  }
80  }
81 }
SqlExpression[] Arguments
Gets an array of arguments to be passed to the invoked routine.
Definition: Invoke.cs:63
Describes the name of an object within a database.
Definition: ObjectName.cs:44
A type that represents a static function.
RoutineType
The type of routine program.
Definition: RoutineType.cs:23
ProcedureInfo(ObjectName routineName, ProcedureType procedureType)
ProcedureInfo(ObjectName routineName)
The information about the invocation of a routine, including the full name and arguments (as SqlExpre...
Definition: Invoke.cs:30
override bool MatchesInvoke(Invoke invoke, IQuery query)
ObjectName RoutineName
Gets the fully qualified name of the routine to invoke.
Definition: Invoke.cs:58
Defines the metadata for a routine that are used to resolve within a context.
Definition: RoutineInfo.cs:28
ProcedureType
The form of a database stored PROCEDURE.
ProcedureInfo(ObjectName routineName, ProcedureType procedureType, RoutineParameter[] parameters)
ProcedureInfo(ObjectName routineName, RoutineParameter[] parameters)