internal MsSqlCursor(MsSqlCRUDQueryExecutionContext context, SqlCommand command, SqlDataReader reader, IEnumerable <Doc> source) : base(source) { m_Context = context; m_Command = command; m_Reader = reader; }
private IEnumerable <Doc> execEnumerable(MsSqlCRUDQueryExecutionContext ctx, SqlCommand cmd, SqlDataReader reader, Schema schema, Schema.FieldDef[] toLoad, Query query) { using (cmd) using (reader) while (reader.Read()) { var row = PopulateDoc(ctx, query.ResultDocType, schema, toLoad, reader); yield return(row); } }
/// <summary> /// Reads data from reader into rowset. the reader is NOT disposed /// </summary> public static Doc PopulateDoc(MsSqlCRUDQueryExecutionContext context, Type tDoc, Schema schema, Schema.FieldDef[] toLoad, SqlDataReader reader) { var store = context.DataStore; var row = Doc.MakeDoc(schema, tDoc); for (int i = 0; i < reader.FieldCount; i++) { var fdef = toLoad[i]; if (fdef == null) { continue; } var val = reader.GetValue(i); if (val == null || val is DBNull) { row[fdef.Order] = null; continue; } if (fdef.NonNullableType == typeof(bool)) { if (store.StringBool) { var bval = (val is bool) ? (bool)val : val.ToString().EqualsIgnoreCase(store.StringForTrue); row[fdef.Order] = bval; } else { row[fdef.Order] = val.AsNullableBool(); } } else if (fdef.NonNullableType == typeof(DateTime)) { var dtVal = val.AsNullableDateTime(); row[fdef.Order] = dtVal.HasValue ? DateTime.SpecifyKind(dtVal.Value, store.DateTimeKind) : (DateTime?)null; } else { row[fdef.Order] = val; } } return(row); }
/// <summary> /// Performs CRUD load. Override to do custom Query interpretation /// </summary> protected internal async virtual Task <Cursor> DoOpenCursorAsync(SqlConnection cnn, SqlTransaction transaction, Query query) { var context = new MsSqlCRUDQueryExecutionContext(this, cnn, transaction); var handler = QueryResolver.Resolve(query); try { return(await handler.OpenCursorAsync(context, query).ConfigureAwait(false)); } catch (Exception error) { throw new MsSqlDataAccessException( StringConsts.OPEN_CURSOR_ERROR + error.ToMessageWithType(), error, KeyViolationKind.Unspecified, CRUDGenerator.KeyViolationName(error)); } }
/// <summary> /// Reads data from reader into rowset. the reader is NOT disposed /// </summary> public static Rowset PopulateRowset(MsSqlCRUDQueryExecutionContext context, SqlDataReader reader, string target, Query query, QuerySource qSource, bool oneDoc) { Schema.FieldDef[] toLoad; Schema schema = GetSchemaForQuery(target, query, reader, qSource, out toLoad); var store = context.DataStore; var result = new Rowset(schema); while (reader.Read()) { var row = PopulateDoc(context, query.ResultDocType, schema, toLoad, reader); result.Add(row); if (oneDoc) { break; } } return(result); }