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 10-15-2010, 03:39 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 6
sarahhbabyyyy is on a distinguished road
Smile Inserting into SQLite

Hi Everyone,
I have been stuck on this for the past two days! So basically, I am trying to get what the user typed into the app and store it into the SQLite database. I can already read data from it but for some reason, my insert is not working! Can someone please help? Thanks!

Here's my insert code:

-(void) insertSavedData
{
databaseName = @"Database.sqlite";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
dbPath = [documentsDir stringByAppendingPathComponent:databaseName];

int addID;

// Open the database from the users filessytem
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
NSLog(@"in method");
if(addStmt == nil) {
const char *sql = "insert into vehicleInfo(vehicleID, brandName, modelName, vehicleType, idr, spur, pinion) values(?,?,?,?,?,?,?)";
if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
{
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
}
}

sqlite3_bind_double(addStmt, 1, 500);
sqlite3_bind_text(addStmt, 2, [@"test" UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 3, [@"test" UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt, 4, [@"test" UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_double(addStmt, 5, 1);
sqlite3_bind_double(addStmt, 6, 1);
sqlite3_bind_double(addStmt, 7, 1);

if(SQLITE_DONE != sqlite3_step(addStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));

else
{
//SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid
addID = sqlite3_last_insert_rowid(database);
NSLog(@"in method %d", addID);
}

//Reset the add statement.
sqlite3_reset(addStmt);
}
sqlite3_finalize(addStmt);

sqlite3_close(database);
}


Thank you in advance!
sarahhbabyyyy is offline   Reply With Quote
Reply

Bookmarks

Tags
database, insert into, sql, sqlite

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: 342
8 members and 334 guests
Desert Diva, dre, hain, HemiMG, mottdog, oceanlablight, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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