Example #1
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);

            return(handler.OpenCursor(context, query));
        }
Example #2
0
 internal MySQLCursor(MySQLCRUDQueryExecutionContext context,
                      MySqlCommand command,
                      MySqlDataReader reader,
                      IEnumerable <Row> source) : base(source)
 {
     m_Context = context;
     m_Command = command;
     m_Reader  = reader;
 }
Example #3
0
 internal MySQLCursor(MySQLCRUDQueryExecutionContext context, 
     MySqlCommand command,
     MySqlDataReader reader,
     IEnumerable<Row> source)
     : base(source)
 {
     m_Context = context;
       m_Command = command;
       m_Reader = reader;
 }
 private IEnumerable <Row> execEnumerable(MySQLCRUDQueryExecutionContext ctx, MySqlCommand cmd, MySqlDataReader reader, Schema schema, Schema.FieldDef[] toLoad, Query query)
 {
     using (cmd)
         using (reader)
             while (reader.Read())
             {
                 var row = PopulateRow(ctx, query.ResultRowType, schema, toLoad, reader);
                 yield return(row);
             }
 }
Example #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 oneRow)
        {
            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 = Row.MakeRow(schema, query.ResultRowType);

                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
                    {
                        row[fdef.Order] = val;
                    }
                }

                result.Add(row);
                if (oneRow)
                {
                    break;
                }
            }

            return(result);
        }
Example #6
0
        /// <summary>
        /// Reads data from reader into rowset. the reader is NOT disposed
        /// </summary>
        public static Row PopulateRow(MySQLCRUDQueryExecutionContext context, Type tRow, Schema schema, Schema.FieldDef[] toLoad, MySqlDataReader reader)
        {
            var store = context.DataStore;
            var row   = Row.MakeRow(schema, tRow);

            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);
        }
Example #7
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));
            }
        }
        /// <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 oneRow)
        {
            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 = PopulateRow(context, query.ResultRowType, schema, toLoad, reader);

                result.Add(row);
                if (oneRow)
                {
                    break;
                }
            }

            return(result);
        }
 private IEnumerable<Row> execEnumerable(MySQLCRUDQueryExecutionContext ctx, MySqlCommand cmd, MySqlDataReader reader, Schema schema, Schema.FieldDef[] toLoad, Query query)
 {
     using(cmd)
                  using(reader)
                   while(reader.Read())
                   {
                     var row = PopulateRow(ctx, query.ResultRowType, schema, toLoad, reader);
                     yield return row;
                   }
 }
        /// <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 oneRow)
        {
            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 = PopulateRow(context, query.ResultRowType, schema, toLoad, reader);

                result.Add( row );
                if (oneRow) break;
              }

              return result;
        }
        /// <summary>
        /// Reads data from reader into rowset. the reader is NOT disposed
        /// </summary>
        public static Row PopulateRow(MySQLCRUDQueryExecutionContext context, Type tRow, Schema schema, Schema.FieldDef[] toLoad, MySqlDataReader reader)
        {
            var store= context.DataStore;
              var row = Row.MakeRow(schema, tRow);

              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
                      row[fdef.Order] = val;
              }

              return row;
        }
Example #12
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));
     }
 }