2

I have 2 columns of type VARCHAR(1000) and type TEXT in a SQLite db. My requirement is to store the values in an array into the db. I tried storing the values in the array into a string using the for loop but once the control comes out of the for loop the values displayed for the string is only the last element in the array...

Is there any way using which I can directly store the array into the DB??

Below is my code:

NSString *tempVal=0, *tempFlag=0;
NSString *temp[256], *Flag[256];

    for(int i=0; i<256; i++)
    {
    NSLog(@"HELLO %d", tempVal);
        temp[i] = (NSString*)valMines[i];
        Flag[i] = (NSString*)openFlag[i];

        NSLog(@"ValMines is %d", temp[i]);
        NSLog(@"OpenFlag is %d", Flag[i]);

        tempVal = temp[i];
        tempFlag == Flag[i];

        NSLog(@"ValMines is %d %d", temp[i], tempVal);
    }

NSLog(@"Inside Save Data func");
NSLog(@"ValMines is %d", tempVal);
NSLog(@"OpenFlag is %d", tempFlag);

Would append work on it? How?

2 Answers 2

1

According to this other post, SQLite does not support arrays directly. It only does ints, text and floats.

How to store array in one column in Sqlite3?

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

NSMutableString *tempVal = [NSMutableString stringWithCapacity:1000];
NSMutableString *tempFlag = [NSMutableString stringWithCapacity:256];

for (int i = 0; i < 256; i++)
{      
    NSLog(@"ValMines is %@", valMines[i]);
    NSLog(@"OpenFlag is %@", openFlag[i]);

    // adding a space between each string
    [tempVal appendFormat:@" %@", valMines[i]];
    [tempFlag appendFormat:@" %@", openFlag[i]];
}

NSLog(@"Inside Save Data func");
NSLog(@"ValMines is %@", tempVal);
NSLog(@"OpenFlag is %@", tempFlag);

1 Comment

No its not working... I think its taking some junked values and printing it out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.