Saturday, 24 September 2016

MySQL: case sensitivity



I have a very complicated problem.
The dev team wrote a SQL script using jdbc (case sensitive), which searches for a table in MySQL. But in MySQL, the table is written in lower case, so it throws an error.



The problem is the dev team do not accept to change the table name to lowercase, and the exploitation team do not accept to change the table name to uppercase.




I know we can use lower_case_table_names to 1 to force the case to insensitive, but I do not have the permission to restart mysqld.



What should I do?


Answer



Create view with Uppercase name 

mysql> select * from f_val;
ERROR 1146 (42S02): Table 'TEST.f_val' doesn't exist
mysql> select * from F_VAL;
+------+------+------+--------+-------+-------+

| ID | F_ID | DATE | I | II | III |
+------+------+------+--------+-------+-------+
| 1 | 11 | 1/26 | peanut | where | Now |
| 2 | 22 | 1/26 | butter | he | there |
| 3 | 11 | 1/27 | jelly | at | he |
| 4 | 33 | 1/27 | time | huh | go |
| 1 | 11 | 1/25 | cake | where | Now |
+------+------+------+--------+-------+-------+
5 rows in set (0.01 sec)


CREATE VIEW f_val AS SELECT * FROM F_VAL;

select * from f_val;
+------+------+------+--------+-------+-------+
| ID | F_ID | DATE | I | II | III |
+------+------+------+--------+-------+-------+
| 1 | 11 | 1/26 | peanut | where | Now |
| 2 | 22 | 1/26 | butter | he | there |
| 3 | 11 | 1/27 | jelly | at | he |
| 4 | 33 | 1/27 | time | huh | go |

| 1 | 11 | 1/25 | cake | where | Now |
+------+------+------+--------+-------+-------+
5 rows in set (0.00 sec)

mysql> INSERT INTO f_val(ID,F_ID,DATE) VALUES(10,10,"1/25")
-> ;
Query OK, 1 row affected (0.08 sec)

select * from f_val;
+------+------+------+--------+-------+-------+

| ID | F_ID | DATE | I | II | III |
+------+------+------+--------+-------+-------+
| 1 | 11 | 1/26 | peanut | where | Now |
| 2 | 22 | 1/26 | butter | he | there |
| 3 | 11 | 1/27 | jelly | at | he |
| 4 | 33 | 1/27 | time | huh | go |
| 1 | 11 | 1/25 | cake | where | Now |
| 10 | 10 | 1/25 | NULL | NULL | NULL |
+------+------+------+--------+-------+-------+
6 rows in set (0.00 sec)


mysql> SELECT * FROM F_VAL;
+------+------+------+--------+-------+-------+
| ID | F_ID | DATE | I | II | III |
+------+------+------+--------+-------+-------+
| 1 | 11 | 1/26 | peanut | where | Now |
| 2 | 22 | 1/26 | butter | he | there |
| 3 | 11 | 1/27 | jelly | at | he |
| 4 | 33 | 1/27 | time | huh | go |
| 1 | 11 | 1/25 | cake | where | Now |

| 10 | 10 | 1/25 | NULL | NULL | NULL |
+------+------+------+--------+-------+-------+
6 rows in set (0.01 sec)

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...