コード例 #1
0
 internal MySqlCursor(MySqlCRUDQueryExecutionContext context,
                      MySqlCommand command,
                      MySqlDataReader reader,
                      IEnumerable <Doc> source) : base(source)
 {
     m_Context = context;
     m_Command = command;
     m_Reader  = reader;
 }
コード例 #2
0
 private IEnumerable <Doc> execEnumerable(MySqlCRUDQueryExecutionContext ctx, MySqlCommand cmd, MySqlDataReader 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);
             }
 }
コード例 #3
0
        /// <summary>
        /// Reads data from reader into rowset. the reader is NOT disposed
        /// </summary>
        public static Doc PopulateDoc(MySqlCRUDQueryExecutionContext context, Type tDoc, Schema schema, Schema.FieldDef[] toLoad, MySqlDataReader 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);
        }
コード例 #4
0
        /// <summary>
        ///  Performs CRUD load. Override to do custom Query interpretation
        /// </summary>
        protected internal virtual Cursor DoOpenCursor(MySqlConnection cnn, MySqlTransaction transaction, Query query)
        {
            var context = new MySqlCRUDQueryExecutionContext(this, cnn, transaction);
            var handler = QueryResolver.Resolve(query);

            try
            {
                return(handler.OpenCursor(context, query));
            }
            catch (Exception error)
            {
                throw new MySqlDataAccessException(
                          StringConsts.OPEN_CURSOR_ERROR + error.ToMessageWithType(),
                          error,
                          KeyViolationKind.Unspecified,
                          CRUDGenerator.KeyViolationName(error));
            }
        }
コード例 #5
0
        /// <summary>
        /// Reads data from reader into rowset. the reader is NOT disposed
        /// </summary>
        public static Rowset PopulateRowset(MySqlCRUDQueryExecutionContext context, MySqlDataReader 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);
        }