mysql

Rails sees mysql tinyint(1) as a boolean - but I want it to be a number

我与影子孤独终老i 提交于 2021-02-19 03:43:09
问题 Rails 4.2.1 using mysql2 gem. ActiveRecord treats a mysql column with data type tinyint(1) as a boolean. But I want to use it as a small number - I want to store values up to 100 which is ok for tinyint(1) . When I try to create a record, the tinyint column casts to false and I get a depreciation warning: > Foo.create(my_tinyint_col: 13) (0.2ms) BEGIN SQL (0.5ms) INSERT INTO `foos` (`my_tinyint_col`) VALUES (0) (107.3ms) COMMIT => #<Foo ID: 519, my_tinyint_col: false> DEPRECATION WARNING: You

SQL: How to select rows that sum up to certain value

寵の児 提交于 2021-02-19 03:43:07
问题 I want to select rows that sum up to a certain value. My SQL (SQL Fiddle): id user_id storage 1 1 1983349 2 1 42552 3 1 367225 4 1 1357899 37 1 9314493 It should calculate the sum up to 410000 and get the rows. Meanwhile it should get something like this: id user_id storage 2 1 42552 3 1 367225 As you can see, 42552 + 367225 = 409777. It selected two rows that are nearly 410000. I have tried everything but it didn't work :( Sorry for my language, I am German. 回答1: You can use a correlated

Does MySQL Workbench automatically create indexes for foreign keys?

与世无争的帅哥 提交于 2021-02-19 03:31:06
问题 When I create a foreign key in MySQL workbench, a new entry appears on the "Indexes" tab with the exact same same as the foreign key that I just created. Is this actually the foreign key, showing up on the "Indexes" tab for some reason? Or does MySQL Workbench try to be helpful and create an index for me, knowing that I'm likely to be selecting against that column, and give it (confusingly) the same name as the foreign key? 回答1: It's MySQL doing that, not workbench. And yes, it is being

MySQL foreach loop

五迷三道 提交于 2021-02-19 02:59:06
问题 I have to iterate each row in my table User in MySQL. I need to create a new row Address for each iteration in User with some conditions described below. I have 3 tables: User: id, stuff, id_person, email Person: id, stuff, id_address Address: id, email I need to create a new row in Address if the User.id_person is NOT NULL and that person.id_address IS NULL. I have to create the row with the same email that User.email. I have to do that for each row in User. I tried to use MySQL cursor's but

ResultSetImpl throws NullPointerException

天涯浪子 提交于 2021-02-19 02:29:10
问题 i'm running mysql 5.5 with mysql 5.1.18 connector. a simple query of style select * from my_table where column_a in ('aaa','bbb',...) and column b=1; is executed from within java application. the query returns a resultset of 25k rows, 8 columns in each. while reading the results in while loop while(rs.next()) { MyObject c= new MyObject(); c.setA(rs.getString("A")); c.setB(rs.getString("B")); c.setC(rs.getString("C")); ... } a following exception is thrown, usually during the first loops, but

Mysql select for update - it is not locking the target rows. How do I make sure it does?

守給你的承諾、 提交于 2021-02-19 02:22:26
问题 So the syntax for select for update is something like SELECT * //1st query FROM test WHERE id = 4 FOR UPDATE; UPDATE test //2nd query SET parent = 100 WHERE id = 4; I am guessing the locking part is the first line. So when the first set of queries executes, I should not be able to select and modify the row with id = 4 (it is primary key by the way). However, I am still able to select row with id = 4 before I update anything, meaning another thread could probably come in and try to select and

Is there any legitimate reason for using Unix sockets over TCP/IP with mysql?

会有一股神秘感。 提交于 2021-02-19 02:12:53
问题 I'm trying to figure out why mysql uses Unix socket (/tmp/mysql.sock) by default, instead of normal TCP/IP sockets. It doesn't seem like a security thing, as you can listen only on 127.0.0.1 which should be equally safe (socket file is world-writable, so you don't get Unix accounts based protection). And surely all operating systems rely on high performance TCP/IP so much that it cannot be significantly slower than Unix sockets - Linux does all sort of zero-copy tricks even for network

Having a mySQL error, unknown column where clause [duplicate]

强颜欢笑 提交于 2021-02-19 01:45:07
问题 This question already has answers here : When to use single quotes, double quotes, and backticks in MySQL (13 answers) Closed 6 years ago . I am currently having a problem selecting a certain item from a mySQL database. My program is designed to pass a parameter from an android application to a servlet which then queries the database. However an error appears on the console window: Unknown column '0102310c24' in 'where clause' There is only an error when the value I want to select contains a

洋哥!我要进大厂!

China☆狼群 提交于 2021-02-19 01:43:13
阅读本文大概需要4分钟。 最近不少读者咨询洋哥如何进大厂,回答的多了就想着要不整理出一个系列文章出来。 说干就干,第一期先写写应届毕业和刚工作不久的计算机专业的童鞋如何进大厂。 先说说必须要做到的几件事: 第一,学校内的课程,计算机基础知识,如C语言,数据结构,计算机组成原理,计算机网络,计算机操作系统等这些基础专业知识一定要理解掌握,在校招中,这些内容必考。 第二,提升自己写代码的能力。不会配置环境,不会框架,就去找资料自学,B站,慕课很多免费视频课程。 第三,做项目。这里不是指学校做的项目,而是真正可以部署上线的项目。你可以去GitHub上找,也可以从学长学姐或者老师看是否有合适的项目,或者找一些大厂实习岗位。 第四,疯狂刷算法题。leetcode上的题目很多都可能在校招中被拿来当面试题,《剑指Offer》也挺不错,leetcode最起码刷个200,300道,然后把《剑指Offer》背一遍,基本没大问题了。 以上基础,如果读书期间没有打牢固,工作后也必须想办法拼命学习。 再说说我应届毕业加入腾讯的学习路线吧: 首先攻克C语言,这个没什么,谭浩强的《C语言程序设计》反复看,然后一行行在电脑上敲出来。 当时对计算机缺乏系统认识,最难理解的就是指针,书上说它是个变量地址,那么问题来了,什么是地址?一不小心,指针就让程序Crash了。直到读研的时候,看了大学教材:《计算机组成原理

Mysql Query issues using LIKE and apostrophe

主宰稳场 提交于 2021-02-19 01:32:23
问题 So I have an interesting issue that I have never come across and can't seem to find much information about correcting the issue. I have massive database that has an enormous amount of data in it (10 years worth), and attempting to search through it. Now the search stuff works fine, but recently someone brought it to my attention about a 'bug' if you will. I've tried to trouble shoot it to get the expected results, but to no avail. This is my issue: When someone uses an apostrophe in the