Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: libpq prepared statement



These are _very_ basic C (and Objective-C) questions.

1) An NSString is a Cocoa Objective-C class. It is not a char* C string.
Whether you need to have your UUID as a char* throughout the code, or
whether you need to start with an NSString* and extract a char* for use with
libpq depends on the bigger picture of what you're doing.

2) Do you want to use the conn you just created, or the theConnection
variable whose origin is not clear in your code snippet?

3) %s is the syntax for an argument placeholder to printf (and various other
library routines for CFString and NSString) for a char*; it has nothing to
do with parameters in SQL statements. See "Command Execution Functions" in
the PG documentation for a description of PQprepare.

4) [theUUID] is meaningless. The [object message:args] notation is for
sending a message to an object. If you thought that PQprepare would take an
NSString*, you would have tried just theUUID. If you wanted to convert it to
a char*, you would have tried something like [theUUID getCString...]. I
can't tell from this what you were thinking.

5) You are trying to prepare a statement, not execute it. PQprepare takes an
array of types, not the array of arguments. (PQexecPrepared will require the
arguments for execution.)

The following should compile:

const char *theUUID = "test";
PGconn *conn = PQconnectdb(conninfo);
Oid textoid = 25;
PGresult *statement = PQPrepare(conn, "stmtname", "SELECT *
FROM admin WHERE id = $1::text", 1, &textoid);
PGresult *result = PQexecPrepared(conn, "stmtname", 1, &theUUID, NULL, NULL,
0);

But please, step back and read a beginner book on C and one on Objective-C
before you try to go further. Then you'll be better prepared to read the PG
docs, and to figure out which future questions related to Cocoa, or
Postgres, or C.

-- 
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 722-0567 voice


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >libpq prepared statement (From: Justin Giboney <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.