0

I have interfaced SQLite3 with my Am1808 processor. I store my data in the SDcard.

It is working very fine. I have inserted a table for 38 fields. Now I want to add a column in the same table. So I have changed the table fields parameters, and make the changes accordingly in the related files. My code successfully compiled but when I execute the application it gives me the following error:

Error : "38 columns for 39 Values"

Here is the Table which I have created with modification:

const char *SQL_CREATE_ABCTABLE   = "CREATE TABLE IF NOT EXISTS MilkCollection   \
                (  MilkCollectionId        INTEGER,  \
                   CollectionDate          DATE,  \
                   CollectionShift         UNSIGNED TINYINT,  \
                   MemberId                INTEGER REFERENCES Member(MemberId) ON UPDATE RESTRICT ON DELETE RESTRICT,  \
                   SocietyId               INTEGER REFERENCES Society(SocietyId) ON UPDATE RESTRICT ON DELETE RESTRICT,  \
                   SampleNo                UNSIGNED INTEGER,  \
                   MilkType                UNSIGNED TINYINT,  \
                   Qty                     FLOAT, \
                   ActualQty               FLOAT, \
                   QtyType                 UNSIGNED TINYINT,  \
                   Fat                     FLOAT, \
                   ActualFat               FLOAT, \
                   LRCLR                   FLOAT, \
                   ActualLRCLR             FLOAT, \
                   SNF                     FLOAT, \
                   ActualSNF               FLOAT, \
                   Solid                   FLOAT, \
                   ActualSolid             FLOAT, \
                   Water               FLOAT, \ // I have inserted this field   
                   FatKG                   FLOAT, \
                   ActualFatKG             FLOAT, \
                   SNFKG                   FLOAT, \
                   ActualSNFKG             FLOAT, \
                   Rate                    FLOAT, \
                   Amount                  FLOAT, \
                   ActualAmount            FLOAT, \
                   CanNumber               UNSIGNED INTEGER, \
                   MemberCodeAuto          UNSIGNED TINYINT, \
                   WeightAuto              UNSIGNED TINYINT, \
                   FatAuto                 UNSIGNED TINYINT, \
                   LRCLRAuto               UNSIGNED TINYINT, \
                   SNFAuto                 UNSIGNED TINYINT, \
                   EntryMode               UNSIGNED TINYINT, \
                   CreatedBy               INTEGER REFERENCES UserMaster(UsermasterId) ON UPDATE RESTRICT ON DELETE RESTRICT, \
                   CreatedOn               DATE, \
                   UpdatedBy               INTEGER REFERENCES UserMaster(UsermasterId) ON UPDATE RESTRICT ON DELETE RESTRICT, \
                   UpdatedOn               DATE, \
                   FlagGSM                 UNSIGNED TINYINT, \
                   FlagUSB                 UNSIGNED TINYINT, \
                   PRIMARY KEY (MilkCollectionId) )";

After creating this table I delete the old database file.

I am still getting this error.

jonsca
  • 10,218
  • 26
  • 54
  • 62
  • `x columns for y values` is not an SQLite error message. Please show the code and the query where you get this error. – CL. Oct 06 '12 at 07:45

3 Answers3

0

In your INSERT command, you have 39 column names, but only 38 NULL/? values.

CL.
  • 173,858
  • 17
  • 217
  • 259
  • const char *INSERT_MILKCOLLECTIONTABLE = "INSERT INTO MilkCollection ( MilkCollectionId, CollectionDate, CollectionShift, MemberId, SocietyId,SampleNo, MilkType, Qty, ActualQty, QtyType, Fat, ActualFat, LRCLR, ActualLRCLR, SNF, ActualSNF, Solid, ActualSolid, Water, FatKG, ActualFatKG, SNFKG, ActualSNFKG, Rate, Amount, ActualAmount, CanNumber, MemberCodeAuto, WeightAuto, FatAuto, LRCLRAuto, SNFAuto, EntryMode, CreatedBy, CreatedOn, UpdatedBy, UpdatedOn, FlagGSM, FlagUSB) VALUES(NULL,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NULL,?,?,?)";This is a query for data insertion – Parthiv Shah Oct 06 '12 at 09:05
  • This belongs into the question. – CL. Oct 06 '12 at 09:16
  • Oh wow i got the solution. Thank you.But i want to know that why this values are needed ? Means why we have to assign such values (?, NUll ) for each field ? – Parthiv Shah Oct 06 '12 at 09:49
  • You need exactly one value for each column that is listed. But you can omit columns, so that they will get NULL implicitly; see [the documentation](http://www.sqlite.org/lang_insert.html). – CL. Oct 06 '12 at 09:53
0

CREATE TABLEIF NOT EXISTS

You changed the SQL DDL command to create the table, but the new command never ran because the table already existed.

You need to check whether the schema is correct, export the data, drop or rename the table, create the table with the new correct column list, and import the old data (providing appropriate values for new columns).

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
0

Good to know that you integrated SQLlite with AM1808 processor. Currently i'm working on same thing. kindly let me know how to get source for SQLlite, how to compile it for our processor and example application from c to create,insert table etc.

chainz
  • 253
  • 1
  • 2
  • 8