Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dolt_commit error check when autocommit is off #1074

Merged
merged 5 commits into from
Dec 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 51 additions & 0 deletions bats/sql-server.bats
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,57 @@ teardown() {
[[ "$output" =~ "one_pk" ]] || false
}


@test "test dolt sql interface works properly with autocommit" {
skiponwindows "Has dependencies that are missing on the Jenkins Windows installation."

cd repo1
start_sql_server repo1

# No tables at the start
run dolt ls
[ "$status" -eq 0 ]
[[ "$output" =~ "No tables in working set" ]] || false

# create table with autocommit off and verify there are still no tables
server_query 0 "CREATE TABLE one_pk (
pk BIGINT NOT NULL COMMENT 'tag:0',
c1 BIGINT COMMENT 'tag:1',
c2 BIGINT COMMENT 'tag:2',
PRIMARY KEY (pk)
)" ""
run dolt ls
[ "$status" -eq 0 ]
[[ "$output" =~ "No tables in working set" ]] || false

# check that dolt_commit throws an error when autocommit is off
run dolt sql -q "SELECT DOLT_COMMIT('-a', '-m', 'Commit1')"
VinaiRachakonda marked this conversation as resolved.
Show resolved Hide resolved
[ "$status" -eq 1 ]

run dolt ls
[ "$status" -eq 0 ]
[[ "$output" =~ "No tables in working set" ]] || false

# create table with autocommit on and verify table creation
server_query 1 "CREATE TABLE one_pk (
pk BIGINT NOT NULL COMMENT 'tag:0',
c1 BIGINT COMMENT 'tag:1',
c2 BIGINT COMMENT 'tag:2',
PRIMARY KEY (pk)
)" ""
run dolt ls
[ "$status" -eq 0 ]
[[ "$output" =~ "one_pk" ]] || false

# check that dolt_commit works properly when autocommit is on
run dolt sql -q "SELECT DOLT_COMMIT('-a', '-m', 'Commit1')"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also should have a test of the negative case, where there are no staged changes / no changes to stage. With and without -a.

[ "$status" -eq 0 ]

run dolt log
[ $status -eq 0 ]
[[ "$output" =~ "Commit1" ]] || false
}

@test "test basic querying via dolt sql-server" {
skiponwindows "Has dependencies that are missing on the Jenkins Windows installation."

Expand Down
6 changes: 6 additions & 0 deletions go/libraries/doltcore/sqle/dfunctions/dolt_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ func (d DoltCommitFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)
dbName := ctx.GetCurrentDatabase()
dSess := sqle.DSessFromSess(ctx.Session)

_, val := dSess.Session.Get(sql.AutoCommitSessionVar)
VinaiRachakonda marked this conversation as resolved.
Show resolved Hide resolved

if !(val.(bool)) {
return nil, fmt.Errorf("AUTOCOMMIT must be set to true.")
}

ddb, ok := dSess.GetDoltDB(dbName)

if !ok {
Expand Down