开发者

Quoting integers

I've been under the impression that quoting integers in SQL queries is frowned upon, but I've recently le开发者_如何学Pythonarned that prominent frameworks like Django adheres to this practice. Is it in fact perfectly acceptable?


The question implies that you put naked values in your SQL query in the first place. I think the most "acceptable" practice would be to parameterize the query instead - that way you don't have to concern yourself with issues such as this; let the data access library handle it for you instead.


Quoting integers in SQL has only a minor performance penalty. Removing the quotes is much less work than converting the ASCII representation to a binary integer.

So I'd say it's perfectly acceptable, especially for a RAD framework.


I'm not sure about all SQL databases, but SQL Server will implicitly convert a quoted number to an int. For example the following returns 166 in SQL Server 2000:

select '500'/3
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜