mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-24 03:09:22 -06:00
Some cleanup
This commit is contained in:
@@ -346,14 +346,14 @@ func listSavedQueries(ctx *sql.Context, qryist cli.Queryist, format engine.Print
|
||||
|
||||
func executeSavedQuery(ctx *sql.Context, qryist cli.Queryist, savedQueryName string, format engine.PrintResultFormat, usage cli.UsagePrinter) int {
|
||||
var buffer bytes.Buffer
|
||||
buffer.WriteString("SELECT query FROM dolt_query_catalog where name = ?")
|
||||
buffer.WriteString("SELECT query FROM dolt_query_catalog where id = ?")
|
||||
searchQuery, err := dbr.InterpolateForDialect(buffer.String(), []interface{}{savedQueryName}, dialect.MySQL)
|
||||
|
||||
rows, err := GetRowsForSql(qryist, ctx, searchQuery)
|
||||
if err != nil {
|
||||
return sqlHandleVErrAndExitCode(qryist, errhand.VerboseErrorFromError(err), usage)
|
||||
} else if len(rows) == 0 {
|
||||
err = fmt.Errorf("no saved queries found")
|
||||
err = fmt.Errorf("saved query %s not found", savedQueryName)
|
||||
return sqlHandleVErrAndExitCode(qryist, errhand.VerboseErrorFromError(err), usage)
|
||||
}
|
||||
|
||||
@@ -369,7 +369,7 @@ func executeSavedQuery(ctx *sql.Context, qryist cli.Queryist, savedQueryName str
|
||||
}
|
||||
}
|
||||
|
||||
cli.PrintErrf("Executing saved query '%s': \n%s\n", savedQueryName, query)
|
||||
cli.PrintErrf("Executing saved query '%s':\n%s\n", savedQueryName, query)
|
||||
return sqlHandleVErrAndExitCode(qryist, execSingleQuery(ctx, qryist, query, format), usage)
|
||||
}
|
||||
|
||||
|
||||
@@ -422,7 +422,7 @@ func getUint64ColAsUint64(col interface{}) (uint64, error) {
|
||||
}
|
||||
|
||||
// getInt32ColAsInt32 returns the value of an int32 column as an int32
|
||||
// This is necessary because Queryist may return an uint64 column as an uint64 (when using SQLEngine)
|
||||
// This is necessary because Queryist may return an int32 column as an int32 (when using SQLEngine)
|
||||
// or as a string (when using ConnectionQueryist).
|
||||
func getInt32ColAsInt32(col interface{}) (int32, error) {
|
||||
switch v := col.(type) {
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
// Copyright 2020 Dolthub, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package dtables_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInsertIntoQueryCatalogTable(t *testing.T) {
|
||||
return
|
||||
/*ctx := context.Background()
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
defer dEnv.DoltDB(ctx).Close()
|
||||
|
||||
root, _ := dEnv.WorkingRoot(ctx)
|
||||
|
||||
_, ok, err := root.GetTable(ctx, doltdb.TableName{Name: doltdb.DoltQueryCatalogTableName})
|
||||
require.NoError(t, err)
|
||||
require.False(t, ok)
|
||||
|
||||
queryStr := "select 1 from dual"
|
||||
sq, root, err := dtables.NewQueryCatalogEntryWithRandID(ctx, root, "name", queryStr, "description")
|
||||
require.NoError(t, err)
|
||||
require.True(t, sq.ID != "")
|
||||
assert.Equal(t, queryStr, sq.Query)
|
||||
assert.Equal(t, "name", sq.Name)
|
||||
assert.Equal(t, "description", sq.Description)
|
||||
|
||||
retrieved, err := dtables.RetrieveFromQueryCatalog(ctx, root, sq.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, sq, retrieved)
|
||||
|
||||
_, ok, err = root.GetTable(ctx, doltdb.TableName{Name: doltdb.DoltQueryCatalogTableName})
|
||||
require.NoError(t, err)
|
||||
require.True(t, ok)
|
||||
|
||||
err = dEnv.UpdateWorkingRoot(ctx, root)
|
||||
require.NoError(t, err)
|
||||
|
||||
rows, err := sqle.ExecuteSelect(ctx, dEnv, root, "select display_order, query, name, description from "+doltdb.DoltQueryCatalogTableName)
|
||||
require.NoError(t, err)
|
||||
expectedRows := []sql.Row{
|
||||
{uint64(1), "select 1 from dual", "name", "description"},
|
||||
}
|
||||
|
||||
assert.Equal(t, expectedRows, rows)
|
||||
|
||||
queryStr2 := "select 2 from dual"
|
||||
sq2, root, err := dtables.NewQueryCatalogEntryWithNameAsID(ctx, root, "name2", queryStr2, "description2")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "name2", sq2.ID)
|
||||
assert.Equal(t, "name2", sq2.Name)
|
||||
assert.Equal(t, queryStr2, sq2.Query)
|
||||
assert.Equal(t, "description2", sq2.Description)
|
||||
|
||||
retrieved2, err := dtables.RetrieveFromQueryCatalog(ctx, root, sq2.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, sq2, retrieved2)
|
||||
|
||||
err = dEnv.UpdateWorkingRoot(ctx, root)
|
||||
require.NoError(t, err)
|
||||
|
||||
rows, err = sqle.ExecuteSelect(ctx, dEnv, root, "select display_order, query, name, description from "+doltdb.DoltQueryCatalogTableName+" order by display_order")
|
||||
require.NoError(t, err)
|
||||
expectedRows = []sql.Row{
|
||||
{uint64(1), "select 1 from dual", "name", "description"},
|
||||
{uint64(2), "select 2 from dual", "name2", "description2"},
|
||||
}
|
||||
|
||||
assert.Equal(t, expectedRows, rows)
|
||||
|
||||
rows, err = sqle.ExecuteSelect(ctx, dEnv, root, "select id from "+doltdb.DoltQueryCatalogTableName)
|
||||
require.NoError(t, err)
|
||||
for _, r := range rows {
|
||||
assert.NotEmpty(t, r)
|
||||
assert.NotEmpty(t, r[0])
|
||||
}
|
||||
|
||||
queryStr3 := "select 3 from dual"
|
||||
sq3, root, err := dtables.NewQueryCatalogEntryWithNameAsID(ctx, root, "name2", queryStr3, "description3")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "name2", sq3.ID)
|
||||
assert.Equal(t, "name2", sq3.Name)
|
||||
assert.Equal(t, queryStr3, sq3.Query)
|
||||
assert.Equal(t, "description3", sq3.Description)
|
||||
assert.Equal(t, sq2.Order, sq3.Order)*/
|
||||
}
|
||||
@@ -34,9 +34,6 @@ var DoltQueryCatalogScripts = []queries.ScriptTest{
|
||||
},
|
||||
{
|
||||
Name: "can drop dolt query catalog, cannot drop twice",
|
||||
SetUpScript: []string{
|
||||
"insert into dolt_query_catalog values ('test', 1, 'test', 'show tables;', '')",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "drop table dolt_query_catalog",
|
||||
@@ -87,4 +84,19 @@ var DoltQueryCatalogScripts = []queries.ScriptTest{
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "can update dolt query catalog",
|
||||
SetUpScript: []string{
|
||||
"INSERT INTO dolt_query_catalog VALUES ('show', 1, 'show', 'show tables;', '')",
|
||||
"UPDATE dolt_query_catalog SET display_order = display_order + 1",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "SELECT * FROM dolt_query_catalog",
|
||||
Expected: []sql.Row{
|
||||
{"show", 2, "show", "show tables;", ""},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlutil"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/writer"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
@@ -819,11 +818,10 @@ func TestAlterSystemTables(t *testing.T) {
|
||||
|
||||
CreateTestTable(t, dEnv, "dolt_docs", doltdb.DocsSchema,
|
||||
"INSERT INTO dolt_docs VALUES ('LICENSE.md','A license')")
|
||||
CreateTestTable(t, dEnv, doltdb.DoltQueryCatalogTableName, dtables.DoltQueryCatalogSchema,
|
||||
"INSERT INTO dolt_query_catalog VALUES ('abc123', 1, 'example', 'select 2+2 from dual', 'description')")
|
||||
ExecuteSetupSQL(context.Background(), `
|
||||
CREATE VIEW name as select 2+2 from dual;
|
||||
CREATE PROCEDURE simple_proc2() SELECT 1+1;
|
||||
INSERT INTO dolt_query_catalog VALUES ('test', 1, 'test', 'show tables;', '');
|
||||
INSERT INTO dolt_ignore VALUES ('test', 1);`)(t, dEnv)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/json"
|
||||
)
|
||||
|
||||
@@ -367,15 +366,6 @@ var systemTableUpdateTests = []UpdateTest{
|
||||
ExpectedRows: []sql.Row{{"LICENSE.md", "Some text"}},
|
||||
ExpectedSchema: CompressSchema(doltdb.DocsSchema),
|
||||
},
|
||||
{
|
||||
Name: "update dolt_query_catalog",
|
||||
AdditionalSetup: CreateTableFn(doltdb.DoltQueryCatalogTableName, dtables.DoltQueryCatalogSchema,
|
||||
"INSERT INTO dolt_query_catalog VALUES ('abc123', 1, 'example', 'select 2+2 from dual', 'description')"),
|
||||
UpdateQuery: "update dolt_query_catalog set display_order = display_order + 1",
|
||||
SelectQuery: "select * from dolt_query_catalog",
|
||||
ExpectedRows: []sql.Row{{"abc123", uint64(2), "example", "select 2+2 from dual", "description"}},
|
||||
ExpectedSchema: CompressSchema(dtables.DoltQueryCatalogSchema),
|
||||
},
|
||||
}
|
||||
|
||||
// Tests the given query on a freshly created dataset, asserting that the result has the given schema and rows. If
|
||||
|
||||
@@ -377,7 +377,6 @@ EOF
|
||||
dolt ci import ./workflow.yaml
|
||||
|
||||
run dolt ci view "workflow"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "name: \"workflow\"" ]] || false
|
||||
[[ "$output" =~ "saved_query_name: \"get tables\"" ]] || false
|
||||
|
||||
@@ -2210,12 +2210,10 @@ EOF
|
||||
[[ "$output" =~ "test" ]] || false
|
||||
|
||||
run dolt --host 0.0.0.0 --no-tls --port $PORT --use-db repo1 sql -l -r csv
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "show,1,show,show tables,\"\"" ]] || false
|
||||
|
||||
run dolt --host 0.0.0.0 --no-tls --port $PORT --use-db repo1 sql -x "show"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "test" ]] || false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user