diff --git a/docs/USAGE.md b/docs/USAGE.md index 5e426c63c9216..bbb8c3892763b 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -22,10 +22,12 @@ func main() { // Default log level is debug, set it to error to turn off debug log. log.SetLevelByString("error") - // DriverName is 'tidb', dataSourceName is in the form of "://". + // DriverName is 'tidb', dataSourceName is in the form of ":///". // dbPath is the directory that stores the data files if you use a local storage engine. + // dbName is the name of the database which you want to use. dbPath := "/tmp/tidb" - db, err := sql.Open("tidb", "goleveldb://" + dbPath) + dbName := "tidb" + db, err := sql.Open("tidb", "goleveldb://" + dbPath + "/" + dbName) if err != nil { log.Fatal(err) } diff --git a/driver.go b/driver.go index f87805046a289..b2507e301db15 100644 --- a/driver.go +++ b/driver.go @@ -135,7 +135,7 @@ 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) + return nil, errors.Errorf("Invalid dataSource: %q", dataSource) } uri := dataSource[:i] dbName := dataSource[i+1:] @@ -146,12 +146,6 @@ func (d *sqlDriver) Open(dataSource string) (driver.Conn, error) { } driver := &sqlDriver{} - switch { - case strings.HasPrefix(uri, "file://"): - uri = uri[len("file://"):] - case strings.HasPrefix(uri, "memory://"): - uri = uri[len("memory://"):] - } dbName = filepath.Clean(dbName) if dbName == "" || dbName == "." || dbName == string(os.PathSeparator) { return nil, errors.Errorf("invalid DB name %q", dbName) @@ -171,7 +165,6 @@ func (d *sqlDriver) Open(dataSource string) (driver.Conn, error) { return nil, errors.Trace(err) } } - return newDriverConn(s, driver, DBName.O) }