A Long overflow in an int overflow + ASP statement in an SQL statement

Source: Internet
Author: User

More than 5 o'clock in the evening, colleagues in QQ told me that a user responded to him, when he logged in to display the error message, we in the management platform to view the user's basic information, also display error message.

After a preliminary analysis, an int overflow occurred while executing the SQL statement:

sql = "Select sum (fileSize) as Fstotal from pic where UserID = 1632"

Originally, this SQL was used to get a total of all file sizes uploaded by a user before.

fileSize field type int

An int overflow occurs when a user uploads a file with a cumulative size of more than 2G (2147483648 bytes) and then executes sum (fileSize).

After you find the cause of the problem, start modifying the SQL statement:

sql = "Select sum (CAST (fileSize as bigint)) as Fstotal from pic where UserID = 1632"

After the modification, the test found that there are still errors, but this time the error is not because of this SQL, but from the ASP long overflow.

sql = "Select sum (CAST (fileSize as bigint)) as Fstotal from pic where UserID = 1632"
Set Re=conn.execute (SQL)
If not re.eof then
Fstotal = Re.fields ("Fstotal")
Fstotal = fstotal/1024/1024 ' converted to MB-a long overflow occurred
End If

To modify the code:

Fstotal = Re.fields ("Fstotal")
Fstotal = CDbl (fstotal) ' convert to double type before proceeding
Fstotal = fstotal/1024/1024 ' converted to MB

-----------------------------------------------------------------------------------------------------------

SQL server,int Type value max 2147483647 (2^31-1)
Asp,long (Long Integer) 4 bytes-2,147,483,648 to 2,147,483,647

2010-11-03

A Long overflow in an int overflow + ASP statement in an SQL statement

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.