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 AdoConnection connection = new AdoConnection(this.Options); foreach (QueryData queryData in queries.NotNull()) { AdoHelper helper = new AdoHelper(queryData); if (string.IsNullOrWhiteSpace(queryData.QueryText)) { continue; } foreach (IDataReader reader in connection.Execute(helper)) { yield return(new QueryReader(reader, this.Options.Schemas)); } } }
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 (AdoConnection connection = new AdoConnection(this.Options)) { foreach (QueryData queryData in queries.NotNull()) { AdoHelper helper = new AdoHelper(queryData); if (string.IsNullOrWhiteSpace(queryData.QueryText)) { continue; } foreach (IDataReader dataReader in connection.Execute(helper)) { adapter.AddResult(dataReader); } } } return(adapter.ToList()); }
public async IAsyncEnumerable <QueryReader> EnumerateAsync(IEnumerable <QueryData> queries, [EnumeratorCancellation] CancellationToken cancellationToken = default) { if (queries == null) { throw new ArgumentNullException(nameof(queries)); } if (this.Options.Schemas == null) { throw new InvalidOperationException("No schema builder found."); } #if NETSTANDARD2_1 await #endif using AdoConnection connection = new AdoConnection(this.Options); foreach (QueryData queryData in queries.NotNull()) { AdoHelper helper = new AdoHelper(queryData); if (string.IsNullOrWhiteSpace(queryData.QueryText)) { continue; } await foreach (DbDataReader dataReader in connection.ExecuteAsync(helper, cancellationToken)) { yield return(new QueryReader(dataReader, this.Options.Schemas)); } } }
static void Main(string[] args) { Console.WriteLine("hello"); DatabaseConnection conn = new AdoConnection(); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(conn); //Console.WriteLine("Found database " + database + " of type " + database.GetType()); LockService lockService = LockService.getInstance(database); lockService.waitForLock(); Console.Read(); }
public IEnumerable <Cidade> ObterTodasCidadesPor(Guid idEstado) { var listaDeCidade = new List <Cidade>(); var sql = @"select IdCidade, Nome, EstadoId from TB_CIDADE where EstadoId = '" + idEstado + "'"; using (IDataReader reader = AdoConnection.ExecuteReader(CommandType.Text, sql)) { while (reader.Read()) { var cidade = new Cidade(reader["Nome"].ToString(), Guid.Parse(reader["EstadoId"].ToString()), Guid.Parse(reader["IdCidade"].ToString())); listaDeCidade.Add(cidade); } } return(listaDeCidade); }
public async Task <IList <TItem> > ListAsync <TItem>(IEnumerable <QueryData> queries, CancellationToken cancellationToken = default) { if (queries == null) { throw new ArgumentNullException(nameof(queries)); } if (this.Options.Schemas == null) { throw new InvalidOperationException("No schema builder found."); } ResultAdapter <TItem> adapter = new ResultAdapter <TItem>(this.Options.Schemas); #if NETSTANDARD2_1 await #endif using AdoConnection connection = new AdoConnection(this.Options); foreach (QueryData queryData in queries.NotNull()) { AdoHelper helper = new AdoHelper(queryData); if (string.IsNullOrWhiteSpace(queryData.QueryText)) { continue; } #if NETSTANDARD2_0 await connection.ExecuteAsync(helper, async (r) => { await adapter.AddResultAsync(r, cancellationToken).ConfigureAwait(false); }, cancellationToken).ConfigureAwait(false); #elif NETSTANDARD2_1 await foreach (DbDataReader dataReader in connection.ExecuteAsync(helper, cancellationToken)) { await adapter.AddResultAsync(dataReader, cancellationToken); } #endif } return(adapter.ToList()); }
public IEnumerable <PessoaFisica> ObterTodosPorFiltro(string cpf, string nome) { var listaDePessoasFisica = new List <PessoaFisica>(); var sql = @"Select p.IdPessoa, pf.Nome, pf.CPF_Codigo, pf.DataDeNascimento, pf.Sexo, pf.RG, pf.TituloEleitor, pf.NaturalidadeId, pf.Nacionalidade, pf.EstadoCivil, p.Status from TB_PESSOA p inner join TB_PESSOA_FISICA pf on p.IdPessoa = pf.IdPessoa where 1=1"; if (!string.IsNullOrEmpty(cpf)) { sql += "and pf.CPF_Codigo = " + TextoHelper.GetNumeros(cpf); } if (!string.IsNullOrEmpty(nome)) { sql += "and pf.Nome Like '%" + nome + "%'"; } using (IDataReader reader = AdoConnection.ExecuteReader(CommandType.Text, sql)) { while (reader.Read()) { var pessoaFisica = new PessoaFisica(reader["Nome"].ToString(), reader["CPF_Codigo"].ToString(), reader["RG"].ToString(), reader["TituloEleitor"].ToString(), Convert.ToDateTime(reader["DataDeNascimento"].ToString()), Guid.Parse(reader["NaturalidadeId"].ToString()), reader["Nacionalidade"].ToString(), (ESexo)(Convert.ToInt32(reader["Sexo"].ToString())), (EEstadoCivil)(Convert.ToInt32(reader["EstadoCivil"].ToString())), reader["Status"].ToString(), Guid.Parse(reader["IdPessoa"].ToString())); listaDePessoasFisica.Add(pessoaFisica); } } return(listaDePessoasFisica); }
public void Execute(IEnumerable <CommandData> commands) { FieldMap fieldMap = new FieldMap(); using (AdoConnection connection = new AdoConnection(this.Options)) { foreach (CommandData commandData in commands.NotNull()) { AdoHelper helper = new AdoHelper(commandData, fieldMap); if (string.IsNullOrWhiteSpace(commandData.CommandText)) { continue; } foreach (IDataReader reader in connection.Execute(helper)) { TableIdentity tableInfo = TableIdentity.FromRecord(reader); FieldData[] fields = helper.GetHeading(tableInfo); MetadataIdentity[] metadata = fields.Select(f => f?.Attribute).ToArray(); var fun = FuncCache.GetFieldDataBinder(metadata, tableInfo); if (reader.Read()) { fun(reader, fields); } } } } foreach (FieldData fieldData in fieldMap) { fieldData.Bind(); } }
/// <summary> /// 创建实例。 /// </summary> /// <param name="connection">连接对象。</param> public PostgreSQLTransaction(AdoConnection connection) : base(connection) { }
public void closeTest() { DatabaseConnection target = new AdoConnection(); target.close(); }
public void commitTest() { DatabaseConnection target = new AdoConnection(); target.commit(); }
public void rollbackTest() { DatabaseConnection target = new AdoConnection(); target.rollback(); }
public void CsConnectionConstructorTest() { AdoConnection target = new AdoConnection(); Assert.IsNotNull(target.GetUnderlyingConnection()); }
public void getProductNameTest() { DatabaseConnection target = new AdoConnection(); Assert.AreEqual("asdf", target.getDatabaseProductName()); }
public void getURLTest() { DatabaseConnection target = new AdoConnection(); Assert.AreEqual("Provider=SQLOLEDB;Data Source=localhost\\SQL2005;Initial Catalog=liquibase;User Id=liquibase;", target.getURL()); }