public async Task LargeCursor_ExplicitFetch() { int FetchSize = 20000; int count = 0; int batchCount = 0; var db = new SPTestsDatabase(); using (var conn = await db.OpenConnectionAsync()) { // cursors in PostgreSQL must share a transaction (not just a connection, as in Oracle) using (var trans = conn.BeginTransaction()) { var result = await db.ExecuteProcedureAsync("lump", returnParams: new { cursor = new Cursor() }, connection: conn); while(true) { var fetchTest = await db.QueryAsync($@"FETCH {FetchSize} FROM ""{result.cursor.CursorRef}""", connection: conn); int subcount = 0; await fetchTest.ForEachAsync(item => { count++; subcount++; // there is no ORDER BY (it would not be sensible on such a huge data set) - this only sometimes works... //Assert.AreEqual(count, item.id); }); if(subcount == 0) { break; } batchCount++; } await db.ExecuteAsync($@"CLOSE ""{result.cursor.CursorRef}""", connection: conn); trans.Commit(); } } Assert.AreEqual((LargeCursorSize + FetchSize - 1) / FetchSize, batchCount); Assert.AreEqual(LargeCursorSize, count); }
public async Task PassingCursorInputParameter(bool explicitConnection) { var db = new SPTestsDatabase(ProviderName, explicitConnection); if (explicitConnection) { MightyTests.ConnectionStringUtils.CheckConnectionStringRequiredForOpenConnectionAsync(db); } // To share cursors between commands in Oracle the commands must use the same connection using (var conn = await db.OpenConnectionAsync( explicitConnection ? MightyTests.ConnectionStringUtils.GetConnectionString(TestConstants.ReadWriteTestConnection, ProviderName) : null)) { var res1 = await db.ExecuteWithParamsAsync("begin open :p_rc for select * from emp where deptno = 10; end;", outParams : new { p_rc = new Cursor() }, connection : conn); Assert.AreEqual(typeof(Cursor), res1.p_rc.GetType()); Assert.AreEqual("OracleRefCursor", ((Cursor)res1.p_rc).CursorRef.GetType().Name); await db.ExecuteAsync("delete from processing_result", connection : conn); // oracle demo code takes the input cursor and writes the results to `processing_result` table var res2 = await db.ExecuteProcedureAsync("cursor_in_out.process_cursor", inParams : new { p_cursor = res1.p_rc }, connection : conn); Assert.AreEqual(0, ((IDictionary <string, object>)res2).Count); var processedRows = await(await db.QueryAsync("select * from processing_result", connection: conn)).ToListAsync(); Assert.AreEqual(3, processedRows.Count); } }
public async Task Devart_ParameterCheck(bool explicitConnection) { var db = new SPTestsDatabase(ProviderName, explicitConnection); if (explicitConnection) { MightyTests.ConnectionStringUtils.CheckConnectionStringRequiredForOpenConnectionAsync(db); } dynamic result; using (var connection = await db.OpenConnectionAsync( explicitConnection ? WhenDevart.AddLicenseKey(ProviderName, MightyTests.ConnectionStringUtils.GetConnectionString(TestConstants.ReadTestConnection, ProviderName)) : null)) { using (var command = db.CreateCommandWithParams("testproc_in_out", isProcedure: true, connection: connection)) { // uses a dynamic cast to set a provider-specific property without explicitly depending on the provider library ((dynamic)command).ParameterCheck = true; // Devart-specific: makes a round-trip to the database to fetch the parameter names command.Prepare(); command.Parameters["param1"].Value = 10; await db.ExecuteAsync(command, connection : connection); result = db.ResultsAsExpando(command); } } Assert.AreEqual(20, result.param2); }
public async Task Devart_ParameterCheck() { var db = new SPTestsDatabase(ProviderName); dynamic result; using (var connection = await db.OpenConnectionAsync()) { using (var command = db.CreateCommandWithParams("testproc_in_out", isProcedure: true, connection: connection)) { // uses a dynamic cast to set a provider-specific property without explicitly depending on the provider library ((dynamic)command).ParameterCheck = true; // Devart-specific: makes a round-trip to the database to fetch the parameter names command.Prepare(); command.Parameters["param1"].Value = 10; await db.ExecuteAsync(command); result = db.ResultsAsExpando(command); } } Assert.AreEqual(20, result.param2); }