Class SpecialHandler
- Namespace
- Rinku.Querying.Parameters
- Assembly
- Rinku.dll
A marker that both binds database parameters and writes SQL, for a variable that expands into several
parameters, such as a list spread into an IN clause. Subclass it and register a letter in
SpecialHandlerGetter to add your own.
public abstract class SpecialHandler : IQuerySegmentHandler
- Inheritance
-
SpecialHandler
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
A custom handler must support two calls in order. First the binding call, Use(IDbCommand, ref object?), SaveUse(IDbCommand, ref object?), or Update(IDbCommand, ref object?, object?), sets the command's parameters and may rewrite the value in place (a list, for instance, becomes its element count). Then the render pass, Handle(ref ValueStringBuilder, object), writes the SQL from that rewritten value, so it never re-reads the original input.
Fields
IsCached
Whether this handler has settled its parameter metadata, so it binds without further learning.
public bool IsCached
Field Value
SpecialHandlerGetter
The suffix letters that map to a special handler, X for list spread to start. Add a letter here
to register your own handler for every command.
public static readonly LetterMap<HandlerGetter<SpecialHandler>> SpecialHandlerGetter
Field Value
Methods
CanHandle(ref object?)
Checks whether this handler can use the supplied value. The handler may replace the value with data needed by the binding and rendering calls.
public virtual bool CanHandle(ref object? value)
Parameters
Returns
GetHandlers(int, int, Mapper, string, QuerySegment[])
Builds a command's special handlers, one per claimed variable, from its parsed template.
public static SpecialHandler[] GetHandlers(int startSpecialHandlers, int startBaseHandlers, Mapper mapper, string queryString, QuerySegment[] segments)
Parameters
startSpecialHandlersintstartBaseHandlersintmapperMapperqueryStringstringsegmentsQuerySegment[]
Returns
GetUsageEmitter(Type, MemberInfo)
The part of CanHandle(ref object?) that is cheap enough to fold into the presence check a parameter object is read with, turning a key away before its value is ever fetched. This is an optimization and carries no promise, so whatever it lets through is asked of CanHandle(ref object?) in full. Returning null keeps the member on the ordinary presence check.
public virtual Action<ILGenerator, int>? GetUsageEmitter(Type targetType, MemberInfo member)
Parameters
targetTypeTypeThe parameter object's type.
memberMemberInfoThe member holding this handler's variable.
Returns
Handle(ref ValueStringBuilder, object)
Writes the SQL for this variable, reading the value the binding pass rewrote rather than the original input.
public abstract void Handle(ref ValueStringBuilder sb, object value)
Parameters
sbValueStringBuilderThe builder the query is being assembled in.
valueobjectThe value as the binding pass left it.
ResetCache(DbParamInfo)
Returns learned provider metadata owned by this handler to the inferred strategy.
public virtual void ResetCache(DbParamInfo inferred)
Parameters
inferredDbParamInfoThe current inferred strategy supplied by the parameter services.
SaveUse(IDbCommand, ref object?)
Binds the value's parameters and rewrites value to what a later Update(IDbCommand, ref object?, object?)
needs, so reusing the same command can update in place.
public abstract bool SaveUse(IDbCommand cmd, ref object? value)
Parameters
cmdIDbCommandThe command to bind onto.
valueobjectOn the way in, the value to bind. On the way out, the state Update(IDbCommand, ref object?, object?) reuses.
Returns
Update(IDbCommand, ref object?, object?)
Updates parameters for a reused command from the value left by SaveUse(IDbCommand, ref object?).
public abstract bool Update(IDbCommand cmd, ref object? currentValue, object? newValue)
Parameters
cmdIDbCommandThe command to update.
currentValueobjectThe rewritten value from the previous SaveUse(IDbCommand, ref object?).
newValueobjectThe new value for this run.
Returns
UpdateCache<T>(T)
Settles this handler's parameter metadata from a provider reader, so later runs bind without inferring.
public abstract bool UpdateCache<T>(T infoGetter) where T : IDbParamInfoGetter
Parameters
infoGetterT
Returns
Type Parameters
T
Use(DbCommand, ref object?)
The DbCommand form of Use(IDbCommand, ref object?).
public abstract bool Use(DbCommand cmd, ref object? value)
Parameters
Returns
Use(IDbCommand, ref object?)
Binds the value's parameters for a single run, without keeping the state a later Update(IDbCommand, ref object?, object?) would need. When the value cannot report a count without being walked again, the handler rewrites it to what the render pass needs, so a lazy sequence is enumerated exactly once.
public abstract bool Use(IDbCommand cmd, ref object? value)
Parameters
cmdIDbCommandThe command to bind onto.
valueobjectOn the way in, the value to bind. On the way out, what Handle(ref ValueStringBuilder, object) reads.