Ejemplo n.º 1
0
        public IList <TItem> List <TItem>(IEnumerable <QueryData> queries)
        {
            if (queries == null)
            {
                throw new ArgumentNullException(nameof(queries));
            }

            if (this.Options.Schemas == null)
            {
                throw new InvalidOperationException("No schema store found.");
            }

            ResultAdapter <TItem> adapter = new ResultAdapter <TItem>(this.Options.Schemas);

            using SyncSession connection = new SyncSession(this.Options);

            foreach (QueryData queryData in queries.NotNull())
            {
                Query builder = new Query(queryData);

                if (string.IsNullOrWhiteSpace(queryData.QueryText))
                {
                    continue;
                }

                foreach (IDataReader dataReader in connection.Execute(builder))
                {
                    adapter.AddResult(dataReader);
                }
            }

            return(adapter.ToList());
        }
Ejemplo n.º 2
0
        public void Execute(IEnumerable <CommandData> commands)
        {
            FieldMap fieldMap = new FieldMap();

            using SyncSession session = new SyncSession(this.Options);

            foreach (CommandData commandData in commands.NotNull())
            {
                Command command = new Command(commandData, fieldMap);

                if (string.IsNullOrWhiteSpace(commandData.CommandText))
                {
                    continue;
                }

                foreach (IDataReader reader in session.Execute(command))
                {
                    TableIdentity      tableInfo = TableIdentity.FromRecord(reader);
                    FieldData[]        fields    = command.GetHeading(tableInfo);
                    MetadataIdentity[] metadata  = fields.Select(f => f?.Attribute).ToArray();

                    var binder = FuncCache.GetFieldDataBinder(metadata, tableInfo);

                    if (reader.Read())
                    {
                        binder(reader, fields);
                    }
                }
            }

            foreach (FieldData fieldData in fieldMap)
            {
                fieldData.Bind();
            }
        }
Ejemplo n.º 3
0
        public IEnumerable <QueryReader> Enumerate(IEnumerable <QueryData> queries)
        {
            if (queries == null)
            {
                throw new ArgumentNullException(nameof(queries));
            }

            if (this.Options.Schemas == null)
            {
                throw new InvalidOperationException("No schema builder found.");
            }

            using SyncSession connection = new SyncSession(this.Options);

            foreach (QueryData queryData in queries.NotNull())
            {
                Query query = new Query(queryData);

                if (string.IsNullOrWhiteSpace(queryData.QueryText))
                {
                    continue;
                }

                foreach (IDataReader reader in connection.Execute(query))
                {
                    yield return(new QueryReader(reader, this.Options.Schemas));
                }
            }
        }
Ejemplo n.º 4
0
        public void Test_ConnectionManagement_WithSyncSession()
        {
            var connection = new SqliteConnection(DatabaseHelper.TestDbConnectionString);

            QueryOptions options = new QueryOptions()
            {
                ConnectionFactory = () => connection,
                Schemas           = DatabaseHelper.Default.Schemas,
            };

            using (var ado = new SyncSession(options))
            {
                foreach (var r in ado.Execute(new SqlOperation("SELECT 12; SELECT 12")))
                {
                    r.Read().ShouldBeTrue();
                    r.GetInt32(0).ShouldBe(12);
                    r.Read().ShouldBeFalse();
                }
            }

            connection.State.ShouldBe(ConnectionState.Closed);
        }
Ejemplo n.º 5
0
        public void Test_Session_Connection()
        {
            var connection = new SqliteConnection(DatabaseHelper.TestDbConnectionString);

            QueryOptions options = new QueryOptions()
            {
                ConnectionFactory = () => connection,
                Store             = DatabaseHelper.Default.Store,
            };

            using (var ado = new SyncSession(options.ConnectionFactory, options.Filters))
            {
                foreach (var r in ado.Execute(new MockBatch("SELECT 12; SELECT 12")))
                {
                    r.Read().ShouldBeTrue();
                    r.GetInt32(0).ShouldBe(12);
                    r.Read().ShouldBeFalse();
                }
            }

            connection.State.ShouldBe(ConnectionState.Closed);
        }