Esempio n. 1
0
 internal OracleCursor(OracleCRUDQueryExecutionContext context,
                       OracleCommand command,
                       OracleDataReader reader,
                       IEnumerable <Doc> source) : base(source)
 {
     m_Context = context;
     m_Command = command;
     m_Reader  = reader;
 }
 private IEnumerable <Doc> execEnumerable(OracleCRUDQueryExecutionContext ctx, OracleCommand cmd, OracleDataReader 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(OracleCRUDQueryExecutionContext context, Type tDoc, Schema schema, Schema.FieldDef[] toLoad, OracleDataReader 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);
        }
Esempio n. 4
0
        /// <summary>
        ///  Performs CRUD load. Override to do custom Query interpretation
        /// </summary>
        protected internal async virtual Task <Cursor> DoOpenCursorAsync(OracleConnection cnn, OracleTransaction transaction, Query query)
        {
            var context = new OracleCRUDQueryExecutionContext(this, cnn, transaction);
            var handler = QueryResolver.Resolve(query);

            try
            {
                return(await handler.OpenCursorAsync(context, query).ConfigureAwait(false));
            }
            catch (Exception error)
            {
                throw new OracleDataAccessException(
                          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(OracleCRUDQueryExecutionContext context, OracleDataReader 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);
        }