Skip to content

Commit

Permalink
test(pkg/pgsql): cover fixed query for odbc help
Browse files Browse the repository at this point in the history
Signed-off-by: Jeronimo Irazabal <[email protected]>
  • Loading branch information
jeroiraz committed Nov 16, 2023
1 parent ed973e1 commit 6808ecf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/database/all_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func TestExecAllOps(t *testing.T) {
Set: []byte(`mySet`),
}
zList, err := db.ZScan(context.Background(), zScanOpt)
require.ErrorIs(t, err, ErrResultSizeLimitReached)
require.NoError(t, err)
println(len(zList.Entries))
require.Len(t, zList.Entries, batchCount*batchSize)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
)

const MaxKeyResolutionLimit = 1
const MaxKeyScanLimit = 1000
const MaxKeyScanLimit = 2500

var ErrKeyResolutionLimitReached = errors.New("key resolution limit reached. It may be due to cyclic references")
var ErrResultSizeLimitExceeded = errors.New("result size limit exceeded")
Expand Down
4 changes: 2 additions & 2 deletions pkg/pgsql/server/query_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
fm "github.com/codenotary/immudb/pkg/pgsql/server/fmessages"
)

const tableHelpPrefix = "select n.nspname, c.relname, a.attname, a.atttypid, t.typname, a.attnum, a.attlen, a.atttypmod, a.attnotnull, c.relhasrules, c.relkind, c.oid, pg_get_expr(d.adbin, d.adrelid), case t.typtype when 'd' then t.typbasetype else 0 end, t.typtypmod, c.relhasoids, '', c.relhassubclass from (((pg_catalog.pg_class c inner join pg_catalog.pg_namespace n on n.oid = c.relnamespace and c.relname like '"

func (s *session) QueryMachine() error {
var waitForSync = false

Expand Down Expand Up @@ -70,8 +72,6 @@ func (s *session) QueryMachine() error {
statements = "show tables"
}

tableHelpPrefix := "select n.nspname, c.relname, a.attname, a.atttypid, t.typname, a.attnum, a.attlen, a.atttypmod, a.attnotnull, c.relhasrules, c.relkind, c.oid, pg_get_expr(d.adbin, d.adrelid), case t.typtype when 'd' then t.typbasetype else 0 end, t.typtypmod, c.relhasoids, '', c.relhassubclass from (((pg_catalog.pg_class c inner join pg_catalog.pg_namespace n on n.oid = c.relnamespace and c.relname like '"

if strings.HasPrefix(statements, tableHelpPrefix) {
tableName := strings.Split(strings.TrimPrefix(statements, tableHelpPrefix), "'")[0]
statements = fmt.Sprintf("select column_name as tq, column_name as tow, column_name as tn, column_name as COLUMN_NAME, type_name as DATA_TYPE, type_name as TYPE_NAME, type_name as p, type_name as l, type_name as s, type_name as r, is_nullable as NULLABLE, column_name as rk, column_name as cd, type_name as SQL_DATA_TYPE, type_name as sts, column_name as coll, type_name as orp, is_nullable as IS_NULLABLE, type_name as dz, type_name as ft, type_name as iau, type_name as pn, column_name as toi, column_name as btd, column_name as tmo, column_name as tin from table(%s)", tableName)
Expand Down
20 changes: 20 additions & 0 deletions pkg/pgsql/server/query_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,26 @@ func TestSession_QueriesMachine(t *testing.T) {
},
out: nil,
},
{
name: "schema info",
in: func(c2 net.Conn) {
ready4Query := make([]byte, len(bmessages.ReadyForQuery()))
c2.Read(ready4Query)
c2.Write(h.Msg('Q', h.S("select current_schema()")))
c2.Close()
},
out: nil,
},
{
name: "schema info",
in: func(c2 net.Conn) {
ready4Query := make([]byte, len(bmessages.ReadyForQuery()))
c2.Read(ready4Query)
c2.Write(h.Msg('Q', h.S(tableHelpPrefix)))
c2.Close()
},
out: nil,
},
}

for i, tt := range tests {
Expand Down

0 comments on commit 6808ecf

Please sign in to comment.