Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Buschmaster

macrumors 65816
Original poster
Feb 12, 2006
1,306
27
Minnesota
I'm working with SQLite so that's why I need a const char, otherwise I'd know exactly how to do this, no problem at all.

Unfortunately I haven't spent much time with the char data type.

Here's my question...

What I have is a string and then a variable to put at the end of the string. How can I format this so I can put the variable at the end of the string? If I were working with an NSString this is what I'd be trying to accomplish:
NSString *sqlString = [NSString stringWithFormat:mad:"delete from mytable where name = %@",theName];

That's just an example but almost exactly what I'm trying to accomplish, just not inside my const char. Any ideas?
 

kpua

macrumors 6502
Jul 25, 2006
294
0
Your question isn't really clear, but I assume you're asking how to do something like -stringWithFormat: using C strings.

Take a look at sprintf. -stringWithFormat: is essentially a wrapper around that function.

Or, you could build an NSString and then get the C string from it.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
Before you do anything else, google for "SQL injection".

What would happen if you take the name from a text field, and the user types the following into the text field:

joe" or "a" = "a

Your code probably puts quotes around the name, turning it into

"joe" or "a" = "a"

and your SQL statement becomes

delete from mytable where name = "joe" or "a" = "a"

and everything is zapped.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.