Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Boolean type does not work in raw CREATE TABLE queries #611

Closed
wolfrace opened this issue Feb 6, 2019 · 5 comments
Closed

Boolean type does not work in raw CREATE TABLE queries #611

wolfrace opened this issue Feb 6, 2019 · 5 comments
Assignees
Labels
3rd-party Third party compatibility bug Something isn't working

Comments

@wolfrace
Copy link

wolfrace commented Feb 6, 2019

err: "invalid connection": query := "CREATE TABLE schema_migrations (version bigint not null primary key, dirty boolean not null)"
all is ok: query := "CREATE TABLE schema_migrations (version bigint not null primary key, dirty bit not null)"

package mysql

import (
   dbSql "database/sql"
   "os"
   "testing"
   "time"

   _ "github.com/go-sql-driver/mysql"
   "github.com/stretchr/testify/assert"
   "gopkg.in/src-d/go-mysql-server.v0"
   "gopkg.in/src-d/go-mysql-server.v0/auth"
   "gopkg.in/src-d/go-mysql-server.v0/mem"
   "gopkg.in/src-d/go-mysql-server.v0/server"
)

type DataSourceName struct {
   User     string
   Password string
   Host     string
   Database string
   Protocol string
}

var dsn = DataSourceName{
   User:     "root",
   Password: "123",
   Host:     "localhost:3400",
   Database: "roll",
   Protocol: "tcp",
}

func TestMain(m *testing.M) {
   engine := sqle.NewDefault()
   engine.AddDatabase(createTestDatabase(dsn.Database))

   config := server.Config{
   	Protocol: dsn.Protocol,
   	Address:  dsn.Host,
   	Auth:     auth.NewNativeSingle(dsn.User, dsn.Password, auth.AllPermissions),
   }

   s, err := server.NewDefaultServer(config, engine)
   if err != nil {
   	panic(err)
   }

   go s.Start()
   retCode := m.Run()
   s.Close()

   os.Exit(retCode)
}

func TestWorkWithDb(t *testing.T) {
   time.Sleep(1000 * time.Millisecond)
   conn, err := dbSql.Open("mysql", "root:123@tcp(localhost:3400)/roll")
   if err != nil {
   	t.Error(err)
   }
   defer conn.Close()

   //query := "CREATE TABLE schema_migrations (version bigint not null primary key, dirty boolean not null)"
   query := "CREATE TABLE schema_migrations (version bigint not null primary key, dirty bit not null)"

   _, err = conn.Exec(query)
   assert.NoError(t, err)
}

func createTestDatabase(dbName string) *mem.Database {
   return mem.NewDatabase(dbName)
}
@erizocosmico erizocosmico added the bug Something isn't working label Feb 6, 2019
@erizocosmico
Copy link
Contributor

Thanks for reporting this, we'll look into it!

@wolfrace wolfrace changed the title Boolean type does not working Boolean type does not work Feb 6, 2019
@wolfrace wolfrace changed the title Boolean type does not work Boolean type does not work in raw CREATE TABLE queries Feb 6, 2019
@kuba-- kuba-- self-assigned this Feb 11, 2019
@kuba-- kuba-- added the 3rd-party Third party compatibility label Feb 11, 2019
@kuba--
Copy link
Contributor

kuba-- commented Feb 11, 2019

Partly this is 3rd party issue (in vitess parser). Vitess doesn't recognize BOOL, BOOLEAN types.
See: https://github.com/vitessio/vitess/blob/master/go/vt/sqlparser/ast.go#L1144
https://github.com/vitessio/vitess/blob/master/go/sqltypes/type.go#L111

But I'm going to send a PR to vitess. So, after they accept it, we can update our mysql-server.
Based on mysql docs. BOOL types are aliases for TINYINT, so in vitess it will be converted to sqltypes.Uint8.

@kuba--
Copy link
Contributor

kuba-- commented Feb 11, 2019

vitess PR: vitessio/vitess#4609

@wolfrace
Copy link
Author

wolfrace commented Feb 13, 2019

@ajnavarro, @erizocosmico, can you create new release tag?

@ajnavarro
Copy link
Contributor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3rd-party Third party compatibility bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants