Visual Basic / MySQL Datatypes

<script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>

Visual Basic can be very loose with it's data types. If you want to avoid worrying about which type of data is coming from your database, you can simply not specify a datatype when you declare a variable, which defaults the datatype to variant. The variant should be avoided whenever possible, as it can be very CPU and memory intensive. Below is a table of the different MySQL and VB6 datatypes and how they correlate. One warning: often the VB6 datatype can hold a larger value than the MySQL equivalent (marked with a * in the notes section), in these situations you need to take care that the VB6 value is not to large to fit in the MySQL column. While you will not necesscarily get an error (you get a warning in the mysql client), data corruption will occur.

MySQL DatatypeLengthVB6 DatatypeLengthNotes
TINYINT-128 to 127integer-32,768 to 32,767*
TINYINT UNSIGNED0 to 255byte0 to 255 
SMALLINT-32,768 to 32,767integer-32,768 to 32,767 
SMALLINT UNSIGNED0 to 65,535long-2,147,483,647 to 2,147,483,647*
MEDIUMINT-8,388,608 to 8,388,607long-2,147,483,647 to 2,147,483,647*
MEDIUMINT UNSIGNED0 to 16,777,215long-2,147,483,647 to 2,147,483,647*
INT-2,147,483,647 to 2,147,483,647long-2,147,483,647 to 2,147,483,647 
INT UNSIGNED0 to 4,294,967,295double64 Bit1*
BIGINT64 BitN/AN/A2
FLOAT32 Bit Floating Pointsingle32 Bit Floating Point 
DOUBLE64 Bit Floating Pointdouble64 Bit Floating Point 
DECIMALVariable Floating Pointdouble64 Bit Floating Point3*
CHAR1 to 255 Charactersstring1 to Approx. 2,000,000,000 Characters*
VARCHAR1 to 255 Charactersstring1 to Approx. 2,000,000,000 Characters*
TINYTEXT1 to 255 Charactersstring1 to Approx. 2,000,000,000 Characters*
TEXT1 to 65535 Charactersstring1 to Approx. 2,000,000,000 Characters4*
MEDIUMTEXT1 to 16,777,215 Charactersstring1 to Approx. 2,000,000,000 Characters4*
LONGTEXT1 to 4,294,967,295 CharactersN/AN/A5
all BLOB types1 to 4,294,967,295 BytesVariantVaries6
DATEDate without Timedate Date and Time value*
DATETIMEDate and Timedate Date and Time value 
TIMESTAMPDate and Timedate Date and Time value 
TIMETimedate Date and Time value*
YEARYearinteger-32,768 to 32,767*
ENUMEnumeration of Value Setstring1 to Approx. 2,000,000,000 Characters*
SETSet of Valuesstring1 to Approx. 2,000,000,000 Characters*

Notes:

1) There is no such thing as a 32 bit unsigned integer in VB, so data must be stored in a double, which is actually a floating-point datatype, therefore, be careful to make sure that any value that you will be passing to MySQL is rounded off before you post it. The use of an UNSIGNED INT with VB6 is not reccomended, but you may have some luck with the larger integers of VB.NET.

2) BIGINT cannot be used with ADO, as it will cause errors, you can use the MyODBC option of 16384 (convert BIGINT to INT) to make them funnel down, but from what I understand your BIGINT is then limited to the size of an INT anyway. If a BIGINT is brought into a long, you will be ok up to the limit if the long datatype, after which your data will be corrupted.

3) DECIMAL can be passed to different VB6 Datatypes depending on how you define the DECIMAL column when creating the table. I personally would recommend staying away from the DECIMAL type, as it takes 1 byte per digit for storage, you are better off using the appropriate numeric type.

4) If you have trouble loading TEXT and MEDIUMTEXT values from a recordset, make sure your max_allowed_packet parameter in MySQL is set appropriately high. I have been able to load text from a MEDIUMTEXT object up to the max_allowed_packet limit set in my server.

5) LONGTEXT data cannot be held in a string, and would need to be treated as a BLOB and written directly to a file using the BLOB handling methods. If using the stream object, change the stream type to adTypeText instead of adTypeBinary.

6) All blob data must be passed using either the getchunk/appendchunk method, or the ADO stream object. The variant in this case becomes a byte array, and cannot be handled directly by VB6.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值