Fix import file bug #2025

Merged
lunny merged 1 commits from lunny/fix_import_bug into master 2021-08-06 03:26:23 +00:00
3 changed files with 9 additions and 1 deletions

View File

@ -229,6 +229,11 @@ func TestImport(t *testing.T) {
_, err := sess.ImportFile("./testdata/import1.sql") _, err := sess.ImportFile("./testdata/import1.sql")
assert.NoError(t, err) assert.NoError(t, err)
assert.NoError(t, sess.Commit()) assert.NoError(t, sess.Commit())
assert.NoError(t, sess.Begin())
_, err = sess.ImportFile("./testdata/import2.sql")
assert.NoError(t, err)
assert.NoError(t, sess.Commit())
} }
func TestDBVersion(t *testing.T) { func TestDBVersion(t *testing.T) {

3
integrations/testdata/import2.sql vendored Normal file
View File

@ -0,0 +1,3 @@
CREATE TABLE IF NOT EXISTS `Core_Goods` (`Id` BIGINT(20) PRIMARY KEY AUTO_INCREMENT NOT NULL, `GoodsSN` VARCHAR(20) NULL COMMENT '商品序列号', `GoodsSort` INT(11) NULL COMMENT '商品排序', `GoodsName` VARCHAR(100) NULL COMMENT '商品名称', `GoodsThumb` VARCHAR(500) NULL, `GoodsUnit` VARCHAR(255) NULL, `PerUnitNum` BIGINT(20) NULL, `GoodsState` TINYINT(4) NULL COMMENT '商品状态', `IsClose` TINYINT(1) DEFAULT 0 NULL COMMENT '关闭下单', `GoodsDesc` VARCHAR(200) NULL COMMENT '商品简介', `GoodsContent` TEXT NULL COMMENT '商品详情', `GoodsImages` TEXT NULL COMMENT '商品图片', `MinOrderNum` INT(11) NULL COMMENT '最少下单数', `MaxOrderNum` INT(11) NULL COMMENT '最大下单数', `CategoryId` INT(11) NULL COMMENT '商品分类', `SupplyPrice` BIGINT(20) NULL COMMENT '供货单价', `StockNum` INT(11) NULL COMMENT '库存数量小于0不限制', `HandleRemarks` VARCHAR(255) NULL COMMENT '处理备注', `ParamsTemplate` TEXT NULL COMMENT '下单参数模板', `PriceTemplateId` INT(11) NULL COMMENT '加价模板id', `GoodsSnapshotId` INT(11) NULL COMMENT '当前快照id', `SupplierUserId` INT(11) NULL COMMENT '供货商用户id', `CanTui` TINYINT(1) DEFAULT 0 NULL COMMENT '是否可以申请退款', `CanRepeat` TINYINT(1) DEFAULT 1 NULL COMMENT '是否可以申请退款', `GoodsType` TINYINT(4) DEFAULT 1 NULL COMMENT '商品类型', `CreatedAt` DATETIME NULL COMMENT '创建时间', `UpdatedAt` DATETIME NULL COMMENT '修改时间', `LastHandlerAdminUserId` INT(11) NULL COMMENT '最后操作管理员', `GoodsMode` TINYINT(4) DEFAULT 0 NULL COMMENT '商品属性', `SaleTotal` INT(11) NULL COMMENT '总销量', `SaleMonth` INT(11) NULL COMMENT '月销量', `Notice` TEXT NULL COMMENT '商品公告', `AfterLunchOrderState` TINYINT(4) NULL COMMENT '下单后状态', `JoinMode` TINYINT(4) DEFAULT 1 NULL COMMENT '对接模式', `ApiOrderLunchConfig` TEXT NULL COMMENT '提交订单配置', `Version` BIGINT(20) DEFAULT 1 NULL) ENGINE=InnoDB;
INSERT INTO `Core_Goods` (`Id`, `GoodsSN`, `GoodsSort`, `GoodsName`, `GoodsThumb`, `GoodsUnit`, `PerUnitNum`, `GoodsState`, `IsClose`, `GoodsDesc`, `GoodsContent`, `GoodsImages`, `MinOrderNum`, `MaxOrderNum`, `CategoryId`, `SupplyPrice`, `StockNum`, `HandleRemarks`, `ParamsTemplate`, `PriceTemplateId`, `GoodsSnapshotId`, `SupplierUserId`, `CanTui`, `CanRepeat`, `GoodsType`, `CreatedAt`, `UpdatedAt`, `LastHandlerAdminUserId`, `GoodsMode`, `SaleTotal`, `SaleMonth`, `Notice`, `AfterLunchOrderState`, `JoinMode`, `ApiOrderLunchConfig`, `Version`) VALUES (42,'2107290140000432',91,' - ','','',1,2,0,'','--','[]',3,10000,10,5974060,-1,'','',1,0,10001,0,1,1,'2021-07-29 01:40:55','2021-07-30 18:28:59',10000,2,0,0,'',0,0,'{"url":"","method":"","type":"","succContactStr":"","data":null}',35);
INSERT INTO `Core_Goods` (`Id`, `GoodsSN`, `GoodsSort`, `GoodsName`, `GoodsThumb`, `GoodsUnit`, `PerUnitNum`, `GoodsState`, `IsClose`, `GoodsDesc`, `GoodsContent`, `GoodsImages`, `MinOrderNum`, `MaxOrderNum`, `CategoryId`, `SupplyPrice`, `StockNum`, `HandleRemarks`, `ParamsTemplate`, `PriceTemplateId`, `GoodsSnapshotId`, `SupplierUserId`, `CanTui`, `CanRepeat`, `GoodsType`, `CreatedAt`, `UpdatedAt`, `LastHandlerAdminUserId`, `GoodsMode`, `SaleTotal`, `SaleMonth`, `Notice`, `AfterLunchOrderState`, `JoinMode`, `ApiOrderLunchConfig`, `Version`) VALUES (43,'2107290140000433',90,' - ','','',1,2,0,'','','[]',3,10000,10,9064091,-1,'','',1,0,10001,0,1,1,'2021-07-29 01:40:55','2021-07-30 18:28:59',10000,2,0,0,'',0,0,'{"url":"","method":"","type":"","succContactStr":"","data":null}',39);

View File

@ -469,7 +469,7 @@ func (session *Session) Import(r io.Reader) ([]sql.Result, error) {
startComment = false startComment = false
} }
} else { } else {
if i > 0 && data[i-1] == '-' && data[i] == '-' { if !inSingleQuote && i > 0 && data[i-1] == '-' && data[i] == '-' {
startComment = true startComment = true
continue continue
} }