Skip to content

Commit

Permalink
pgwire: test some portal and prepared statement behavior
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
maddyblue committed Jul 2, 2019
1 parent 81cb3d4 commit 4b7cf62
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
87 changes: 87 additions & 0 deletions pkg/sql/pgwire/testdata/pgtest/portals
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,90 @@ ReadyForQuery
----
{"Type":"ErrorResponse"}
{"Type":"ReadyForQuery","TxStatus":"I"}

# Verify that closing a bound portal prevents execution.

# 80 = ASCII 'P'
send
Parse {"Name": "s", "Query": "SELECT 1"}
Bind {"DestinationPortal": "p", "PreparedStatement": "s"}
Close {"ObjectType": 80, "Name": "p"}
Execute {"Portal": "p"}
Sync
----

until
ErrorResponse
ReadyForQuery
----
{"Type":"ParseComplete"}
{"Type":"BindComplete"}
{"Type":"CloseComplete"}
{"Type":"ErrorResponse"}
{"Type":"ReadyForQuery","TxStatus":"I"}

# The spec says that closing a prepared statement also closes its portals,
# but that doesn't seem to be the case. Below I would expect that Bind,
# Close, Execute causes the execute to return an error, but it instead
# returns the portal result. This happens in both Postgres and Cockroach.

# 83 = ASCII 'S'
# After closing, re-parse with the same name to make sure the execute
# happens on the old statement.
send
Bind {"DestinationPortal": "p", "PreparedStatement": "s"}
Close {"ObjectType": 83, "Name": "s"}
Parse {"Name": "s", "Query": "SELECT 2"}
Execute {"Portal": "p"}
Sync
----

until
ReadyForQuery
----
{"Type":"BindComplete"}
{"Type":"CloseComplete"}
{"Type":"ParseComplete"}
{"Type":"DataRow","Values":[{"text":"1"}]}
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ReadyForQuery","TxStatus":"I"}

# Portal still isn't destroyed within a transaction either, in PG or CR.

send
Query {"String": "BEGIN"}
----

until
ReadyForQuery
----
{"Type":"CommandComplete","CommandTag":"BEGIN"}
{"Type":"ReadyForQuery","TxStatus":"T"}

send
Bind {"DestinationPortal": "p", "PreparedStatement": "s"}
Close {"ObjectType": 83, "Name": "s"}
Parse {"Name": "s", "Query": "SELECT 3"}
Execute {"Portal": "p"}
Sync
----

until
ReadyForQuery
----
{"Type":"BindComplete"}
{"Type":"CloseComplete"}
{"Type":"ParseComplete"}
{"Type":"DataRow","Values":[{"text":"2"}]}
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ReadyForQuery","TxStatus":"T"}

send
Query {"String": "COMMIT"}
----

until
ReadyForQuery
----
{"Type":"CommandComplete","CommandTag":"COMMIT"}
{"Type":"ReadyForQuery","TxStatus":"I"}
2 changes: 2 additions & 0 deletions pkg/testutils/pgtest/datadriven.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func toMessage(typ string) interface{} {
switch typ {
case "Bind":
return &pgproto3.Bind{}
case "Close":
return &pgproto3.Close{}
case "CommandComplete":
return &pgproto3.CommandComplete{}
case "DataRow":
Expand Down

0 comments on commit 4b7cf62

Please sign in to comment.