agora inbox for pgsql-interfaces@postgresql.org
help / color / mirror / Atom feedFrom: Neeraj Rai <rneeraj@yahoo.com>
To: pgsql-interfaces@postgresql.org <pgsql-interfaces@postgresql.org>
Date: Tue, 21 May 2013 18:26:08 -0700 (PDT)
Message-ID: <1369185968.87888.YahooMailNeo@web164906.mail.bf1.yahoo.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-interfaces>
Hi,
I'm trying a simple pgsql program with PQexecPrepared and have a few questions.
I have seen the example but didn't find the answer there. googled too.
http://www.postgresql.org/docs/9.2/static/libpq-example.html
Q1. what format is date set in ? what is the length ?
Q2.Q2.what is the type and length of bit wise fields
Q3. how to convert seconds since epoch to date
Q4. is int passable as time?
Q5. the paramValsVec_ is char* const char[] . Can we type cast int to char* and pass in ? and set type to INT4OID?
Below is some pseudo code to put above questions in perspective.
>>. table
CREATE TABLE t1
(curdate date,
str1 varchar(19),
tm_new timestamptz,
count int);
>>> c++ code PGconn* pgconn; // connected
char * UpsertStmt_= "INSERT INTO t1 values( $1, $2, $3, $4)";
int result=0;
PGresult* pgres = PQprepare (pgconn, "stmtname", UpsertStmt_, 4, NULL);
int result = PQresultStatus(pgres);
PQclear(pgres_);
struct mydata
{
int curtime;
char str1[32];
int mycount;
intmybitfield : 3;
},
mydata myvar;
myvar.curtime = time(NULL)
strcpy(myvar.str1, hello);
myvar.mycount = 2;
myvar.mybitfield = 2;
// set helper vars
paramLenVec_[0] = 8;// Q1. what format is date set in ? what is the length
paramLenVec_[1] = strlen(str1);
paramLenVec_[2] = sizeof(int); // type = INT4OID, sizeof (int)
paramLenVec_[3] = sizeof(int);// Q2.what is the type and length of bit wise fields
paramValsVec_[0] = (char*)&myvar.curtime; // Q3. how to convert to date
paramValsVec_[1] = myvar.str1;
paramValsVec_[2] = &myvar.curtime; // Q4. is int passable as time
paramValsVec_[3] = (char*)&myvar.mycount; // Q5.
PQexecPrepared (pgconn, "stmtname", 4,
paramValsVec_,
paramLenVec_,
NULL, 0
);
view thread (5+ messages) latest in thread
Message-ID: <1369185968.87888.YahooMailNeo@web164906.mail.bf1.yahoo.com>
Permalink: ../1369185968.87888.YahooMailNeo@web164906.mail.bf1.yahoo.com/
Also on: postgresql.org/message-id/1369185968.87888.YahooMailNeo@web164906.mail.bf1.yahoo.com
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: rneeraj@yahoo.com
Subject: Re:
In-Reply-To: <1369185968.87888.YahooMailNeo@web164906.mail.bf1.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox