0

(MySQL Version 5.6.36)

We have many tables in our database that have columns typed as INT. I was just running a linq query against the resultant DataTable from our currency table... and was implicitly casting the id field as int.

A "Specified cast is not valid" exception happened.

So I decided to run a standard foreach on the datarows, getting the type of the id column... sure enough it was being returned as an INT64.

This led me further down into the rabbit hole... I opened up a console, and started up the mysql command line, with the option --column-type-info turned on... and did a simple query.

mysql> select id from currency;
Field   1:  `id`
Catalog:    `def`
Database:   `intranet`
Table:      `currency`
Org_table:  `currency`
Type:       LONG
Collation:  binary (63)
Length:     11
Max_length: 1
Decimals:   0
Flags:      NOT_NULL PRI_KEY AUTO_INCREMENT NUM PART_KEY


+----+
| id |
+----+
|  1 |
|  2 |
|  3 |
+----+
3 rows in set (0.00 sec)

This is the Describe:

+----------+------------+------+-----+---------+----------------+
| Field    | Type       | Null | Key | Default | Extra          |
+----------+------------+------+-----+---------+----------------+
| id       | int(11)    | NO   | PRI | NULL    | auto_increment |
| currency | varchar(3) | YES  |     | NULL    |                |
| per_usd  | double     | YES  |     | NULL    |                |
+----------+------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

And the Create:

CREATE TABLE `currency` (  `id` int(11) NOT NULL AUTO_INCREMENT,
  `currency` varchar(3) DEFAULT NULL,
  `per_usd` double DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1

But this isn't limited to just this one table... all tables are showing INT, but returning LONG.

I've changed the id column to a MEDIUMINT in my testing, and instead of a LONG, it then returns an INT24.

Just wonder if there is something simple I am missing?

matthyde
  • 1
  • 1

1 Answers1

0

Just delete that table and create a new one which you add unsigned to the id definition

CREATE TABLE  currency (

id int(11) unsigned NOT NULL AUTU_INCREMENT,

// the other definitions 

);

Hope you get the point. Sorry I am writing from my phone.

hans-könig
  • 553
  • 8
  • 10
  • Unsigned or not, it still returns the same: `Type: LONG` – matthyde Jun 02 '17 at 15:32
  • I've read your question again and found that all tables are returning LONG. I have done some reading and found that LONG data type is an ORACLE thing. I have even checked my MYSQL database and there is nothing there as LONG data type. I was trying to say that may be your database is ORACLE but your code is showing MYSQL. I'm just baffled. – hans-könig Jun 03 '17 at 08:44