=head1 DBD::mysql and DBD::mSQL =begin docbook =end docbook =head1 =head2 Version Versions 1.20xx and 1.21_xx. Version 1.20xx ( even numbers ) are the stable line, which is maintained for bug and portability fixes only. Version 1.21_xx ( odd numbers ) is used for development of the driver: All new features or interface modifications will be done in this line until it finally becomes 1.22xx. =head2 Author and Contact Details The driver author is Jochen Wiedmann. He can be contacted via the mailing list I. The drivers include modules that emulate the old Msql and Mysql Perl extensions using the DBI and DBD modules. =head2 Supported Database Versions and Options MySQL and mSQL are freely available lightweight database servers. MySQL has a rich feature set while mSQL is very minimalist. The C driver 1.20xx supports all MySQL versions since around 3.20. The C driver 1.21_xx supports MySQL 3.22 or later. Support for more recent versions may or may not be added at a later time. The C drivers 1.20xx and 1.21_xx support all mSQL versions upto and including mSQL 2.0.x. =head2 Connect Syntax The Cconnect()> Data Source Name, or I, can be one of the following: DBI:mysql:database=$db DBI:mysql:database=$db; DBI:mSQL:database=$db DBI:mSQL:database=$db; The optional attributes are specified as a semicolon separated list of key/value pairs. Some significant attributes include: =over 8 =item I The host name you want to connect to, by default I. =item I Load driver specific settings from the given file, by default F. This path is fixed at compile time. =item I For slow connections, you may wish to compress the traffic between your client and the engine. If the MySQL engine supports it, this can be enabled by using this attribute. Default is off. =back There are no driver specific attributes applicable to the C method. =head2 Numeric Data Handling MySQL has five sizes of integer data type, each of which can be signed (the default) or unsigned (by adding the word UNSIGNED after the type name). Name Bits Signed Range Unsigned Range --------- ---- ----------------------- ----------------------- TINYINT 8 -128..127 0..255 SMALLINT 16 -32768..32767 0..65535 MEDIUMINT 24 -8388608..8388607 0..16777215 INTEGER 32 -2147483648..2147483647 0..4294967295 BIGINT 64 -(2*63)..(2**63-1) 0..(2**64) The type INT can be used as an alias for INTEGER. Other aliases include FLOAT4=FLOAT, FLOAT8=DOUBLE, INT1=TINYINT, INT2=SMALLINT, INT3=MEDIUMINT, INT4=INT, INT8=BIGINT, MIDDLEINT=MEDIUMINT. Note that all arithmetic is done using signed BIGINT or DOUBLE values, so you shouldn't use unsigned big integers larger than the largest signed big integer (except with bit functions). Note that C<->, I<+>, and C<*> will use BIGINT arithmetic when both arguments are INTEGER values. This means that if you multiply two big integers (or multiply the results from functions that return integers), you may get unexpected results if the result is bigger than 9223372036854775807. MySQL has three main types of I data type: FLOAT, DOUBLE, and DECIMAL. In what follows, the letter C is used for the I or I in ODBC and DBI terminology. The letter C is used for the number of digits that may follow the decimal point. (I in ODBC or DBI terminology). Maximum display size (PRECISION) and number of fraction digits (SCALE) are typically not required. For example, if you use just "DOUBLE" then default values will be silently inserted. =over 8 =item C A normal-size (double-precision) floating-point number. Allowable values are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0 and 2.2250738585072014E-308 to 1.7976931348623157E+308. REAL and DOUBLE PRECISION can be used as aliases for DOUBLE. =item C A small (single-precision) floating-point number. Allowable values are -3.402823466E+38 to -1.175494351E-38, 0 and -1.175494351E-38 to 3.402823466E+38. =item C A floating-point number. Precision (I) can be 4 or 8. C is a single-precision number and C is a double-precision number. These types are like the FLOAT and DOUBLE types described above. C and C have the same ranges as the corresponding FLOAT and DOUBLE types, but their display size and number of decimals is undefined. This syntax is provided for ODBC compatibility. =item C The DECIMAL type is an unpacked floating-point number type. NUMERIC is an alias for DECIMAL. It behaves like a CHAR column; "unpacked" means the number is stored as a string, using one character for each digit of the value, the decimal point, and, for negative numbers, the C<-> sign). If I is 0, values will have no decimal point or fractional part. The maximum range of DECIMAL values is the same as for DOUBLE, but the actual range for a given DECIMAL column may be constrained by the choice of I and I. NUMERIC can be used as an alias for DECIMAL. =back The numeric data types supported by mSQL are much more restricted: INTEGER - corresponds to MySQL's INTEGER type. UINT - corresponds to MySQL's INTEGER UNSIGNED type. REAL - corresponds to MySQL's REAL type. The driver returns all data types, including numbers, as strings. It thus puts no restriction on size of PRECISION or SCALE. =head2 String Data Handling The following string types are supported by MySQL, quoted from F where I denotes the maximum display size or PRECISION: =over 8 =item CHAR(I) A fixed-length string that is always right-padded with spaces to the specified length. The range of I is 1 to 255 characters. =item VARCHAR(C) A variable-length string. NOTE: Trailing spaces are removed by the database when the value is stored (this differs from the ANSI SQL specification). The range of I is 1 to 255 characters. =item ENUM('I','I',...) An enumeration. A string object that can have only one value, chosen from the specified list of values (or NULL). An ENUM can have a maxiumum of 65535 distinct values. =item SET('I','I',...) A set. A string object that can have zero or more values, each of which must be chosen from the specified list of values. A SET can have a maximum of 64 members. =back CHAR and VARCHAR types have a limit of 255 bytes. Binary characters, including the NUL byte, are supported by all string types. (Use the C<$dbh-Equote()> method for literal strings). These aliases are also supported: BINARY(num) CHAR(num) BINARY CHAR VARYING VARCHAR LONG VARBINARY BLOB LONG VARCHAR TEXT VARBINARY(num) VARCHAR(num) BINARY With C, the I attribute is always on: The MySQL engine itself removes spaces from the strings right end. As far as I know, this "feature" cannot be turned off. Another "feature" is that CHAR and VARCHAR columns are always case-insensitive in comparisons and sort operations, unless you use the I attribute, as in: CREATE TABLE foo (A VARCHAR(10) BINARY) With versions of MySQL after 3.23, you can perform a case-insensitve comparison of strings with the BINARY operator modifier: SELECT * FROM table WHERE BINARY column = "A" National language characters are handled in comparisons following the coding system that was specified at compile-time, by default ISO-8859-1. Non-ISO coding systems, and in particular UTF-16, are not supported. Strings can be concatenated using the C SQL function. The mSQL engine (and hence the C driver) only supports the CHAR(I) string type, which corresponds to the MySQL's VARCHAR(I) type, and a TEXT(I) type which is a cross between a CHAR and a BLOB. Also, mSQL has no way to concatenate strings. =head2 Date Data Handling The following date and time types are supported by MySQL, quoted from F: =over 8 =item DATE A date. The supported range is C<0000-01-01> to C<9999-12-31>. MySQL displays I values in C format, but allows you to assign values to I columns using these formats: YYMMDD YYYYMMDD YY.MM.DD YYYY.MM.DD Where C<.> may be any non-numerical separator and a two digit year is assumed to be 20I if I is less than 70. =item DATETIME A date and time combination. The supported range is C<0000-01-01 00:00:00> to C<9999-12-31 23:59:59>. MySQL displays I values in B format, but allows you to assign values to I columns using the formats shown for DATE above but with " HH:MM:SS" appended. =item TIMESTAMP(I) A timestamp. The range is B<1970-01-01 00:00:00> to sometime in the year 2032 (or 2106, depending on the OS specific type I). MySQL displays I values in C, C, C, or C format, depending on whether I is 14 (or missing), 12, 8 or 6, but allows you to assign values to I columns using either strings or numbers. This output format behavior disagrees with the manual, so check your version because the behavior may change. A I column is useful for recording the time of an I or I operation because it is automatically set to the time of the last operation if you don't give it an value yourself. You can also set it to the current time by giving it a I value. =item TIME A time. The range is -838:59:59 to 838:59:59. MySQL displays I