Fixed a bug on windows when redirecting STDIN for SQL import, e.g. dolt sql < dump.sql. Also fixed up ip2nation sample so that it successfully imports

Signed-off-by: Zach Musgrave <zach@liquidata.co>
This commit is contained in:
Zach Musgrave
2019-08-09 12:48:19 -07:00
parent 7e969ffb51
commit 9b9ec6dc3e
3 changed files with 11 additions and 5 deletions

8
go/cmd/dolt/commands/sql.go Normal file → Executable file
View File

@@ -19,6 +19,7 @@ import (
"bytes"
"context"
"fmt"
"github.com/liquidata-inc/dolt/go/libraries/utils/osutil"
"io"
"os"
"path/filepath"
@@ -117,9 +118,12 @@ func Sql(commandStr string, args []string, dEnv *env.DoltEnv) int {
}
// Run in either batch mode for piped input, or shell mode for interactive
fi, _ := os.Stdin.Stat()
if (fi.Mode() & os.ModeCharDevice) == 0 {
fi, err := os.Stdin.Stat()
// Windows has a bug where STDIN can't be statted in some cases, see https://github.com/golang/go/issues/33570
if (err != nil && osutil.IsWindows) || (fi.Mode() & os.ModeCharDevice) == 0 {
root = runBatchMode(dEnv, root)
} else if err != nil {
HandleVErrAndExitCode(errhand.BuildDError("Couldn't stat STDIN. This is a bug.").Build(), usage)
} else {
var err error
root, err = runShell(dEnv, root)

2
go/libraries/doltcore/sql/sqlddl.go Normal file → Executable file
View File

@@ -451,6 +451,8 @@ func getColumn(colDef *sqlparser.ColumnDefinition, indexes []*sqlparser.IndexDef
return schema.InvalidCol, nil, err
}
// TODO: type conversion. This doesn't work at all for uint columns (parser always thinks integer literals are int,
// not uint)
if getter.NomsKind != colKind {
return errColumn("Type mismatch for default value of column %v: '%v'", column.Name, nodeToString(colDef.Type.Default))
}

View File

@@ -1,6 +1,6 @@
CREATE TABLE ip2nation (
ip int(11) unsigned NOT NULL default '0',
ip int(11) NOT NULL default 0,
country char(2) NOT NULL default '',
PRIMARY KEY (ip)
);
@@ -11,8 +11,8 @@ CREATE TABLE ip2nationCountries (
iso_code_3 varchar(3) default '',
iso_country varchar(255) NOT NULL default '',
country varchar(255) NOT NULL default '',
lat float NOT NULL default '0',
lon float NOT NULL default '0',
lat float NOT NULL default 0.0,
lon float NOT NULL default 0.0,
PRIMARY KEY (code)
);