Table of Contents

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

bool

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

LetterMap<HandlerGetter<SpecialHandler>>

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

value object

The value, never null on the way in, in a slot the handler may rewrite.

Returns

bool

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

startSpecialHandlers int
startBaseHandlers int
mapper Mapper
queryString string
segments QuerySegment[]

Returns

SpecialHandler[]

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

targetType Type

The parameter object's type.

member MemberInfo

The member holding this handler's variable.

Returns

Action<ILGenerator, int>

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

sb ValueStringBuilder

The builder the query is being assembled in.

value object

The 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

inferred DbParamInfo

The 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

cmd IDbCommand

The command to bind onto.

value object

On the way in, the value to bind. On the way out, the state Update(IDbCommand, ref object?, object?) reuses.

Returns

bool

true when the parameters were bound.

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

cmd IDbCommand

The command to update.

currentValue object

The rewritten value from the previous SaveUse(IDbCommand, ref object?).

newValue object

The new value for this run.

Returns

bool

true when the parameters were updated.

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

infoGetter T

Returns

bool

Type Parameters

T

Use(DbCommand, ref object?)

public abstract bool Use(DbCommand cmd, ref object? value)

Parameters

cmd DbCommand
value object

Returns

bool

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

cmd IDbCommand

The command to bind onto.

value object

On the way in, the value to bind. On the way out, what Handle(ref ValueStringBuilder, object) reads.

Returns

bool

true when the parameters were bound.