Skip to content

Commit 3ecb3ca

Browse files
author
邹嵩
committed
修复数据字段长度有大小限制
1 parent f893c43 commit 3ecb3ca

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

src/DotnetSpider.Extension/Pipeline/MySqlEntityPipeline.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private string GetDataTypeSql(DataType type, int length)
284284
}
285285
default:
286286
{
287-
dataType = (length <= 0) ? "LONGTEXT" : $"VARCHAR({length})";
287+
dataType = length <= 0 || length > 8000 ? "LONGTEXT" : $"VARCHAR({length})";
288288
break;
289289
}
290290
}

src/DotnetSpider.Extension/Pipeline/SqlServerEntityPipeline.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ private string GetDataTypeSql(DataType type, int length)
267267
}
268268
default:
269269
{
270-
dataType = length <= 0 ? "NVARCHAR(MAX)" : $"NVARCHAR({length})";
270+
dataType = length <= 0 || length >= 8000 ? "NVARCHAR(MAX)" : $"NVARCHAR({length})";
271271
break;
272272
}
273273
}
@@ -288,7 +288,7 @@ protected override Sqls GenerateSqls(IModel model)
288288
var sqls = new Sqls();
289289

290290
sqls.InsertSql = GenerateInsertSql(model);
291-
sqls.InsertAndIgnoreDuplicateSql= GenerateInsertSql(model);
291+
sqls.InsertAndIgnoreDuplicateSql = GenerateInsertSql(model);
292292
sqls.UpdateSql = GenerateUpdateSql(model);
293293
sqls.SelectSql = GenerateSelectSql(model);
294294
return sqls;

src/DotnetSpider.Sample/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public static void Main(string[] args)
2727
OcrDemo.Process();
2828
#endif
2929

30-
ModelSpider.Run();
30+
TestSpider spider = new TestSpider();
31+
spider.Run();
3132
}
3233

3334

src/netstandard2.0/DotnetSpider.Sample/TestSpider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected override void MyInit(params string[] arguments)
2323
var word = "可乐|雪碧";
2424
AddStartUrl(string.Format("http://news.baidu.com/ns?word={0}&tn=news&from=news&cl=2&pn=0&rn=20&ct=1", word), new Dictionary<string, dynamic> { { "Keyword", word } });
2525
AddEntityType<BaiduSearchEntry>();
26-
AddPipeline(new MySqlEntityPipeline("Database='mysql';Data Source=localhost;User ID=root;Port=3306;SslMode=None;"));
26+
AddPipeline(new SqlServerEntityPipeline("Server=.\\SQLEXPRESS;Database=master;Trusted_Connection=True;MultipleActiveResultSets=true"));
2727
}
2828

2929
[TableInfo("baidu", "baidu_search_entity_model")]
@@ -45,16 +45,16 @@ class BaiduSearchEntry : BaseEntity
4545
[ReplaceFormatter(NewValue = "-", OldValue = "&nbsp;")]
4646
public string Website { get; set; }
4747

48-
[Field(Expression = ".//div/span/a[@class='c-cache']/@href")]
48+
[Field(Expression = ".//div/span/a[@class='c-cache']/@href", Length = 0)]
4949
public string Snapshot { get; set; }
5050

51-
[Field(Expression = ".//div[@class='c-summary c-row ']", Option = FieldOptions.InnerText)]
51+
[Field(Expression = ".//div[@class='c-summary c-row ']", Option = FieldOptions.InnerText, Length = 0)]
5252
[ReplaceFormatter(NewValue = "", OldValue = "<em>")]
5353
[ReplaceFormatter(NewValue = "", OldValue = "</em>")]
5454
[ReplaceFormatter(NewValue = " ", OldValue = "&nbsp;")]
5555
public string Details { get; set; }
5656

57-
[Field(Expression = ".", Option = FieldOptions.InnerText)]
57+
[Field(Expression = ".", Option = FieldOptions.InnerText, Length = 0)]
5858
[ReplaceFormatter(NewValue = "", OldValue = "<em>")]
5959
[ReplaceFormatter(NewValue = "", OldValue = "</em>")]
6060
[ReplaceFormatter(NewValue = " ", OldValue = "&nbsp;")]

0 commit comments

Comments
 (0)