1- /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.22 2001/08/24 14:07:49 petere Exp $ */
1+ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.23 2001/09/19 14:09:32 meskes Exp $ */
22
33/*
44 * The aim is to get a simpler inteface to the database routines.
@@ -817,6 +817,7 @@ ECPGexecute(struct statement * stmt)
817817 * it should go into a separate function
818818 */
819819{
820+ bool clear_result = TRUE;
820821var = stmt -> outlist ;
821822switch (PQresultStatus (results ))
822823{
@@ -840,7 +841,19 @@ ECPGexecute(struct statement * stmt)
840841break ;
841842}
842843
843- for (act_field = 0 ;act_field < nfields && status ;act_field ++ )
844+ if (var != NULL && var -> type == ECPGt_descriptor )
845+ {PGresult * * resultpp = ECPGdescriptor_lvalue (stmt -> lineno , (const char * )var -> pointer );
846+ if (resultpp == NULL )status = false;
847+ else
848+ {if (* resultpp )
849+ PQclear (* resultpp );
850+ * resultpp = results ;
851+ clear_result = FALSE;
852+ ECPGlog ("ECPGexecute putting result into descriptor '%s'\n" , (const char * )var -> pointer );
853+ }
854+ var = var -> next ;
855+ }
856+ else for (act_field = 0 ;act_field < nfields && status ;act_field ++ )
844857{
845858if (var == NULL )
846859{
@@ -972,7 +985,7 @@ ECPGexecute(struct statement * stmt)
972985status = false;
973986break ;
974987}
975- PQclear (results );
988+ if ( clear_result ) PQclear (results );
976989}
977990
978991/* check for asynchronous returns */
@@ -1032,186 +1045,12 @@ ECPGdo(int lineno, const char *connection_name, char *query,...)
10321045return (status );
10331046}
10341047
1035- /* dynamic SQL support routines
1036- *
1037- * Copyright (c) 2000, Christof Petig <christof.petig@wtal.de>
1038- *
1039- * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.22 2001/08/24 14:07:49 petere Exp $
1040- */
1041-
1042- PGconn * ECPG_internal_get_connection (char * name );
1043-
1044- extern struct descriptor
1045- {
1046- char * name ;
1047- PGresult * result ;
1048- struct descriptor * next ;
1049- }* all_descriptors ;
1050-
1051- /* like ECPGexecute */
1052- static bool
1053- execute_descriptor (int lineno ,const char * query
1054- ,struct connection * con ,PGresult * * resultptr )
1055- {
1056- bool status = false;
1057- PGresult * results ;
1058- PGnotify * notify ;
1059-
1060- /* Now the request is built. */
1061-
1062- if (con -> committed && !con -> autocommit )
1063- {
1064- if ((results = PQexec (con -> connection ,"begin transaction" ))== NULL )
1065- {
1066- ECPGraise (lineno ,ECPG_TRANS ,NULL );
1067- return false;
1068- }
1069- PQclear (results );
1070- con -> committed = false;
1071- }
1072-
1073- ECPGlog ("execute_descriptor line %d: QUERY: %s on connection %s\n" ,lineno ,query ,con -> name );
1074- results = PQexec (con -> connection ,query );
1075-
1076- if (results == NULL )
1077- {
1078- ECPGlog ("ECPGexecute line %d: error: %s" ,lineno ,
1079- PQerrorMessage (con -> connection ));
1080- ECPGraise (lineno ,ECPG_PGSQL ,PQerrorMessage (con -> connection ));
1081- }
1082- else
1083- {
1084- * resultptr = results ;
1085- switch (PQresultStatus (results ))
1086- {
1087- int ntuples ;
1088-
1089- case PGRES_TUPLES_OK :
1090- status = true;
1091- sqlca .sqlerrd [2 ]= ntuples = PQntuples (results );
1092- if (ntuples < 1 )
1093- {
1094- ECPGlog ("execute_descriptor line %d: Incorrect number of matches: %d\n" ,
1095- lineno ,ntuples );
1096- ECPGraise (lineno ,ECPG_NOT_FOUND ,NULL );
1097- status = false;
1098- break ;
1099- }
1100- break ;
1101- #if 1 /* strictly these are not needed (yet) */
1102- case PGRES_EMPTY_QUERY :
1103- /* do nothing */
1104- ECPGraise (lineno ,ECPG_EMPTY ,NULL );
1105- break ;
1106- case PGRES_COMMAND_OK :
1107- status = true;
1108- sqlca .sqlerrd [1 ]= PQoidValue (results );
1109- sqlca .sqlerrd [2 ]= atol (PQcmdTuples (results ));
1110- ECPGlog ("ECPGexecute line %d Ok: %s\n" ,lineno ,PQcmdStatus (results ));
1111- break ;
1112- case PGRES_COPY_OUT :
1113- ECPGlog ("ECPGexecute line %d: Got PGRES_COPY_OUT ... tossing.\n" ,lineno );
1114- PQendcopy (con -> connection );
1115- break ;
1116- case PGRES_COPY_IN :
1117- ECPGlog ("ECPGexecute line %d: Got PGRES_COPY_IN ... tossing.\n" ,lineno );
1118- PQendcopy (con -> connection );
1119- break ;
1120- #else
1121- case PGRES_EMPTY_QUERY :
1122- case PGRES_COMMAND_OK :
1123- case PGRES_COPY_OUT :
1124- case PGRES_COPY_IN :
1125- break ;
1126- #endif
1127- case PGRES_NONFATAL_ERROR :
1128- case PGRES_FATAL_ERROR :
1129- case PGRES_BAD_RESPONSE :
1130- ECPGlog ("ECPGexecute line %d: Error: %s" ,
1131- lineno ,PQerrorMessage (con -> connection ));
1132- ECPGraise (lineno ,ECPG_PGSQL ,PQerrorMessage (con -> connection ));
1133- status = false;
1134- break ;
1135- default :
1136- ECPGlog ("ECPGexecute line %d: Got something else, postgres error.\n" ,
1137- lineno );
1138- ECPGraise (lineno ,ECPG_PGSQL ,PQerrorMessage (con -> connection ));
1139- status = false;
1140- break ;
1141- }
1142- }
1143-
1144- /* check for asynchronous returns */
1145- notify = PQnotifies (con -> connection );
1146- if (notify )
1147- {
1148- ECPGlog ("ECPGexecute line %d: ASYNC NOTIFY of '%s' from backend pid '%d' received\n" ,
1149- lineno ,notify -> relname ,notify -> be_pid );
1150- free (notify );
1151- }
1152- return status ;
1153- }
1154-
1155- /* like ECPGdo */
1156- static bool
1157- do_descriptor2 (int lineno ,const char * connection_name ,
1158- PGresult * * resultptr ,const char * query )
1159- {
1160- struct connection * con = get_connection (connection_name );
1161- bool status = true;
1162- char * locale = setlocale (LC_NUMERIC ,NULL );
1163-
1164- /* Make sure we do NOT honor the locale for numeric input/output */
1165- /* since the database wants teh standard decimal point */
1166- setlocale (LC_NUMERIC ,"C" );
1167-
1168- if (!ecpg_init (con ,connection_name ,lineno ))
1169- {
1170- setlocale (LC_NUMERIC ,locale );
1171- return (false);
1172- }
1173-
1174- /* are we connected? */
1175- if (con == NULL || con -> connection == NULL )
1176- {
1177- ECPGlog ("do_descriptor2: not connected to %s\n" ,con -> name );
1178- ECPGraise (lineno ,ECPG_NOT_CONN ,NULL );
1179- setlocale (LC_NUMERIC ,locale );
1180- return false;
1181- }
1182-
1183- status = execute_descriptor (lineno ,query ,con ,resultptr );
1184-
1185- /* and reset locale value so our application is not affected */
1186- setlocale (LC_NUMERIC ,locale );
1187- return (status );
1188- }
1189-
1048+ /* old descriptor interface */
11901049bool
11911050ECPGdo_descriptor (int line ,const char * connection ,
11921051const char * descriptor ,const char * query )
11931052{
1194- struct descriptor * i ;
1195-
1196- for (i = all_descriptors ;i != NULL ;i = i -> next )
1197- {
1198- if (!strcmp (descriptor ,i -> name ))
1199- {
1200- bool status ;
1201-
1202- /* free previous result */
1203- if (i -> result )
1204- PQclear (i -> result );
1205- i -> result = NULL ;
1206-
1207- status = do_descriptor2 (line ,connection ,& i -> result ,query );
1208-
1209- if (!i -> result )
1210- PQmakeEmptyPGresult (NULL ,0 );
1211- return (status );
1212- }
1213- }
1214-
1215- ECPGraise (line ,ECPG_UNKNOWN_DESCRIPTOR , (char * )descriptor );
1216- return false;
1053+ return ECPGdo (line ,connection , (char * )query ,ECPGt_EOIT ,
1054+ ECPGt_descriptor ,descriptor ,0L ,0L ,0L ,
1055+ ECPGt_NO_INDICATOR ,NULL ,0L ,0L ,0L ,ECPGt_EORT );
12171056}