-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
tidb: Split datasource name to uri and dbName #96
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,22 +131,30 @@ func (d *sqlDriver) lock() func() { | |
// efficient re-use. | ||
// | ||
// The returned connection is only used by one goroutine at a time. | ||
func (d *sqlDriver) Open(name string) (driver.Conn, error) { | ||
store, err := NewStore(name) | ||
func (d *sqlDriver) Open(dataSource string) (driver.Conn, error) { | ||
// Split the dataSource to uri and dbName | ||
i := strings.LastIndex(dataSource, "/") | ||
if i == -1 { | ||
return nil, errors.Errorf("Wrong format of datasource string: %q", dataSource) | ||
} | ||
uri := dataSource[:i] | ||
dbName := dataSource[i+1:] | ||
|
||
store, err := NewStore(uri) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
|
||
driver := &sqlDriver{} | ||
switch { | ||
case strings.HasPrefix(name, "file://"): | ||
name = name[len("file://"):] | ||
case strings.HasPrefix(name, "memory://"): | ||
name = name[len("memory://"):] | ||
case strings.HasPrefix(uri, "file://"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does any engine use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The switch statement is useless now. I will remove it. |
||
uri = uri[len("file://"):] | ||
case strings.HasPrefix(uri, "memory://"): | ||
uri = uri[len("memory://"):] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need use default to return an error? |
||
} | ||
name = filepath.Clean(name) | ||
if name == "" || name == "." || name == string(os.PathSeparator) { | ||
return nil, errors.Errorf("invalid DB name %q", name) | ||
dbName = filepath.Clean(dbName) | ||
if dbName == "" || dbName == "." || dbName == string(os.PathSeparator) { | ||
return nil, errors.Errorf("invalid DB name %q", dbName) | ||
} | ||
|
||
sess, err := CreateSession(store) | ||
|
@@ -155,7 +163,7 @@ func (d *sqlDriver) Open(name string) (driver.Conn, error) { | |
} | ||
s := sess.(*session) | ||
defer d.lock()() | ||
DBName := model.NewCIStr(name[strings.LastIndex(name, "/")+1:]) | ||
DBName := model.NewCIStr(dbName) | ||
domain := sessionctx.GetDomain(s) | ||
if !domain.InfoSchema().SchemaExists(DBName) { | ||
err = domain.DDL().CreateSchema(s, DBName) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong -> Bad?