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 Tools & Utilities

Reply
 
LinkBack Thread Tools Display Modes
Old 11-03-2010, 08:17 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 32
y2kreddy is on a distinguished road
Default not able insert values into sqlite database.

Hi people,


HERE IS MY CODE,

const char *sqlStatement = (const char *)query;

//const char *sqlStatement ="insert into usertable values('one','two')";


if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement,NULL) == SQLITE_OK)
{
NSLog(@"inside");
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{ }
sqlite3_finalize(compiledStatement);

}

if i run this code, the values does not get inserted into the database. however if i uncomment the second line and comment the first line it works fine.
the variable "query" is of type NSMutableString and it is a local variable declared in the header file.
sqlStatement is member variable for the method.
i tried several things like retain and release and nothing worked.
not able to resolve this for the past 2 days. and its kindof getting frustrated.

Anyone please HELP???
y2kreddy is offline   Reply With Quote
Old 11-03-2010, 08:34 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: Last spotted in MD.
Posts: 17
LazyCoder is on a distinguished road
Default

Quote:
Originally Posted by y2kreddy View Post
Hi people,


HERE IS MY CODE,

const char *sqlStatement = (const char *)query;

//const char *sqlStatement ="insert into usertable values('one','two')";


if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement,NULL) == SQLITE_OK)
{
NSLog(@"inside");
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{ }
sqlite3_finalize(compiledStatement);

}

if i run this code, the values does not get inserted into the database. however if i uncomment the second line and comment the first line it works fine.
the variable "query" is of type NSMutableString and it is a local variable declared in the header file.
sqlStatement is member variable for the method.
i tried several things like retain and release and nothing worked.
not able to resolve this for the past 2 days. and its kindof getting frustrated.

Anyone please HELP???
You may want use:
Code:
const char *sqlStatement = [query cStringUsingEncoding:[NSString defaultCStringEncoding]];
As first line.
Right now you are casting 'id' to 'const char*'.
LazyCoder is offline   Reply With Quote
Old 11-03-2010, 08:48 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 32
y2kreddy is on a distinguished road
Default

Hey man

i just used the below code and it worked fine.

sqlStatement=[query cStringUsingEncoding:NSASCIIStringEncoding];

i also tested with your code and its working too. i should have posted this 2 days ago. it would have saved lot of time for me , anyways thank you soo much for your response.

Have a nice day.
Thank You.
y2kreddy is offline   Reply With Quote
Reply

Bookmarks

Tags
insertion, 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: 370
7 members and 363 guests
husthlj, illogical, LegionMD, LunarMoon, mer10, Murphy, padsoftware
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,677
Threads: 94,127
Posts: 402,916
Top Poster: BrianSlick (7,990)
Welcome to our newest member, husthlj
Powered by vBadvanced CMPS v3.1.0

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