Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uexom-0003f7-KP for pgsql-interfaces@arkaria.postgresql.org; Wed, 22 May 2013 01:26:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Uexom-0000Sp-1e for pgsql-interfaces@arkaria.postgresql.org; Wed, 22 May 2013 01:26:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uexok-0000Rv-JD for pgsql-interfaces@postgresql.org; Wed, 22 May 2013 01:26:14 +0000 Received: from nm34.bullet.mail.bf1.yahoo.com ([72.30.238.192]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uexoh-0001ln-GV for pgsql-interfaces@postgresql.org; Wed, 22 May 2013 01:26:14 +0000 Received: from [98.139.212.149] by nm34.bullet.mail.bf1.yahoo.com with NNFMP; 22 May 2013 01:26:09 -0000 Received: from [98.139.212.230] by tm6.bullet.mail.bf1.yahoo.com with NNFMP; 22 May 2013 01:26:09 -0000 Received: from [127.0.0.1] by omp1039.mail.bf1.yahoo.com with NNFMP; 22 May 2013 01:26:09 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 677837.59150.bm@omp1039.mail.bf1.yahoo.com Received: (qmail 88122 invoked by uid 60001); 22 May 2013 01:26:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1369185969; bh=+b7z1LYGaTHhbesV3xPAVBGgcdUcj6nbWtuEXga9gDw=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Reply-To:To:MIME-Version:Content-Type; b=AFC0JaB4HRI+lO51tvoEo6bmDTnLeOULVxxPwOMOKpQpWKAwoDW6IskY1Y1AvjfQ6we+ohpa88zFfBWtiOEkowHA17wkCuQCOpm8yDC2kXc2/HFIBamGIgkACBlJI9YsIdjncIQdLOv6LgVTj+MBRmB6OBXmg4OJMwJcwgujpHE= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Reply-To:To:MIME-Version:Content-Type; b=IchzdY5KY1Fn4K5lkrFWsRf/Hb0bm2pIZ+WDbZfmsaICrZCgLjig1fnSLl/JEzvEdEh5EZUaUkdEc7cv+5QFRWt2Vhp19RfW+JMr6qMSY05RR6hsZMm+edFxvmm9q5TpQuznEtRGgEYMSYWojThxVzEZk2cLt1RhkWX3FkEPz/w=; X-YMail-OSG: E21oLWMVM1nF2x3F.SVLVBQpibBb2GtOYXKJ1jtxVdSljy2 unQ7lRHMFXZNtbHjZfsGUW3oGpBONWEVoarRLDHMNPcgv55nk450_AqfRtDG dyvLzSn8XSdciLNUg.M.mZSxBpuYH.O7s8QqTZkKH5MUCToMNW6L8AppAd.K 1Rey9Nwv0sR_ucphjX_8KILS0RyRPXnXOOv.N7JpxnVctsYxmnyZzdXfVR0p im_VmD18_0L6lxx3oxOXAWnxQWcqPxb6fcRYQD2I4hhxenVnwn0F5nJzXklH n0S0FsUjCYItca6Pe0calYOnlYiAKJnwwGxvphR2BjqNjaDTytCQxYnoxBSN EY3A.uZ__neodLVNCWHHgGGDwpxSci6gFekXtd6nTxUTD1C4FCEEYvys6kww PeYlnWWzXOfnIo58pP5EVn1eKBtJzkJeerwZPEX_jGLmpbPs6XmmZ.eDAGQ8 jyDSVN_rTDiqPs6ka.6k5bbu8356w5yx_gwL4lALfMU7TLzJQgZ2vDCVQicv VAe7pp_gRfXixIvJl28M53mAgudBX8yxNBJjG_6DK3J6CnPE.0RXSiZ.Ywk. SWCQMxkhE0cQZiLId9iWBvpIw4Jgj3Ak012x39NCLDE3lsuiyBoect.AE Received: from [69.125.89.202] by web164906.mail.bf1.yahoo.com via HTTP; Tue, 21 May 2013 18:26:08 PDT X-Rocket-MIMEInfo: 002.001, SGksCkknbSB0cnlpbmcgYSBzaW1wbGUgcGdzcWwgcHJvZ3JhbSB3aXRowqBQUWV4ZWNQcmVwYXJlZMKgYW5kIGhhdmUgYSBmZXcgcXVlc3Rpb25zLsKgCkkgaGF2ZSBzZWVuIHRoZSBleGFtcGxlIGJ1dCBkaWRuJ3QgZmluZCB0aGUgYW5zd2VyIHRoZXJlLiBnb29nbGVkIHRvby4KaHR0cDovL3d3dy5wb3N0Z3Jlc3FsLm9yZy9kb2NzLzkuMi9zdGF0aWMvbGlicHEtZXhhbXBsZS5odG1sCgoKUTEuIHdoYXQgZm9ybWF0IGlzIGRhdGUgc2V0IGluID8gd2hhdCBpcyB0aGUgbGVuZ3RoID8KClEyLlEyLndoYXQgaXMBMAEBAQE- X-Mailer: YahooMailWebService/0.8.142.542 Message-ID: <1369185968.87888.YahooMailNeo@web164906.mail.bf1.yahoo.com> Date: Tue, 21 May 2013 18:26:08 -0700 (PDT) From: Neeraj Rai Reply-To: Neeraj Rai To: "pgsql-interfaces@postgresql.org" MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-498039042-897902292-1369185968=:87888" X-Pg-Spam-Score: 0.6 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-interfaces Precedence: bulk Sender: pgsql-interfaces-owner@postgresql.org ---498039042-897902292-1369185968=:87888 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hi,=0AI'm trying a simple pgsql program with=A0PQexecPrepared=A0and have a = few questions.=A0=0AI have seen the example but didn't find the answer ther= e. googled too.=0Ahttp://www.postgresql.org/docs/9.2/static/libpq-example.h= tml=0A=0A=0AQ1. what format is date set in ? what is the length ?=0A=0AQ2.Q= 2.what is the type and length of bit wise fields=0A=0AQ3. how to convert se= conds since epoch to date=0A=0AQ4. is int passable as time?=0A=0AQ5. the=A0= paramValsVec_ is char* const char[] . Can we type cast int to char* and pas= s in ? and set type to INT4OID?=0A=0ABelow is some pseudo code to put above= questions in perspective.=0A>>. table=A0=0ACREATE TABLE t1=0A(curdate =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 date,=0Astr1 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 varchar(19),=0Atm_new =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0timestampt= z,=0Acount =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int);=0A>>> c++ code= =A0PGconn* pgconn; // connected=0A=0Achar * UpsertStmt_=3D "INSERT INTO t1 = values( $1, $2, $3, $4)";=0A=0A=A0int result=3D0;=0A=A0PGresult* pgres =3D = PQprepare (pgconn, "stmtname", UpsertStmt_, 4, NULL);=0A=A0 int result =3D = PQresultStatus(pgres);=0A=A0 PQclear(pgres_);=0A=0A=0A=0Astruct mydata=0A{= =0Aint curtime;=0Achar str1[32];=0Aint mycount;=0A=A0intmybitfield=A0: 3;= =0A=0A},=0Amydata myvar;=0Amyvar.curtime=A0=3D time(NULL)=0A=0Astrcpy(myvar= .str1, hello);=0A=0Amyvar.mycount =3D 2;=0Amyvar.mybitfield =3D 2;=0A=0A=A0= // set helper vars=0A=A0paramLenVec_[0] =A0=3D 8;// Q1. what format is dat= e set in ? what is the length=0A=A0paramLenVec_[1] =A0=3D strlen(str1);=0A= =A0paramLenVec_[2] =A0=3D sizeof(int); =A0// type =3D INT4OID, sizeof (int)= =0A=A0paramLenVec_[3] =A0=3D sizeof(int);// Q2.what is the type and length = of bit wise fields=0A=0A=0A=A0 paramValsVec_[0] =A0=3D (char*)&myvar.curtim= e; // Q3. how to convert to date=0A=A0 paramValsVec_[1] =A0=3D=A0myvar.str1= ;=0A=A0 paramValsVec_[2] =A0=3D &myvar.curtime; // Q4. is int passable as t= ime=0A=A0 paramValsVec_[3] =A0=3D (char*)&myvar.mycount; // Q5.=A0=0APQexec= Prepared (pgconn, "stmtname", 4,=A0=0A=A0 =A0paramValsVec_,=0A=A0 =A0paramL= enVec_,=0A=A0 NULL, 0=0A); ---498039042-897902292-1369185968=:87888 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,
I'm trying a simple pgsql pro= gram 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
<= /div>

Q1. what format is date set in ? what is the lengt= h ?
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 quest= ions in perspective.
>>. table 
CREATE TABLE t1
(curdate        = ;         date,
str1       &nb= sp;             varchar(19),
tm_new            = ;      timestamptz,
count                =       int);
>>> c++ code
&nb= sp;PGconn* pgconn; // connected
char * UpsertStmt_=3D "INSE= RT INTO t1 values( $1, $2, $3, $4)";
 int result=3D0;
 PGresult* pgres =3D = PQprepare (pgconn, "stmtname", UpsertStmt_, 4, NULL);
  int = result =3D PQresultStatus(pgres);
  PQclear(pgres_);

struct mydata
{
int c= urtime;
char str1[32];
int mycount;
 int= =09mybitf= ield =09: 3;
},
mydata myvar;
myvar.curtime&n= bsp;=3D time(NULL)
strcpy(myvar.str1, hello);
myvar.my= count =3D 2;
myvar.mybitfield =3D 2;

&nb= sp; // set helper vars
 paramLenVec_[0]  =3D 8;=09// Q1. what form= at is date set in ? what is the length
 paramLenVec_[1]  =3D strlen(str1);
<= /div>
 paramLenVec_[2] =  =3D sizeof(int);  // type =3D INT4OID, sizeof (int)
<= div style=3D"color: rgb(69, 69, 69); font-family: 'Helvetica Neue', Helveti= ca, Arial, sans-serif; font-size: 12px; ">
 paramLenVec_[3]  = =3D sizeof(int);= =09// Q2.what is the type and length of bit wise fields


<= /div>
  paramValsVec_[0= ]  =3D (char*)&myvar.curtime; // Q3. how to convert to date
<= div>  paramValsVec_[1]  =3D myvar.str1;
  par= amValsVec_[2]  =3D &myvar.curtime; // Q4. is int passable as time<= /div>
  paramValsVec_[3]  =3D (char*)&myvar.mycount; // Q= 5. 
PQexecPrepared (pgconn, "stmtname", 4, 
&= nbsp;  paramValsVec_,
   paramLenVec_,
&= nbsp; NULL, 0
);


---498039042-897902292-1369185968=:87888--