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 05-20-2010, 10:57 AM   #1 (permalink)
Registered Member
 
ManWithMask's Avatar
 
Join Date: Mar 2010
Location: Stellenbosch, South Africa
Posts: 88
ManWithMask is on a distinguished road
Send a message via Skype™ to ManWithMask
Unhappy SQlite3: Select statement...WHERE clause

I am trying to get a row and return a column from the fetched row, but somehow it is not working. I suspect my syntax is wrong.

I have declared an int variable ("Key") and populate its value from another table and want to use this to select the row.

Code:
NSInteger Key = [mydetailsTable.AgeNB integerValue];
My NSLog reports the correct value from the other table:

2010-05-20 17:56:03.941 Ifa[13992:207] Key: 48

If I hard code the value, then it gets the row and returns the correct Rate.

Code:
const char *sql = "SELECT Rate from PremiumRates WHERE AgeNB = 48"//works;

const char *sql = "SELECT Rate from PremiumRates WHERE AgeNB = Key";//does not work
If I use the int variable it does not find the row.

I have looked around, but there seem very few examples of the format of the WHERE clause when trying to return selected rows.

Anyone who can help me? Much appreciated!!!!

Last edited by ManWithMask; 05-20-2010 at 11:02 AM.
ManWithMask is offline   Reply With Quote
Old 05-20-2010, 11:10 AM   #2 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 4
reubensammut is on a distinguished road
Default

Quote:
Originally Posted by ManWithMask View Post
I am trying to get a row and return a column from the fetched row, but somehow it is not working. I suspect my syntax is wrong.

I have declared an int variable ("Key") and populate its value from another table and want to use this to select the row.

Code:
NSInteger Key = [mydetailsTable.AgeNB integerValue];
My NSLog reports the correct value from the other table:

2010-05-20 17:56:03.941 Ifa[13992:207] Key: 48

If I hard code the value, then it gets the row and returns the correct Rate.

Code:
const char *sql = "SELECT Rate from PremiumRates WHERE AgeNB = 48"//works;

const char *sql = "SELECT Rate from PremiumRates WHERE AgeNB = Key";//does not work
If I use the int variable it does not find the row.

I have looked around, but there seem very few examples of the format of the WHERE clause when trying to return selected rows.

Anyone who can help me? Much appreciated!!!!
try this

Code:
NSString *s = [NSString stringWithFormat:@"SELECT SELECT Rate from PremiumRates WHERE AgeNB = %d", Key];
	
const char *sql = [s cStringUsingEncoding:NSASCIIStringEncoding];
reubensammut is offline   Reply With Quote
Old 05-20-2010, 12:02 PM   #3 (permalink)
Registered Member
 
ManWithMask's Avatar
 
Join Date: Mar 2010
Location: Stellenbosch, South Africa
Posts: 88
ManWithMask is on a distinguished road
Send a message via Skype™ to ManWithMask
Talking SQlite3: Select statement...WHERE clause

That worked and the correct Rate is being returned. Now I understand how to set up the WHERE clause for selected records. Hope this will help others as well.

Thanks a million.
ManWithMask is offline   Reply With Quote
Old 05-21-2010, 03:03 AM   #4 (permalink)
Registered Member
 
ManWithMask's Avatar
 
Join Date: Mar 2010
Location: Stellenbosch, South Africa
Posts: 88
ManWithMask is on a distinguished road
Send a message via Skype™ to ManWithMask
Question SQlite3: Select statement...WHERE clause

Hi Reuben,

Is there any documentation on the % parameters one can use in such a select method. If my Key is a string var, then the %d will not work. I have trawled around looking for some useful documentation and cannot find someone who has put together anything useful on the parameter options following the %. Seems like most people want to SELECT all the records and very few include a WHERE clause in their SELECT.

Thanks in advance!

Quote:
Originally Posted by reubensammut View Post
try this

Code:
NSString *s = [NSString stringWithFormat:@"SELECT SELECT Rate from PremiumRates WHERE AgeNB = %d", Key];
	
const char *sql = [s cStringUsingEncoding:NSASCIIStringEncoding];
ManWithMask is offline   Reply With Quote
Old 05-21-2010, 05:44 AM   #5 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 1,018
Tambourin is on a distinguished road
Default

if key is an NSString use %@

check your C language book for documentation about %
Tambourin is offline   Reply With Quote
Old 05-21-2010, 06:54 AM   #6 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 4
reubensammut is on a distinguished road
Default

Yes I suggest you read this as there are some Objective-C specific Format Specifiers like %@ for objects like NSString
reubensammut is offline   Reply With Quote
Reply

Bookmarks

Tags
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: 306
8 members and 298 guests
ajay123123, Fstuff, guusleijsten, HemiMG, newDev, pkIDSF, Sami Gh, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,877
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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