Sqlite database table: can an array become one record column?
I am developing an iPhone application that needs to store data in a Sqlite database.
One table entry looks like
@interface Record:NSObject {
NSInteger primaryKey;
NSString *name;
NSInteger priority;
NSMutableArray *items;
};
Note that one column in the record is an array, and the size of the array is not fixed. The size can be zero or any positive integer.
My question is, when I create a Sqlite table, can I specify the array as one record column? If not, how do I create this table?
UPDATE: Thanks for your reply. The answer to my question seems to be NO. If so, can I use other archive methods, say Property List or NSKeyedArchiver, to implement this?
You cannot do this and be normalized. Your own βuncorrectedβ size requirement tells you that this is not possible. This is true no matter how you code it or what data structure you choose. This is the nature of relational databases. You want to read about normalization to fully understand it.
It looks like the relationship between foreign keys is one-to-many. You will need one table for the record and another for any object in that array. The second table will have a foreign key that points to the primary key of the first.
I would recommend a more descriptive name than "Entry". This seems too general to me.
a source to share