public void PqsqlConnectionTest6() { PqsqlConnection connection = new PqsqlConnection(connectionString); connection.Open(); Assert.AreEqual(ConnectionState.Open, connection.State, "wrong connection state"); PqsqlCommand cmd = connection.CreateCommand(); Assert.AreEqual(CommandType.Text, cmd.CommandType, "wrong command type"); Assert.AreEqual(-1, cmd.CommandTimeout, "wrong command timeout"); Assert.AreEqual(string.Empty, cmd.CommandText, "wrong command text"); Assert.AreEqual(connection, cmd.Connection, "wrong command connection"); Assert.AreEqual(null, cmd.Transaction, "wrong command transaction"); cmd.CommandText = "select pg_terminate_backend(pg_backend_pid()); select pg_sleep(5);"; cmd.ExecuteNonQuery(); // must execute both statements cmd.Cancel(); cmd.CommandText = ""; cmd.ExecuteNonQuery(); }
public void PqsqlConnectionStringBuilderTest1() { PqsqlConnectionStringBuilder builder = new PqsqlConnectionStringBuilder(connectionString); builder[PqsqlConnectionStringBuilder.keepalives] = "1"; builder[PqsqlConnectionStringBuilder.keepalives_idle] = "23"; builder[PqsqlConnectionStringBuilder.keepalives_count] = "3"; builder[PqsqlConnectionStringBuilder.keepalives_interval] = "3"; string dataSource; using (PqsqlConnection connection = new PqsqlConnection(builder)) { // closed connection with service file should give us empty data source Assert.IsTrue(string.IsNullOrEmpty(connection.DataSource)); using (PqsqlCommand cmd = new PqsqlCommand("show all", connection)) using (PqsqlDataReader r = cmd.ExecuteReader()) { object value; if (builder.TryGetValue(PqsqlConnectionStringBuilder.host, out value)) { Assert.AreEqual(connection.DataSource, value); dataSource = value.ToString(); } else // no datasource specified { dataSource = connection.DataSource; } cmd.Cancel(); } } builder[PqsqlConnectionStringBuilder.host] = dataSource; using (PqsqlConnection connection = new PqsqlConnection(builder)) using (PqsqlCommand cmd = new PqsqlCommand("show all", connection)) using (PqsqlDataReader r = cmd.ExecuteReader()) { object value; if (builder.TryGetValue(PqsqlConnectionStringBuilder.host, out value)) { Assert.AreEqual(connection.DataSource, value); } else { Assert.Fail("host part is not available"); } cmd.Cancel(); } }
public void PqsqlCommandTest5() { PqsqlCommand cmd = mConnection.CreateCommand(); cmd.CommandText = "pg_authid"; cmd.CommandTimeout = 10; cmd.CommandType = CommandType.TableDirect; var r = cmd.ExecuteReader(); foreach (var o in r) { Assert.IsNotNull(o); } cmd.Cancel(); mConnection.Close(); mConnection.Open(); }