Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6201325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:31:59+00:00 2026-05-24T04:31:59+00:00

In my SQLite database only one row effect but I want effect 4 rows

  • 0

In my SQLite database only one row effect but I want effect 4 rows at a time. My code is working for one row, not for other value save. How to write the code for saving multiple rows in SQLite?

I create application for weather. I get all weather condition information by XML parsing, I parse all value in table view I see all value. This is all proper.

In XML file I get current condition element and three forecast condition it mean current condition it show today weather condition and forecast condition show next 3 days of weather conditions. I create for fetch this data .3class with name currentcondition and forecastcondition.

In forecastcondition element I have same name of next 3day element name means element name same forecastcondition I store all forecast condition value in array for take value one by one of next 3day value show it working proper in table cell. I see current condition value on 1cell and all next 3forecastcondition display in next 3cell my code is proper working but now I want store first cell value and next 3day value cell in sqlite database table at a time but how can I store?

But I save currentcondition in SQLite because I create object of currentcondition class then I pass value to SQLite. So how to parse another cell value at same time? My table is one and which I give all column name in attach file; I want insert value in this table column only.

I write this code for store SQLite please check the code. This my controller class where I display value on cell here only I wrirten code for SQLite for save data.

    //
    //  TWeatherController.m
    //  Journey
    //
    //  Created by pradeep.yadav on 5/3/11.
    //  Copyright 2011 __MyCompanyName__. All rights reserved.
    //

    #import "TWeatherController.h"
    #import "TWeatherCell.h"
    #import "ForecastInfoParser.h"
    #import "global.h"
    #define DATABASE_NAME @"test.sqlite"
    #define DATABASE_TITLE @"test"
    #import <sqlite3.h>



    @implementation TWeatherController
    @synthesize MyTableView;
    @synthesize forecastcond;

    #pragma mark -
    #pragma mark View lifecycle







    - (NSString *) getWritableDBPath {

        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
        NSString *documentsDir = [paths objectAtIndex:0];
        return [documentsDir stringByAppendingPathComponent:DATABASE_NAME];
    }

    -(void)createEditableCopyOfDatabaseIfNeeded 
    {
        // Testing for existence
        BOOL success;
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSError *error;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                             NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:DATABASE_NAME];
        NSLog(@"%@",writableDBPath);

        success = [fileManager fileExistsAtPath:writableDBPath];
        if (success)
            return;

        // The writable database does not exist, so copy the default to
        // the appropriate location.
        NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath]
                                   stringByAppendingPathComponent:DATABASE_NAME];
        success = [fileManager copyItemAtPath:defaultDBPath
                                       toPath:writableDBPath
                                        error:&error];
        if(!success)
        {
            NSAssert1(0,@"Failed to create writable database file with Message : '%@'.",
                      [error localizedDescription]);
        }
    }


    -(BOOL) insertData

    { 
     [self createEditableCopyOfDatabaseIfNeeded];
     //NSString *filePath = [self getWritableDBPath];
        BOOL value = NO; 

        @try { 

            sqlite3 *database; 
            if (sqlite3_open([[self getWritableDBPath] UTF8String], &database) != SQLITE_OK)
            { 
                sqlite3_close(database); 
            } 
            else { 
                NSString *nsQuery = [[NSString alloc] initWithFormat:@"INSERT INTO weather (ReportDate,conditionname,humidity,maxtemp,mintemp,wind) VALUES('%@','%@','%@','%@','%@','%@')" ,_forecastInfo.CurrentDateTime,currentcond.Condition,currentcond.Tempf,currentcond.Tempf,currentcond.WindCondition,currentcond.Humidity]; 
                const char *query = [nsQuery UTF8String]; 
                [nsQuery release]; 

                sqlite3_stmt *statement; 
                int errorCode = sqlite3_prepare_v2(database, query, -1, &statement, NULL); 
                if(errorCode == SQLITE_OK) { 
                    int result = sqlite3_step(statement); 
                    if(result == SQLITE_DONE) { 
                        value = YES; 
                        sqlite3_finalize(statement); 
                    } 
                } 
                sqlite3_close(database); 
            } 
        } 
        @catch (NSException *exception) { 
            NSLog(@"Error encountered while reading facts: %@", [exception reason]); 
        } 
        return value; 
    }

    - (void)viewDidLoad {
        [super viewDidLoad];
        _forecastInfo=nil;
        currentcond=nil;
        forecastcond=nil;
        NSString *URL=@"http://www.google.com/ig/api?weather=,,,50500000,30500000"; 
        NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:URL]]; 
        NSURLResponse *resp = nil; 
        NSError *err = nil; 
        NSData *response = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: &resp error: &err];
        NSString * theString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; 
        //[resp release]; 
        [err release]; 
        NSLog(@"response: %@", theString);    
        ForecastInfoParser *parser=[[ForecastInfoParser alloc]init];
        parser.delegate=self;
        [parser parseData:response];


        //[self selected];
        [self insertData];


    }


    -(void)forecastInfoParser:(ForecastInfoParser*)parser parsed:(ForecastInformation*)forecastInfo 
    {
        _forecastInfo=[forecastInfo retain];
        [MyTableView reloadData];
    }

    -(void)forecastInfo:(ForecastInfoParser*)parser parsed:(CurrentCondition*)currentcondition
    {
        currentcond=[currentcondition retain];
        [MyTableView reloadData];
    }

    -(void)forecastInfoCondition:(ForecastInfoParser*)parser parsed:(NSMutableArray *)forecastcondition
    {
        forecastcond=[forecastcondition retain];
        [MyTableView reloadData];
    }

    #pragma mark -
    #pragma mark Table view data source

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        // Return the number of sections.
        return 1;
    }


    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        if(_forecastInfo&&currentcond&&forecastcond)
            return 4;
        return 0;

    }


    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

        TWeatherCell *cell =(TWeatherCell *) [MyTableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"cell_%d", indexPath.row]];
        if (cell == nil) {
            //cell = [[[TWeatherCell alloc] initWithStyle:UITableViewStyleGrouped reuseIdentifier:CellIdentifier] autorelease];
            cell = [[[TWeatherCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"cell_%d", indexPath.row]] autorelease];
        }
        //ForecastCondition *cond=[forecastcond objectAtIndex:0];
        cond1=[forecastcond objectAtIndex:1];
        cond2=[forecastcond objectAtIndex:2];
        cond3=[forecastcond objectAtIndex:3];
        if ([currentcond.Icon isEqualToString:@"http://\n"])
        {
            cell.weatherimage.image = [UIImage imageNamed:@"listIcon-H.png"];
        }
        else {
            NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:currentcond.Icon]];       
            NSLog(@"this is image from server:%@",imageData);
            cell.weatherimage.image = [UIImage imageWithData:imageData];
            [imageData release];
        }
        NSDate *today = [NSDate date];
        NSDateFormatter *date_formatter=[[NSDateFormatter alloc]init]; 
        NSString *str=NSLocalizedString(@"date",nil);
        [date_formatter setDateFormat:str]; 
        NSTimeInterval secondsPerDay = 24 * 60 * 60;
        //NSDate *today = [NSDate date];
        NSDate *thursday = [NSDate dateWithTimeInterval:secondsPerDay sinceDate:today];
        NSDate *friday = [NSDate dateWithTimeInterval:2*secondsPerDay sinceDate:today];
        NSDate *sunday = [NSDate dateWithTimeInterval:3*secondsPerDay sinceDate:today];
        //tomorrow = [today addTimeInterval:secondsPerDay];
        switch (indexPath.row) {
            case 0:
                NSLog(@"%d",indexPath.row);
                NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:currentcond.Icon]];
                NSLog(@"this is image from server:%@",imageData);
                cell.weatherimage.image = [UIImage imageNamed:photo];
                [imageData release];
            file://localhost/Users/pradeepyadav/Desktop/JourneyMapper/Journey/Classes/TJourneyTabBar.hcell.weatherimage.image = [UIImage imageNamed:photo];     
                cell.reportdate.text = _forecastInfo.CurrentDateTime;
                //cell.conditionname.text = currentcond.Condition;
                [cell setConditionName:currentcond.Condition];      
                //[cell setConditionName:cond1.Condition];
                cell.twotemp.text = [NSString stringWithFormat:@"Temp:%@/%@",currentcond.Tempf,currentcond.Tempc];
                cell.twodirection.text = currentcond.WindCondition;
                cell.humidity.text = currentcond.Humidity;

                break;
            case 1:
                NSLog(@"%d",indexPath.row);
                cell.weatherimage.image = [UIImage imageNamed:photo]; 
                cell.reportdate.text =[NSString stringWithFormat:@"%@",thursday];
                //cell.conditionname.text = cond1.Condition;
                [cell setConditionName:cond1.Condition];
                cell.twotemp.text = [NSString stringWithFormat:@"Temp:%@/%@",cond1.Low,cond1.High];
                break;
            case 2:
                NSLog(@"%d",indexPath.row);
                cell.weatherimage.image = [UIImage imageNamed:photo];
                cell.reportdate.text = [NSString stringWithFormat:@"%@",friday];
                //cell.conditionname.text = cond2.Condition;
                [cell setConditionName:cond2.Condition];
                cell.twotemp.text = [NSString stringWithFormat:@"Temp:%@/%@",cond2.Low,cond2.High];
                break;
            case 3:
                NSLog(@"%d",indexPath.row);
                cell.weatherimage.image = [UIImage imageNamed:photo];
                cell.reportdate.text = [NSString stringWithFormat:@"%@",sunday];
                //cell.conditionname.text = cond3.Condition;
                [cell setConditionName:cond3.Condition];
                cell.twotemp.text = [NSString stringWithFormat:@"Temp:%@/%@",cond3.Low,cond3.High];
                break;
            default:
                NSLog(@"Out of Range ",indexPath.row);
                break;
        }
        return cell;
    }






    #pragma mark -
    #pragma mark Table view delegate

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        // Navigation logic may go here. Create and push another view controller.
        /*
         <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
         // ...
         // Pass the selected object to the new view controller.
         [self.navigationController pushViewController:detailViewController animated:YES];
         [detailViewController release];
         */
    }



    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *) indexPath
    {
        return 100.0;
    }


    #pragma mark -
    #pragma mark Memory management

    - (void)didReceiveMemoryWarning {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];

        // Relinquish ownership any cached data, images, etc. that aren't in use.
    }

    - (void)viewDidUnload {
        // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
        // For example: self.myOutlet = nil;
    }


    - (void)dealloc {
        [super dealloc];
        [_forecastInfo release];
        [currentcond release];
        [forecastConditions release];
    }

    @end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:32:00+00:00Added an answer on May 24, 2026 at 4:32 am

    I believe what your asking is “how can I update 4 rows in one SQL command?”

    The easiest way to do this is to use “;” to break up the sql statement to form 4 different queries executed in one string

    Your main SQL string appears to be in the NSString nsQuery, here is a way you could set it although its a little tedious

    NSString *qry1 = [NSString stringWithFormat:@"INSERT INTO weather (ReportDate,conditionname,humidity,maxtemp,mintemp,wind) VALUES('%@','%@','%@','%@','%@','%@')" ,_forecastInfo.CurrentDateTime,currentcond.Condition,currentcond.Tempf,currentcond.Tempf,currentcond.Wind2ondition,currentcond.Humidity]; 
    NSString *qry2 = [NSString stringWithFormat:@"INSERT INTO newtable(DifferentColumn) VALUES('Dummy Data')"]; 
    NSString *qry3 = [NSString stringWithFormat:@"INSERT INTO thirdtable(Temp) VALUES(3)"]; 
    NSString *qry4 = [NSString stringWithFormat:@"INSERT INTO forthtable(Other) VALUES('indigo')"]; 
    
    NSString *nsQuery = [[NSString alloc] initWithFormat:@"%@;%@;%@;%@",qry1,qry2,qry3,qry4]; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to ship a default SQLite database, with some predefined key/value pairs in
I am using the SQLite database and have the following persistent class (simplified): public
I have an sqlite database full of huge number of URLs and it's taking
Is there a tool to migrate an SQLite database to SQL Server (both the
Which language for quick GUI app + sqlite database CRUD (2-4 tables). Java, Python?
I am having problems connecting to a Sqlite database through System.Data.Sqlite. I was trying
My application makes use of a SQLite database to store the user's inputs. The
Does anybody know if there is a way to create an SQLite database based
I'm developing an iPhone app that uses the built-in SQLite database. I'm trying to
I'm creating an AIR application which connects to a SQLite database. The database balks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.