- /**
- * Retrieve the maximum string length allowed in a given column.
- *
- * @since 4.2.1
- * @access public
- *
- * @param string $table Table name.
- * @param string $column Column name.
- * @return mixed Max column length as an int. False if the column has no
- * length. WP_Error object if there was an error.
- */
- public function get_col_length( $table, $column ) {
- $tablekey = strtolower( $table );
- $columnkey = strtolower( $column );
-
- // Skip this entirely if this isn't a MySQL database.
- if ( false === $this->is_mysql ) {
- return false;
- }
-
- if ( empty( $this->col_meta[ $tablekey ] ) ) {
- // This primes column information for us.
- $table_charset = $this->get_table_charset( $table );
- if ( is_wp_error( $table_charset ) ) {
- return $table_charset;
- }
- }
-
- if ( empty( $this->col_meta[ $tablekey ][ $columnkey ] ) ) {
- return false;
- }
-
- $typeinfo = explode( '(', $this->col_meta[ $tablekey ][ $columnkey ]->Type );
-
- $type = strtolower( $typeinfo[0] );
- if ( ! empty( $typeinfo[1] ) ) {
- $length = trim( $typeinfo[1], ')' );
- } else {
- $length = false;
- }
-
- switch( $type ) {
- case 'binary':
- case 'char':
- case 'varbinary':
- case 'varchar':
- return $length;
- break;
- case 'tinyblob':
- case 'tinytext':
- return 255; // 2^8 - 1
- break;
- case 'blob':
- case 'text':
- return 65535; // 2^16 - 1
- break;
- case 'mediumblob':
- case 'mediumtext':
- return 16777215; // 2^24 - 1
- break;
- case 'longblob':
- case 'longtext':
- return 4294967295; // 2^32 - 1
- break;
- default:
- return false;
- }
-
- return false;
- }
-