You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug: When I run aCREATE TABLE in the master database, Collection(<newly created table name>).Exists() always returns false when using the mssql adapter. I traced it down to this line here: https://github.com/upper/db/blob/master/adapter/mssql/database.go#L108. It looks like when a table is being checked for whether it exists, the table_schema is being filtered on with the name of the database. However, the table is being created in the master database with a dbo table schema, not master, the name of the database.
We can now also confirm this in Go using the library and see that the Exists method always returns false with mssql (I don't have this issue with the MySQL or Postgres adapters).
In a shell:
$ mkdir test
$ cd test
$ go mod init test
go: creating new go.mod: module test
$ go get github.com/upper/db/v4
go: added github.com/upper/db/v4 v4.7.0
$ go get github.com/upper/db/v4/adapter/mssql
go: downloading golang.org/x/crypto v0.12.0
$ touch main.go
main.go
package main
import (
"fmt""os""github.com/upper/db/v4/adapter/mssql"
)
funcmain() {
db, err:=mssql.Open(mssql.ConnectionURL{
User: "SA",
Password: "testPASS123.?",
Host: "localhost",
Database: "master",
})
iferr!=nil {
fmt.Println(err)
os.Exit(1)
}
_, err=db.SQL().Exec(`CREATE TABLE tmp(id int PRIMARY KEY);`)
iferr!=nil {
fmt.Println(err)
os.Exit(1)
}
// Show that the table shows up in the information_schema and was created.rows, err:=db.SQL().Select("table_name").From("information_schema.tables").Query()
iferr!=nil {
fmt.Println(err)
os.Exit(1)
}
deferrows.Close()
fmt.Println("--- Tables names ---")
forrows.Next() {
vartableNamestringerr:=rows.Scan(&tableName)
iferr!=nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(tableName)
}
// Show that the query for exists doesn't find it._, err=db.Collection("tmp").Exists()
iferr!=nil {
fmt.Println(err)
os.Exit(1)
}
}
Now, in a shell, we can run it:
$ go run main.go
--- Tables names ---
spt_fallback_db
spt_fallback_dev
spt_fallback_usg
tmp
spt_values
spt_monitor
MSreplication_options
upper: collection does not exist
exit status 1
The text was updated successfully, but these errors were encountered:
eugenetriguba
changed the title
[Bug] TableExists for SQL Server adapter uses database name as table schema when checking for existence
[Bug] TableExists for mssql adapter uses database name as table schema when checking for existence
Mar 10, 2024
Bug: When I run a
CREATE TABLE
in themaster
database,Collection(<newly created table name>).Exists()
always returns false when using themssql
adapter. I traced it down to this line here: https://github.com/upper/db/blob/master/adapter/mssql/database.go#L108. It looks like when a table is being checked for whether it exists, thetable_schema
is being filtered on with the name of the database. However, the table is being created in themaster
database with adbo
table schema, notmaster
, the name of the database.Steps to Reproduce:
docker-compose.yml
In a shell:
That should establish that the query (https://github.com/upper/db/blob/master/adapter/mssql/database.go#L108) seems to be incorrect because the table_schema is
dbo
, notmaster
, sosess.Name()
wouldn't find it.We can now also confirm this in Go using the library and see that the Exists method always returns false with mssql (I don't have this issue with the MySQL or Postgres adapters).
In a shell:
main.go
Now, in a shell, we can run it:
The text was updated successfully, but these errors were encountered: