1

I am working on an iOS application that uses a SQLite database.

In the next release of my product, i would like to migrate a table column from TEXT to BLOB. I plan to do a DROP TABLE followed by a CREATE TABLE (we can afford to lose the data, it is not an issue here)

My problem is : how can I check simply from Objective-C if a table's column type is TEXT or BLOB ?

4

2 回答 2

2

SQLite is "typeless". This means that you can store any kind of data you want in any column of any table, regardless of the declared data type of that column. You can find more info here.

But, if you want to get the info about the declared data type of a column, you can do that by using the pragma table_info(table_name).

eg.

pragma table_info(Setting);

Then , you can iterate through the returned resultset and check for the data type you want to check.

于 2012-06-18T09:28:07.917 回答
1

Why do you need this check? You can catch first start after release (use settings for this) and update your table, it will be easier

checking first start after release:

NSUserDefaults *prefs=[NSUserDefaults standardUserDefaults];        
BOOL flag=[prefs boolForKey:SETTINGS_ALREDY_RAN];//will be NO if settings hasn't those parameters, you can change it to version number
于 2012-06-18T08:45:54.547 回答