2013-07-14 71 views
0

我有创建的表像这样一个SQL查询:Ruby脚本包含值(10,8)

db.execute ("CREATE TABLE IF NOT EXISTS RATING (programCode INTEGER , fromDate INTEGER, 
toDate INTEGER, programName TEXT, channelName TEXT, weekday TEXT, startTime TEXT, 
endTime TEXT, duration TEXT, episodeName TEXT, Ind2 DECIMAL(4,2), A18 DECIMAL(4,2), M18 
DECIMAL(4,2), F18 DECIMAL(4,2), A18_24 DECIMAL(4,2), M18_24 DECIMAL(4,2), A18_34 
DECIMAL(4,2), M18_34 DECIMAL(4,2), F18_34 DECIMAL(4,2), A18_49 DECIMAL(4,2), M18_49 
DECIMAL(4,2), F18_49 DECIMAL(4,2), A25_34 DECIMAL(4,2) , M25_34 DECIMAL(4,2), A25_49 
DECIMAL(4,2), M25_49 DECIMAL(4,2), F25_49 DECIMAL(4,2), A25_54 DECIMAL(4,2), M25_54 
DECIMAL(4,2), F25_54 DECIMAL(4,2), A35_plus DECIMAL(4,2), M35_plus DECIMAL(4,2), 
F35_plus DECIMAL(4,2), M35_49 DECIMAL(4,2), F35_49 DECIMAL(4,2), A35_54 DECIMAL(4,2), 
M35_54 DECIMAL(4,2), F35_54 DECIMAL(4,2), A35_64 DECIMAL(4,2), M35_64 DECIMAL(4,2), 
F35_64 DECIMAL(4,2), A50_plus DECIMAL(4,2), M50_plus DECIMAL(4,2), F50_plus 
DECIMAL(4,2), C2_11 DECIMAL(4,2), T12_17 DECIMAL(4,2), V12_24 DECIMAL(4,2), PRIMARY 
KEY(programCode,fromDate , toDate))") 

然而,当我检查表数据,除2个单元格(10,8)外,所有行和列都有十进制值(4,2)。

我不明白什么可能导致这种情况,以及如何解决这个问题!

见附件图像

enter image description here


我改变了我的查询到以下几点:

db.execute ("INSERT INTO RATING (programCode, fromDate, toDate, programName, channelName, weekday, startTime, endTime, duration, episodeName, 
    Ind2 , A18 , M18, F18, A18_24, M18_24, A18_34, M18_34 , F18_34, A18_49 , M18_49, F18_49, A25_34 , M25_34 , A25_49 , M25_49, F25_49 , A25_54 , 
    M25_54, F25_54, A35_plus , M35_plus , F35_plus , M35_49, F35_49 , A35_54 , M35_54 , F35_54 , A35_64 , M35_64 , F35_64 , A50_plus , M50_plus , 
    F50_plus , C2_11 , T12_17 , V12_24) VALUES ('#{progCode}', '#{fromD}', '#{toD}', '#{arr[0]}', '#{arr[1]}','#{arr[2]}','#{arr[3]}','#{arr[4]}','#{arr[5]}','#{arr[6]}', 
    '#{arr[45].to_f.round(2)}','#{arr[46].to_f.round(2)}','#{arr[47].to_f.round(2)}','#{arr[48].to_f.round(2)}','#{arr[49].to_f.round(2)}','#{arr[50].to_f.round(2)}','#{arr[51].to_f.round(2)}','#{arr[52].to_f.round(2)}','#{arr[53].to_f.round(2)}','#{arr[54].to_f.round(2)}','#{arr[55].to_f.round(2)}', 
    '#{arr[56].to_f.round(2)}','#{arr[57].to_f.round(2)}','#{arr[58].to_f.round(2)}','#{arr[59].to_f.round(2)}','#{arr[60].to_f.round(2)}','#{arr[61].to_f.round(2)}','#{arr[62].to_f.round(2)}','#{arr[63].to_f.round(2)}','#{arr[64].to_f.round(2)}','#{arr[65].to_f.round(2)}','#{arr[66].to_f.round(2)}', 
    '#{arr[67].to_f.round(2)}','#{arr[68].to_f.round(2)}','#{arr[69].to_f.round(2)}','#{arr[70].to_f.round(2)}','#{arr[71].to_f.round(2)}','#{arr[72].to_f.round(2)}','#{arr[73].to_f.round(2)}','#{arr[74].to_f.round(2)}','#{arr[75].to_f.round(2)}','#{arr[76].to_f.round(2)}','#{arr[77].to_f.round(2)}', 
    '#{arr[78].to_f.round(2)}','#{arr[79].to_f.round(2)}','#{arr[80].to_f.round(2)}','#{arr[81].to_f.round(2)}');") 

但问题仍然存在

回答

2

SQLite不支持所有的数据库类型 - 小数(...)被翻译成真正的类型,然后遭遇舍入问题。你需要用你使用SQLite的语言来处理这个问题。

SQLite Datatypes