<commit_before>package org.postgresql.test.jdbc2;

import org.postgresql.test.TestUtil;
import junit.framework.TestCase;
import java.sql.*;

/* TODO tests that can be added to this test case
 * - SQLExceptions chained to a BatchUpdateException
 * - test PreparedStatement as thoroughly as Statement
 */

/*
 * Test case for Statement.batchExecute()
 */
public class BatchExecuteTest extends TestCase
{

	private Connection con;

	public BatchExecuteTest(String name)
	{
		super(name);
	}

	// Set up the fixture for this testcase: a connection to a database with
	// a table for this test.
	protected void setUp() throws Exception
	{
		con = TestUtil.openDB();
		Statement stmt = con.createStatement();

		// Drop the test table if it already exists for some reason. It is
		// not an error if it doesn't exist.
		TestUtil.createTable(con, "testbatch", "pk INTEGER, col1 INTEGER");

		stmt.executeUpdate("INSERT INTO testbatch VALUES (1, 0)");

		// Generally recommended with batch updates. By default we run all
		// tests in this test case with autoCommit disabled.
		con.setAutoCommit(false);
	}

	// Tear down the fixture for this test case.
	protected void tearDown() throws Exception
	{
		con.setAutoCommit(true);

		TestUtil.dropTable(con, "testbatch");
		TestUtil.closeDB(con);
	}

	public void testSupportsBatchUpdates() throws Exception
	{
		DatabaseMetaData dbmd = con.getMetaData();
		assertTrue(dbmd.supportsBatchUpdates());
	}

	private void assertCol1HasValue(int expected) throws Exception
	{
		Statement getCol1 = con.createStatement();<commit_msg>Add a test case for recent clearBatch error.<commit_after>package org.postgresql.test.jdbc2;

import org.postgresql.test.TestUtil;
import junit.framework.TestCase;
import java.sql.*;

/* TODO tests that can be added to this test case
 * - SQLExceptions chained to a BatchUpdateException
 * - test PreparedStatement as thoroughly as Statement
 */

/*
 * Test case for Statement.batchExecute()
 */
public class BatchExecuteTest extends TestCase
{

	private Connection con;

	public BatchExecuteTest(String name)
	{
		super(name);
	}

	// Set up the fixture for this testcase: a connection to a database with
	// a table for this test.
	protected void setUp() throws Exception
	{
		con = TestUtil.openDB();
		Statement stmt = con.createStatement();

		// Drop the test table if it already exists for some reason. It is
		// not an error if it doesn't exist.
		TestUtil.createTable(con, "testbatch", "pk INTEGER, col1 INTEGER");

		stmt.executeUpdate("INSERT INTO testbatch VALUES (1, 0)");

		// Generally recommended with batch updates. By default we run all
		// tests in this test case with autoCommit disabled.
		con.setAutoCommit(false);
	}

	// Tear down the fixture for this test case.
	protected void tearDown() throws Exception
	{
		con.setAutoCommit(true);

		TestUtil.dropTable(con, "testbatch");
		TestUtil.closeDB(con);
	}

	public void testSupportsBatchUpdates() throws Exception
	{
		DatabaseMetaData dbmd = con.getMetaData();
		assertTrue(dbmd.supportsBatchUpdates());
	}

	public void testEmptyClearBatch() throws Exception
	{
		Statement stmt = con.createStatement();
		stmt.clearBatch(); // No-op.

		PreparedStatement ps = con.prepareStatement("SELECT ?");
		ps.clearBatch(); // No-op.
	}

	private void assertCol1HasValue(int expected) throws Exception
	{
		Statement getCol1 = con.createStatement();
{'fraction_non_alphanumeric': 0.09574468085106383, 'fraction_numerical': 0.0035460992907801418, 'mean_word_length': 4.09789156626506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7550388', 'n_tokens_mistral': 1052, 'n_tokens_neox': 989, 'n_words': 339}