pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedPQexecPrepared Problem with paramValues
2+ messages / 2 participants
[nested] [flat]
* PQexecPrepared Problem with paramValues
@ 2006-03-30 04:20 Keary Suska <hierophant@pcisys.net>
0 siblings, 1 reply; 2+ messages in thread
From: Keary Suska @ 2006-03-30 04:20 UTC (permalink / raw)
To: pgsql-interfaces
To risk exposing my less-than-geek level knowledge of C, I am having a
problem with PQexecPrepared where it crashes every time.
I am pretty sure it is because I am not sending the right kind of pointer to
the paramValues. I am certain that the problem has to do with the parameter
in any case, because I can execute successfully with static values.
I know this is probably more of a C issue, but I hoping someone has the
heart to help.
Note: I am working in objective-C, and not in C, so I need to convert from
one data representation to one libpq understands. This may help explain why
the approach below is odd.
After a successful prepare, I calloc() a buffer like so:
char *buffer = calloc( 1, maxLen );
where maxLen is the total size of concatenated strings including terminating
nulls.
I then populate the buffer with the strings sequentially. This seems to be
working without any issues (I have verified).
I am assuming that this format is OK since the documentation doesn't
indicate that a proper two-dimensional array is required. Notwithstanding, I
need to work with an arbitrary number of parameters of arbitrary length.
But every way I have tried to pass the buffer (or some other variable made
into a compatible pointer type) causes a crash in the guts of libpq.
An example call:
pgResultStruct = PQexecPrepared( [connection pgConnStruct], "", params,
&buffer, NULL, NULL, 0 );
Of course, the compiler doesn't like the parameter in this case. Trying to
convert to a compatible pointer type:
const char *buf2 = buffer;
const char * const *paramValues = &buf2;
pgResultStruct = PQexecPrepared( [connection pgConnStruct], "", params,
paramValues, NULL, NULL, 0 );
The compiler doesn't mind but libpq crashes.
This is probably a simple issue, but I can't seem to figure it out.
Best,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: PQexecPrepared Problem with paramValues
@ 2006-03-30 04:40 Tom Lane <tgl@sss.pgh.pa.us>
parent: Keary Suska <hierophant@pcisys.net>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2006-03-30 04:40 UTC (permalink / raw)
To: Keary Suska <hierophant@pcisys.net>; +Cc: pgsql-interfaces
Keary Suska <hierophant@pcisys.net> writes:
> I am assuming that this format is OK since the documentation doesn't
> indicate that a proper two-dimensional array is required.
No, what is needed is a one-D array of pointers to char[] strings.
There isn't any use in concatenating those strings into one array,
if you have them available as separate null-terminated strings.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2006-03-30 04:40 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-03-30 04:20 PQexecPrepared Problem with paramValues Keary Suska <hierophant@pcisys.net>
2006-03-30 04:40 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox