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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 10-19-2009, 06:21 AM   #1 (permalink)
lex
Registered Member
 
Join Date: Oct 2009
Location: Switzerland
Posts: 7
Default Sqlite3 textfields display same content.

Hi at all out there,

I've got a big problem.
I'm started to wor on a tour log for myself.
Now i have a problem with my data read and save.

I have several textboxes with different content.
I used the Sqlite books example from Apple iPhone Dev.

my fields in the view are
ship (int), crewlistid (int), name(text), date(date), description(text), wetter(text), wasser(text), gpsset(int).
the values for these fields are pre initialized in the database.

if i open the database and read the data i get the same values for description, wetter and wasser. all other values are read and written correctly, except these three. I dont know why.

here the code for read and write.

Code:
// Brings the rest of the object data into memory. If already in memory, no action is taken (harmless no-op).
- (void)hydrate {
	NSLog(@"Tour hydrate");
    // Check if action is necessary.
    if (hydrated) return;
    // Compile the hydration statement, if needed.
    if (hydrate_statement == nil) {
        const char *sql = "SELECT ship, crewlistid, date, description, wetter, wasser, gpsset FROM tour WHERE pk=?";
        if (sqlite3_prepare_v2(database, sql, -1, &hydrate_statement, NULL) != SQLITE_OK) {
            NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
        }
    }
    // Bind the primary key variable.
    sqlite3_bind_int(hydrate_statement, 1, primaryKey);
    // Execute the query.
    int success =sqlite3_step(hydrate_statement);
    if (success == SQLITE_ROW) {
		self.ship = sqlite3_column_int(hydrate_statement, 0);
		NSLog(@"%i",self.ship);
		self.crewlistid = sqlite3_column_int(hydrate_statement, 1);
		NSLog(@"%i",self.crewlistid);
		self.date = [NSDate dateWithTimeIntervalSince1970:sqlite3_column_double(hydrate_statement, 2)];
		NSLog(@"%@",self.date);
		char *str = (char *)sqlite3_column_blob(hydrate_statement, 3);
        self.description = (str) ? [NSString stringWithUTF8String:str] : @"";
		NSLog(@"%@",self.description);
		char *str2 = (char *)sqlite3_column_blob(hydrate_statement, 4);
        self.wetter = (str2) ? [NSString stringWithUTF8String:str] : @"";
		NSLog(@"%@",self.wetter);
		char *str3 = (char *)sqlite3_column_blob(hydrate_statement, 5);
        self.wasser = (str3) ? [NSString stringWithUTF8String:str] : @"";
		NSLog(@"%@",self.wasser);
		self.gpsset = sqlite3_column_int(hydrate_statement, 6);
		NSLog(@"%i",self.gpsset);
		
		NSLog(@"success hydrate %S", hydrate_statement);
		
		
    } else {
        // The query did not return 
        self.ship = 1;
        self.date = [NSDate date];
		self.description = @"No Description available";
		self.crewlistid = 1;
		self.gpsset =1;
		self.wasser = @"Keine Wasserdaten vorhanden";
		self.wetter = @"Keine Wetterdaten vorhanden";
		NSLog(@"No success hydrate");
    }
    // Reset the query for the next use.
    sqlite3_reset(hydrate_statement);
	sqlite3_finalize(hydrate_statement);
	hydrate_statement = nil;
    // Update object state with respect to hydration.
    hydrated = YES;
	NSLog(@"end hydrated");
}

// Flushes all but the primary key and title out to the database.
- (void)dehydrate {
	NSLog(@"dehydrate tour");
    if (dirty) {
		NSLog(@"dehydrate notwendig");
        // Write any changes to the database.
        // First, if needed, compile the dehydrate query.
        if (dehydrate_statement == nil) {
            const char *sql = "UPDATE tour SET name=?, ship=?, crewlistid=?, date=?, description=?, wetter=?, wasser=?, gpsset=? WHERE pk=?";
            if (sqlite3_prepare_v2(database, sql, -1, &dehydrate_statement, NULL) != SQLITE_OK) {
                NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
				NSLog(@"dehydrate error 1");
            }
        }
        // Bind the query variables.
        sqlite3_bind_text(dehydrate_statement, 1, [name UTF8String], -1, SQLITE_TRANSIENT);
		sqlite3_bind_int(dehydrate_statement, 2, ship);
		sqlite3_bind_int(dehydrate_statement, 3, crewlistid);
		sqlite3_bind_double(dehydrate_statement, 4, [date timeIntervalSince1970]);
        sqlite3_bind_text(dehydrate_statement, 5, [description UTF8String], -1, SQLITE_TRANSIENT);
		sqlite3_bind_text(dehydrate_statement, 6, [wetter UTF8String], -1, SQLITE_TRANSIENT);
		sqlite3_bind_text(dehydrate_statement, 7, [wasser UTF8String], -1, SQLITE_TRANSIENT);
		sqlite3_bind_int(dehydrate_statement, 8, gpsset);
        sqlite3_bind_int(dehydrate_statement, 9, primaryKey);
		NSLog(@"Dehydrate statement vor exec %S", dehydrate_statement);
        // Execute the query.
        int success = sqlite3_step(dehydrate_statement);
		NSLog(@"Dehydrate statement int %i", dehydrate_statement);
		NSLog(@"Dehydrate statement ins %s", dehydrate_statement);
		NSLog(@"Dehydrate statement inu %S", dehydrate_statement);
		NSLog(@"%i" , success);
		int second = sqlite3_step(dehydrate_statement);
		NSLog(@"%i" , second);
        // Reset the query for the next use.
        sqlite3_reset(dehydrate_statement);
        // Handle errors.
        if (success != SQLITE_DONE) {
            NSAssert1(0, @"Error: failed to dehydrate with message '%s'.", sqlite3_errmsg(database));
			NSLog(@"dehydrate error2");
        }
		NSLog(@"error from DB is by dehydrate, %s", sqlite3_errmsg(database));
		NSLog(@"Dehydrate statement int %i", dehydrate_statement);
		NSLog(@"Dehydrate statement ins %s", dehydrate_statement);
		NSLog(@"Dehydrate statement inu %u", dehydrate_statement);
		//NSLog(@"Dehydrate statement int %i", dehydrate_statement);
		//NSLog(@"Dehydrate statement int %i", dehydrate_statement);
		sqlite3_reset(dehydrate_statement);
		sqlite3_finalize(dehydrate_statement);
		dehydrate_statement = nil;
		
        // Update the object state with respect to unwritten changes.
        dirty = NO;
		NSLog(@"dehydrate feddich");
    }
    // Release member variables to reclaim memory. Set to nil to avoid over-releasing them 
    // if dehydrate is called multiple times.
    [name release];
    name = nil;
    [date release];
    date = nil;
	[description release];
	description = nil;
	[wetter release];
	wetter = nil;
	[wasser release];
	wasser = nil;
    [data release];
    data = nil;
    // Update the object state with respect to hydration.
    hydrated = NO;
}
ah and there is again a problem i had to set the hydrate and the dehydrate statement to nil that im able to finalize the statement. why?
maybe im blind. please help me.

Thanks Thomas
lex is offline   Reply With Quote
Old 10-19-2009, 07:48 AM   #2 (permalink)
lex
Registered Member
 
Join Date: Oct 2009
Location: Switzerland
Posts: 7
Default

em, sorry out there i found the error.

At the position oi hydrate my data

char str = statement
var = nsstring utf8 str


self.description = (str) ? [NSString stringWithUTF8String:str] : @"";
NSLog(@"%@",self.description);
char *str2 = (char *)sqlite3_column_blob(hydrate_statement, 4);
self.wetter = (str2) ? [NSString stringWithUTF8String:str] : @"";
NSLog(@"%@",self.wetter);
char *str3 = (char *)sqlite3_column_blob(hydrate_statement, 5);
self.wasser = (str3) ? [NSString stringWithUTF8String:str] : @"";
NSLog(@"%@",self.wasser);


ive every three times checked str not str , str2, str3.

like ive said. im blind.

Sorry for that

but there is one thing , what wonders me.

Why i had to set my statement to nil that i can finalize my statement to close the DB ??? i have an another object with the same code in it but no text fileds. and there i dont need to set the statements to nil. ???????

Last edited by lex; 10-19-2009 at 07:57 AM.
lex is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, sqlite, sqlite3

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: 253
23 members and 230 guests
ADY, bookesp, chillyh, ckgni, dacapo, Dani77, Davey555, Desert Diva, glenn_sayers, HemiMG, JasonR, LEARN2MAKE, M.A.S., marshusensei, mer10, nobre84, prchn4christ, Raggou, Rudy, ryantcb, themathminister, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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