我已经看到了SQL同时使用!=,并<>为不相等.什么是首选语法,为什么?
我喜欢!=,因为<>让我想起Visual Basic.
我正在寻找有关如何处理正在创建,然后由我们的客户上传的csv文件的建议,并且可能在值中使用逗号,例如公司名称.
我们正在关注的一些想法是:引用标识符(值","值","等)或使用| 而不是逗号.最大的问题是我们必须让它变得简单,否则客户就不会这样做.
有没有广泛使用的SQL编码标准?SQL与C/C++类型的编程语言略有不同.真的不知道如何最好地格式化它的可读性.
这看起来像一个小白T-SQL的问题,但我想在存储过程中做这样的逻辑开关和我的想法是使用CASE会喜欢的东西要做到这一点的方式
SELECT CASE @Type
WHEN 1 THEN
INSERT INTO dbo.Credit (
CompanyName,
PhoneNumber,
City,
State
) VALUES (
@CompanyName,
@PhoneNumber,
@City,
@State)
WHEN 2 THEN
INSERT INTO dbo.Debit (
CompanyName,
PhoneNumber,
City,
State
) VALUES (
@CompanyName,
@PhoneNumber,
@City,
@State)
WHEN 3 THEN
--ETC
END
Run Code Online (Sandbox Code Playgroud)
但我一直在收到错误,是否只是一个systax错误,或者我正在吃午饭?
www.sqlservercentral.com上有一篇关于单元测试SQL的文章.
在我的TDD Guy说得好,我们可以测试数据库的东西.
我的系统架构师说,我们测试的逻辑是什么?数据库中不应该有任何逻辑,你应该在数据库中做的唯一事情就是选择,更新或插入.
因此,如果您觉得需要对SQL进行单元测试,那么您是否真的非常彻底,过于务实,还是设计气味的标志?
我正在尝试返回我在sql中更新的行的Id
UPDATE ITS2_UserNames
SET AupIp = @AupIp
WHERE @Customer_ID = TCID AND @Handle_ID = ID
SELECT @@ERROR AS Error, @@ROWCOUNT AS RowsAffected, SCOPE_IDENTITY() AS ID
Run Code Online (Sandbox Code Playgroud)
并且我一直为ID获取Null,我怎么能得到这个?
我有一个无法启动的WinService,因为NServiceBus抛出"服务无法启动.System.Messaging.MessageQueueException(0x80004005):拒绝访问消息队列系统."
这是在Windows 7上
我试图将服务运行为:LocalSystem,Localservice和NetworkService
这是我如何设置NServiceBus
private static IBus _serviceBus;
private static AuditMessageHandler _messageHandler;
public AuditQueueProcessor()
{
_messageHandler = new AuditMessageHandler();
_serviceBus = Configure.With()
.Log4Net()
.DefaultBuilder()
.XmlSerializer()
.MsmqTransport()
.IsTransactional(true)
.PurgeOnStartup(false)
.UnicastBus()
.ImpersonateSender(false)
.LoadMessageHandlers()
.CreateBus()
.Start();
}
Run Code Online (Sandbox Code Playgroud)
这是我的配置
<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core"/>
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"/>
</configSections>
<MsmqTransportConfig InputQueue="LoggerInputQueue" ErrorQueue="LoggerInputError" NumberOfWorkerThreads="1" MaxRetries="5"/>
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="Truckstop2.Imports.Objects.AuditMessage,Truckstop2.Imports.Objects" Endpoint="InputQueue@newimp001" />
</MessageEndpointMappings>
</UnicastBusConfig>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>
Run Code Online (Sandbox Code Playgroud) 我正在尝试模拟一个SqlDataReader
SqlDataReader reader = mocks.CreateMock<SqlDataReader>();
Expect.Call(reader.Read()).Return(true).Repeat.Times(1);
Expect.Call(reader.Read()).Return(false);
Expect.Call(reader.HasRows).Return(true);
Expect.Call(reader.Dispose);
Expect.Call(reader["City"]).Return("Boise");
Expect.Call(reader["State"]).Return("State");
Expect.Call(reader["LAT"]).Return(100);
Expect.Call(reader["LON"]).Return(-100);
mocks.ReplayAll();
Run Code Online (Sandbox Code Playgroud)
但我一直得到一个Rhino.Mocks.Exceptions.ExpectationViolationException:IDisposable.Dispose(); 在我的方法中预期#0,实际#1错误
using (reader)
{
if (reader.HasRows)
{
while (reader.Read())
{
CityState myCity = new CityState
{
City = reader["City"].ToString(),
State = reader["State"].ToString(),
Lat = Convert.ToInt32(reader["LAT"]),
Lon = Convert.ToInt32(reader["LON"])
};
myCities.Add(myCity);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
我有一个事件处理程序,如果它匹配特定类型,需要确定一个类型并执行代码.最初我们将它转换为一个对象,如果它不是null我们执行代码,加快它我使用反射,它实际上减慢了它,我不明白为什么.
这是一个代码示例
Trace.Write("Starting using Reflection");
if (e.Item.GetType() == typeof(GridDataItem))
{
bool isWatch = Convert.ToBoolean(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["IsWatch"]);
if (isWatch)
{
e.Item.Style["Font-Weight"] = "bold";
}
}
Trace.Write("Ending using Reflection");
Trace.Write("Starting using Cast");
GridDataItem gridItem = e.Item as GridDataItem;
if (gridItem !=null)
{
bool isWatch = Convert.ToBoolean(gridItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["IsWatch"]);
if (isWatch)
{
gridItem.Style["Font-Weight"] = "bold";
}
}
Trace.Write("Ending using Cast");
Run Code Online (Sandbox Code Playgroud)
这是我得到的跟踪输出
Starting using Reflection 0.79137944962406 0.576538
Ending using Reflection 0.791600842105263 0.000221
Starting using Cast 0.791623353383459 0.000023
Ending using Cast 0.791649308270677 0.000026
Starting using Reflection 0.876253801503759 0.084604
Ending …Run Code Online (Sandbox Code Playgroud) 我正在寻找在多线程Win服务中使用单例进行日志记录,并想知道我可能遇到的一些问题.我已经设置了get实例来处理同步
private static volatile Logging _instance;
private static object _syncRoot = new object();
private Logging(){}
public static Logging Instance
{
get
{
if (_instance==null)
{
lock(_syncRoot)
{
if (_instance == null)
{
_instance = new Logging();
}
}
}
return _instance;
}
}
Run Code Online (Sandbox Code Playgroud)
还有什么我可能需要担心的吗?
sql ×4
c# ×3
.net ×2
sql-server ×2
t-sql ×2
c#-4.0 ×1
casting ×1
coding-style ×1
csv ×1
nservicebus ×1
reflection ×1
rhino-mocks ×1
singleton ×1
tdd ×1
unit-testing ×1