Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-02-2011, 05:34 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 8
ravindra1989 is on a distinguished road
Default Problem With sqlite3 update Command

Can Any one tell me what is wrong with this code?

Code:
+ (BOOL)updateEntryTable
{
	sqlite3 *database;
	
	sqlite3_stmt *update_statement;
	
	
	NSString *stmt1 = [NSString stringWithFormat:@"UPDATE entryTab SET ebody='done very well' WHERE eid='1'"];
	
	const char *sql = [stmt1 UTF8String];
	
	 if (sqlite3_open([[Utiliy databaseLocation] UTF8String], &database) == SQLITE_OK) 
	 {
	     if (sqlite3_prepare_v2(database, sql, -1, &update_statement, NULL) != SQLITE_OK) 
	     {
	          NSLog(@"Failed!!!!No databAse");
	          return NO;
	      }
	
		 int success = sqlite3_step(update_statement);
		 if (success == SQLITE_ERROR) 
		 {
			 NSLog(@"Error: failed to insert into the database with message %@", sqlite3_errmsg(database));
			 return NO;
		 }
	 }
	sqlite3_finalize(update_statement);
	sqlite3_close(database);
	return YES;
}

The insertion operation is successfully exicuted....While Updating It is exe uted with no error but Update operation is not done in the real database.

Thanks in advance.....
ravindra1989 is offline   Reply With Quote
Old 09-02-2011, 07:25 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 7
DevMike is on a distinguished road
Default

Hi,

eID is your PrimeKey ?
Try your update statement without ' ' .

Cheers,
DevMike

Good sqllite tutorial:
SQLite Tutorial ? Updating data | iPhone SDK Articles
DevMike is offline   Reply With Quote
Old 09-02-2011, 10:57 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 178
dustbyter is on a distinguished road
Default

I'd take this approach to determining why it fails.

1. Take the SQL code as it is and run it in your database directly, does it update correctly? Also, if your PK is an integer, then you don't require the single quotes around it.

2. If the update query works correctly in DB; ensure the database you are reviewing is the correct database file that the app is using.

I didn't see any obvious issues in your code that you provided.
dustbyter is offline   Reply With Quote
Old 09-03-2011, 04:03 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 8
ravindra1989 is on a distinguished road
Default

Thank you DevMike.... eID is not a primary key and is of type String. I tried without single quote, but its not working..

Last edited by ravindra1989; 09-03-2011 at 06:08 AM.
ravindra1989 is offline   Reply With Quote
Old 09-03-2011, 06:11 AM   #5 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 8
ravindra1989 is on a distinguished road
Default

Thank You for kind response....
I Already tried those approaches. Same Query Is working Fine directly....But through code it is not possible...
Insertion is perfectly executed..
ravindra1989 is offline   Reply With Quote
Old 09-06-2011, 07:06 AM   #6 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 8
ravindra1989 is on a distinguished road
Default

Please Can Anyone help me to resolve this.......?....
ravindra1989 is offline   Reply With Quote
Old 09-06-2011, 07:45 AM   #7 (permalink)
Registered Member
 
SundialSoft's Avatar
 
Join Date: Oct 2010
Location: Scotland
Posts: 176
SundialSoft is on a distinguished road
Default

Quote:
Originally Posted by ravindra1989 View Post
Can Any one tell me what is wrong with this code?

Code:
+ (BOOL)updateEntryTable
{
	sqlite3 *database;
	
	sqlite3_stmt *update_statement;
	
	
	NSString *stmt1 = [NSString stringWithFormat:@"UPDATE entryTab SET ebody='done very well' WHERE eid='1'"];
	
	const char *sql = [stmt1 UTF8String];
	
	 if (sqlite3_open([[Utiliy databaseLocation] UTF8String], &database) == SQLITE_OK) 
	 {
	     if (sqlite3_prepare_v2(database, sql, -1, &update_statement, NULL) != SQLITE_OK) 
	     {
	          NSLog(@"Failed!!!!No databAse");
	          return NO;
	      }
	
		 int success = sqlite3_step(update_statement);
		 if (success == SQLITE_ERROR) 
		 {
			 NSLog(@"Error: failed to insert into the database with message %@", sqlite3_errmsg(database));
			 return NO;
		 }
	 }
	sqlite3_finalize(update_statement);
	sqlite3_close(database);
	return YES;
}

The insertion operation is successfully exicuted....While Updating It is exe uted with no error but Update operation is not done in the real database.

Thanks in advance.....
I can't spot what's wrong. I made up my update statement based on the existing add statement from a demo I downloaded. Mine does not look exactly like yours. I have some sqlite3_bind_.... commands, here's my update function for what it's worth, hope it helps:-
Code:
//my attempt at update routine
- (void) updatesqldb {
	
	if(updateStmt == nil) {
		const char *sql = "update weddingBudget Set budDesc = ?, budBudgetAmt = ?,            budActualAmt = ?, budNote = ? Where STKEY = ?";
		if(sqlite3_prepare_v2(database, sql, -1, &updateStmt, NULL) != SQLITE_OK)
			NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(database));
	}
	
	sqlite3_bind_text(updateStmt, 1, [budDesc UTF8String], -1, SQLITE_TRANSIENT);
	sqlite3_bind_double(updateStmt, 2, [budBudgetAmt doubleValue]);
	sqlite3_bind_double(updateStmt, 3, [budActualAmt doubleValue]);
    sqlite3_bind_text(updateStmt, 4, [budNote UTF8String],-1,SQLITE_TRANSIENT);
	
    int returnValue = -1;

    
    sqlite3_bind_int(updateStmt, 5, STKEY);
    
    if(returnValue != SQLITE_OK)
 //       NSLog(@"Not OK!!!");
    
    if(SQLITE_DONE != sqlite3_step(updateStmt))
        NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(database));
    
    sqlite3_reset(updateStmt);
this does work
SundialSoft is offline   Reply With Quote
Old 09-08-2011, 05:01 AM   #8 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 8
ravindra1989 is on a distinguished road
Default

Thank you.....
My code is successfully executed.
The Error is not with this code.Before updating i am checking for record exist or not. that time i am not closing the database. So that the updating is not executed....
ravindra1989 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 391
5 members and 386 guests
JackReidy, jeroenkeij, Sami Gh, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:49 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0