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 03-12-2010, 07:08 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 142
Question sqlite bind text

Hi. I am trying to take a row of my sqldatabase where the data name=X.
SO i have this...
Code:
NSString * name=[NSString stringwithformat:@"Rick"];
const char *sqlStatement = "select * from user where name=?";
		sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
			// Loop through the results and add them to the feeds array
			sqlite3_bind_text(compiledStatement, 1, [name UTF8String],-1,SQLITE_TRANSIENT);
			while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
Anyone knows why it is doesnt working?¿???¿?
ivanraso is offline   Reply With Quote
Old 03-12-2010, 09:56 PM   #2 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 19
Default

Try it without this line:

sqlite3_bind_text(compiledStatement, 1, [name UTF8String],-1,SQLITE_TRANSIENT);
Nungster is offline   Reply With Quote
Old 03-12-2010, 10:01 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 19
Default

Quote:
Originally Posted by Nungster View Post
Try it without this line:

sqlite3_bind_text(compiledStatement, 1, [name UTF8String],-1,SQLITE_TRANSIENT);
Another point may be how you are storing the data once it is returned from SQLite. My guess is you need a NSMutableArray to store the row when it comes back from SQLite and not seeing how you are dealing with that limits the amount by which we are able to help.
Nungster is offline   Reply With Quote
Old 03-13-2010, 08:07 AM   #4 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 142
Default

Quote:
Originally Posted by Nungster View Post
Another point may be how you are storing the data once it is returned from SQLite. My guess is you need a NSMutableArray to store the row when it comes back from SQLite and not seeing how you are dealing with that limits the amount by which we are able to help.
I did it. It was a problem with the database...thank you guys.
ivanraso is offline   Reply With Quote
Old 09-23-2010, 08:07 PM   #5 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: PK
Posts: 27
Default

What was the problem? I am also stuck in the same problem from the past three days. I want to insert data in sqlite database, but not getting success.
I am writing these lines of code
-(void) addNewRecordsbyUserNameNSString *)_userName withCountryNameNSString *)_countryName andEmailNSString *)_emailAddress{
@try
{
NSFileManager *fileManager=[NSFileManager defaultManager];
NSString *theDBPath=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @"Database.sqlite"];
BOOL success=[fileManager fileExistsAtPath:theDBPath];

(sqlite3_open([theDBPath UTF8String], &database))
{
NSString *query = [[NSString alloc ] initWithFormat:@"insert into userinformation Values(%d,'%@','%@','%@')",idName,_emailAddress,_c ountryName,_userName];
const char *sql = [query UTF8String];
sqlite3_stmt *statement;
sqlite3_prepare_v2(database, sql,-1,&statement,NULL)

sqlite3_bind_text(statement, 1, [_userName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 2, [_emailAddress UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 3, [_countryName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_int(statement,4,4); [query release];
sqlite3_finalize(statement)
sqlite3_close(database)
}
@catch (NSException * e)
{
NSLog(@"An exception occured:%a",[e reason]);
}
}

I have no idea where i am putting mistake. Can anybody please help me here. Looking for your positive responses in a very quick time as i am in very much hurry.

Last edited by d4devil; 09-23-2010 at 08:17 PM. Reason: some lines of code was missing
d4devil is offline   Reply With Quote
Old 09-23-2010, 10:59 PM   #6 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,890
Default

Quote:
Originally Posted by d4devil View Post
What was the problem? I am also stuck in the same problem from the past three days. I want to insert data in sqlite database, but not getting success.
I have no idea where i am putting mistake. Can anybody please help me here. Looking for your positive responses in a very quick time as i am in very much hurry.
First of all, use code tags when you post code...

To answer your question, you are missing the most important part!

Code:
 int success = sqlite3_step(statement);
__________________
I really do this.
Bertrand21 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: 257
23 members and 234 guests
@sandris, ADY, Dani77, diyora, FAED, fredidf, F_Bryant, GHuebner, HDshot, iDifferent, JasonR, mer10, Oral B, prchn4christ, Rudy, Speed, spiderguy84, stekki, tgjorgoski, Thompson22, Touchmint, twerner, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,753
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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