Search Postgresql Archives

Re: code example for PQgetCopyData

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 


From: pgsql-general-owner@xxxxxxxxxxxxxx [mailto:pgsql-general-owner@xxxxxxxxxxxxxx] On Behalf Of Dave Huber
Sent: Thursday, December 03, 2009 9:18 AM
To: pgsql-general@xxxxxxxxxxxxxx
Subject: code example for PQgetCopyData

Does anybody have a snippet where they use PQgetCopyData? I must be calling it wrong as it keep crashing my program. I’ve attached my code below. I am writing this for a Code Interface Node in LabVIEW.

 

Thanks,

Dave

 

MgErr CINRun(LStrHandle conninfo, LStrHandle copystr, TD1Hdl resultValues) {

      MgErr err = noErr;

      PGconn *pConn;

      PGresult* pResult = NULL;

      char* szCopyStr = NULL;

      char* errormsg = NULL;

      char** buffer = NULL;               // for retrieving the data

      int nLen;                                 // length of returned data

     

      // connect to the database

      char* szConnInfo = new char[LHStrLen(conninfo)+1];

      LToCStr((*(conninfo)), (CStr)szConnInfo);

      pConn = PQconnectdb(szConnInfo);

      delete [] szConnInfo;

 

      // check for errors connecting to database

      if (PQstatus(pConn) != CONNECTION_OK)

      {

            DbgPrintf("Connection to database failed: %s", PQerrorMessage(pConn));

      }

      else

      {

            // start the copy command

            szCopyStr = new char[LHStrLen(copystr)+1];

            LToCStr((*(copystr)), (CStr)szCopyStr);

 

            pResult = PQexec(pConn, szCopyStr);

            delete [] szCopyStr;

     

            // get the data

            int i = 0;

            while (nLen = PQgetCopyData(pConn, buffer, false) > 0)

            {

     

                  if (err = SetCINArraySize((UHandle)resultValues, 2, ++i))

                        goto out;

                  if (err = NumericArrayResize(uB, 1L, (UHandle*)(&(*resultValues)->elt[i-1]), nLen-1))

                        goto out;

                  LStrLen(*(*resultValues)->elt[i-1]) = nLen-1;                                 // set the Labview String size

                  MoveBlock(*buffer, LStrBuf(*(*resultValues)->elt[i-1]), nLen-1);  // copy the data to a new string

 

                  PQfreemem(*buffer);                                                                             // free the memory from getCopy

           

            }

            (*resultValues)->dimSize = i;

     

out:       

            PQclear(pResult);

 

            // see if there were errors

            if (nLen == -2)

            {

                  DbgPrintf("Copy Out failed: %s", PQerrorMessage(pConn));

            }

 

      }

      // close the connection

      PQfinish(pConn);

 

      return err;

}

 
Where is it blowing up?
 
 

This electronic mail message is intended exclusively for the individual(s) or entity to which it is addressed. This message, together with any attachment, is confidential and may contain privileged information. Any unauthorized review, use, printing, retaining, copying, disclosure or distribution is strictly prohibited. If you have received this message in error, please immediately advise the sender by reply email message to the sender and delete all copies of this message.
THIS E-MAIL IS NOT AN OFFER OR ACCEPTANCE: Notwithstanding the Uniform Electronic Transactions Act or any other law of similar import, absent an express statement to the contrary contained in this e-mail, neither this e-mail nor any attachments are an offer or acceptance to enter into a contract, and are not intended to bind the sender, LeTourneau Technologies, Inc., or any of its subsidiaries, affiliates, or any other person or entity.
WARNING: Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux