Skip to content

Commit 9949b0b

Browse files
committed
Bug fix for db.Ping(ctx) against a Doltgres server
1 parent c642a48 commit 9949b0b

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

server/doltgres_handler.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,16 @@ func (h *DoltgresHandler) doQuery(ctx context.Context, c *mysql.Conn, query stri
230230
}
231231
}()
232232

233-
schema, rowIter, qFlags, err := queryExec(sqlCtx, query, parsed, analyzedPlan)
233+
var schema sql.Schema
234+
var rowIter sql.RowIter
235+
var qFlags *sql.QueryFlags
236+
if parsed == nil && analyzedPlan == nil {
237+
// If the query parsed to a nil parse tree and a nil analyzed plan, then there's nothing to execute
238+
logrus.Debugf("nothing to execute for query: %s", query)
239+
rowIter = sql.RowsToRowIter()
240+
} else {
241+
schema, rowIter, qFlags, err = queryExec(sqlCtx, query, parsed, analyzedPlan)
242+
}
234243
if err != nil {
235244
if printErrorStackTraces {
236245
fmt.Printf("error running query: %+v\n", err)

testing/go/framework.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func RunScript(t *testing.T, script ScriptTest, normalizeRows bool) {
130130
Default: pgxConn,
131131
Current: pgxConn,
132132
}
133+
require.NoError(t, pgxConn.Ping(ctx))
133134
defer func() {
134135
conn.Close(ctx)
135136
}()
@@ -309,6 +310,9 @@ func CreateServer(t *testing.T, database string) (context.Context, *Connection,
309310

310311
conn, err := pgx.Connect(ctx, fmt.Sprintf("postgres://postgres:[email protected]:%d/%s", port, database))
311312
require.NoError(t, err)
313+
314+
// Ping the connection to test that it's alive, and also to test that Doltgres handles empty queries correctly
315+
require.NoError(t, conn.Ping(ctx))
312316
return ctx, &Connection{
313317
Default: conn,
314318
Current: conn,

testing/go/smoke_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ func TestSmokeTests(t *testing.T) {
7171
Query: "SELECT NULL = NULL",
7272
Expected: []sql.Row{{nil}},
7373
},
74+
{
75+
Query: ";",
76+
Expected: []sql.Row{},
77+
},
78+
{
79+
Query: " ; ",
80+
Expected: []sql.Row{},
81+
},
82+
{
83+
Query: "-- this is only a comment",
84+
Expected: []sql.Row{},
85+
},
7486
},
7587
},
7688
{

0 commit comments

Comments
 (0)