logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

PQexecf - Prepares parameters and executes a command.

Author

       A contribution of eSilo, LLC. for the PostgreSQL Database Management System.  Written by  Andrew  Chernow
       and Merlin Moncure.

Description

       The  PQexecf() function executes a command that uses libpqtypes type specifiers instead of $1, $2, etc...
       syntax.  The idea is to combine PQputvf() and PQparamExec() into a single call.   The  variable  argument
       list  must  match  the  type  specs listed within the cmd. The type specifiers should be placed where one
       would normally place $1, $2, etc...

       The PQexecvf() function is identical to PQexecf() except it takes a va_list.

       The PQsendf() and PQsendvf() functions  are  identical  to  PQexecf()  and  PQexecvf()  except  they  are
       asynchronous  versions,  meaning  an  additional  call,  PQgetResult,  must be issued to get the PGresult
       object.  For more information, see the PostgreSQL Documentation: specifically the  "Asynchronous  Command
       Processing" section under "Client Interfaces | libpq - C library".

       A  prepared  type  spec "@name" can be used with these functions, granted that PQspecPrepare() was called
       with a non-zero value for the is_stmt argument.   These  functions  needs  an  actual  SQL  statement  to
       execute.

Examples

UsingPQexecf
       The example uses PQexecf function to execute a query.

              /*ThePQexecfcallisshorthandfor:**PGparam*param=PQparamCreate(conn);*PQputf(param,"%int4%int4",1,1);*res=PQparamExec(conn,param,"SELECT$1+$2",1);*PQparamClear(param);**Asyoumaynotice,PQexecfmakeslifemuchsimpler.*/PGresult*res=PQexecf(conn,"SELECT%int4+%int4",1,1);if(!res)fprintf(stderr,"PQexecffailed:%s",PQgeterror());elsePQclear(res);/*Abitmorecommon,thisputsanint4andatextintoagenerated*PGparamandthenexecutes'myfunc($1,$2)'*/res=PQexecf(conn,"SELECT*FROMmyfunc(%int4,%text)",2,"abc");/*Preparedtypespecexample.Tousewithexecf,thefinal"is_stmt"*argumentmustbesettoanon-zerovalue!*/PQspecPrepare(conn,"account_insert","INSERTINTOaccountVALUES""(%int8,%text,%int4)",1);PGint8acc_id=78236;PGtextacc_name="ABCCoders,LLC.";PGint4acc_biz=ACC_BIZ_TECHNOLOGY;PQexecf(conn,"@account_insert",acc_id,acc_name,acc_biz);

Name

       PQexecf - Prepares parameters and executes a command.

Reporting Bugs

       Report bugs to <libpqtypes@esilo.com>.

Return Value

       PQexecf  and  PQexecvf return NULL on error and a valid PGresult on success.  PQsendf and PQsendvf return
       zero on error and a non-zero value on success.  On error, use PQgeterror(3) to obtain an error message.

See Also

PQgeterror(3), PQputvf(3), PQparamExec(3)

libpqtypes                                            2011                                            PQexecf(3)

Synopsis

#include<libpqtypes.h>PGresult*PQexecf(constPGconn*conn,constchar*cmd,...);PGresult*PQexecvf(constPGconn*conn,constchar*cmd,va_listap);intPQsendf(constPGconn*conn,constchar*cmd,...);intPQsendvf(constPGconn*conn,constchar*cmd,va_listap);

See Also