0

I have a sql query that created a table like so:

 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))")

However when I check the table data, all rows and columns have decimal values (4,2) except for 2 cells which have (10,8).

I dont understand what could be causing this and how to remedy this!

See the attached image

enter image description here


I changed my query to the following:

 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)}');")

But the problem still remains

mu is too short
  • 426,620
  • 70
  • 833
  • 800
banditKing
  • 9,405
  • 28
  • 100
  • 157

1 Answers1

2

SQLite does not support all the database types - decimal(...) is translated into the real type and then suffers from rounding issues. You need to cope with this in the language you are using SQLite from.

SQLite Datatypes

CL.
  • 173,858
  • 17
  • 217
  • 259
noz
  • 1,863
  • 13
  • 14