Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfa9db42

Browse files
committed
From: Michael Meskes <Michael_Meskes@topmail.de>++ Son Feb 21 14:10:47 CET 1999++ - Fixed variable detection in libecpg.++ Mon Feb 22 19:47:45 CET 1999++ - Added 'at <db_connection>' option to all commands it is apllicable+ to. Due to changing the API of some libecpg functions this+ requires me to increase the major version number.+ - Synced pgc.l with scan.l.+ - Added support for unions.+ - Set library version to 3.0.0+ - Set ecpg version to 3.0.0
1 parente17d844 commitfa9db42

File tree

18 files changed

+240
-98
lines changed

18 files changed

+240
-98
lines changed

‎src/interfaces/ecpg/ChangeLog

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,17 @@ Fri Feb 19 21:40:14 CET 1999
463463
- Fixed bug in libecpg that caused it to start transactions only for
464464
the first connection.
465465
- Set library version to 2.7.1
466+
467+
Son Feb 21 14:10:47 CET 1999
468+
469+
- Fixed variable detection in libecpg.
470+
471+
Mon Feb 22 19:47:45 CET 1999
472+
473+
- Added 'at <db_connection>' option to all commands it is apllicable
474+
to. Due to changing the API of some libecpg functions this
475+
requires me to increase the major version number.
476+
- Synced pgc.l with scan.l.
477+
- Added support for unions.
478+
- Set library version to 3.0.0
479+
- Set ecpg version to 3.0.0

‎src/interfaces/ecpg/TODO

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ DESCRIPTOR statement will be ignored.
1111

1212
it would be nice to be able to use :var[:index] as cvariable
1313

14-
'at DB connection' is missing for several commands (is this standard?)
14+
support for dynamic SQL with unknown number of variables with SQLDA structure
1515

16-
supportforunions
16+
allocate memoryforpointers as C input variables
1717

1818
Missing statements:
1919
- exec sql allocate

‎src/interfaces/ecpg/include/ecpglib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ extern"C"
88
voidECPGdebug(int,FILE*);
99
boolECPGsetconn(int,constchar*);
1010
boolECPGconnect(int,constchar*,constchar*,constchar*,constchar*);
11-
boolECPGdo(int,char*,...);
12-
boolECPGtrans(int,constchar*);
11+
boolECPGdo(int,constchar*,char*,...);
12+
boolECPGtrans(int,constchar*,constchar*);
1313
boolECPGdisconnect(int,constchar*);
1414
boolECPGprepare(int,char*,char*);
1515
boolECPGdeallocate(int,char*);

‎src/interfaces/ecpg/include/ecpgtype.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ extern"C"
4343
ECPGt_varchar,ECPGt_varchar2,
4444
ECPGt_array,
4545
ECPGt_struct,
46+
ECPGt_char_variable,
4647
ECPGt_EOIT,/* End of insert types. */
4748
ECPGt_EORT,/* End of result types. */
48-
ECPGt_NO_INDICATOR,/* no indicator */
49-
ECPGt_char_variable
49+
ECPGt_NO_INDICATOR/* no indicator */
5050
};
5151

5252
#defineIS_SIMPLE_TYPE(type) ((type) >= ECPGt_char && (type) <= ECPGt_varchar2)

‎src/interfaces/ecpg/lib/Makefile.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
# Copyright (c) 1994, Regents of the University of California
77
#
88
# IDENTIFICATION
9-
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.42 1999/02/21 03:02:35 scrappy Exp $
9+
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.43 1999/02/23 12:56:55 scrappy Exp $
1010
#
1111
#-------------------------------------------------------------------------
1212

1313
NAME= ecpg
14-
SO_MAJOR_VERSION=2
15-
SO_MINOR_VERSION=7.1
14+
SO_MAJOR_VERSION=3
15+
SO_MINOR_VERSION=0.0
1616

1717
SRCDIR= @top_srcdir@
1818
include$(SRCDIR)/Makefile.global

‎src/interfaces/ecpg/lib/ecpglib.c

Lines changed: 97 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include<unistd.h>
1818
#include<stdarg.h>
1919
#include<string.h>
20+
#include<ctype.h>
2021

2122
#include<libpq-fe.h>
2223
#include<libpq/pqcomm.h>
@@ -78,6 +79,7 @@ struct statement
7879
{
7980
intlineno;
8081
char*command;
82+
structconnection*connection;
8183
structvariable*inlist;
8284
structvariable*outlist;
8385
};
@@ -104,6 +106,21 @@ register_error(long code, char *fmt,...)
104106
sqlca.sqlerrm.sqlerrml=strlen(sqlca.sqlerrm.sqlerrmc);
105107
}
106108

109+
staticstructconnection*
110+
get_connection(constchar*connection_name)
111+
{
112+
structconnection*con=all_connections;;
113+
114+
if (connection_name==NULL||strcmp(connection_name,"CURRENT")==0)
115+
returnactual_connection;
116+
117+
for (;con&&strcmp(connection_name,con->name)!=0;con=con->next);
118+
if (con)
119+
returncon;
120+
else
121+
returnNULL;
122+
}
123+
107124
staticvoid
108125
ECPGfinish(structconnection*act)
109126
{
@@ -145,7 +162,6 @@ ecpg_alloc(long size, int lineno)
145162

146163
if (!new)
147164
{
148-
ECPGfinish(actual_connection);
149165
ECPGlog("out of memory\n");
150166
register_error(ECPG_OUT_OF_MEMORY,"out of memory in line %d",lineno);
151167
returnNULL;
@@ -162,7 +178,6 @@ ecpg_strdup(const char *string, int lineno)
162178

163179
if (!new)
164180
{
165-
ECPGfinish(actual_connection);
166181
ECPGlog("out of memory\n");
167182
register_error(ECPG_OUT_OF_MEMORY,"out of memory in line %d",lineno);
168183
returnNULL;
@@ -238,9 +253,26 @@ quote_strings(char *arg, int lineno)
238253
returnres;
239254
}
240255

241-
/* create a list of variables */
256+
/*
257+
* create a list of variables
258+
* The variables are listed with input variables preceeding outputvariables
259+
* The end of each group is marked by an end marker.
260+
* per variable we list:
261+
* type - as defined in ecpgtype.h
262+
* value - where to store the data
263+
* varcharsize - length of string in case we have a stringvariable, else 0
264+
* arraysize - 0 for pointer (we don't know the size of the array),
265+
* 1 for simple variable, size for arrays
266+
* offset - offset between ith and (i+1)th entry in an array,
267+
* normally that means sizeof(type)
268+
* ind_type - type of indicator variable
269+
* ind_value - pointer to indicator variable
270+
* ind_varcharsize - empty
271+
* ind_arraysize - arraysize of indicator array
272+
* ind_offset - indicator offset
273+
*/
242274
staticbool
243-
create_statement(intlineno,structstatement**stmt,char*query,va_listap)
275+
create_statement(intlineno,structconnection*connection,structstatement**stmt,char*query,va_listap)
244276
{
245277
structvariable**list=&((*stmt)->inlist);
246278
enumECPGttypetype;
@@ -249,6 +281,7 @@ create_statement(int lineno, struct statement ** stmt, char *query, va_list ap)
249281
return false;
250282

251283
(*stmt)->command=query;
284+
(*stmt)->connection=connection;
252285
(*stmt)->lineno=lineno;
253286

254287
list=&((*stmt)->inlist);
@@ -278,7 +311,8 @@ create_statement(int lineno, struct statement ** stmt, char *query, va_list ap)
278311
var->ind_arrsize=va_arg(ap,long);
279312
var->ind_offset=va_arg(ap,long);
280313
var->next=NULL;
281-
314+
315+
/* if variable is NULL, the statement hasn't been prepared */
282316
if (var->value==NULL)
283317
{
284318
ECPGlog("create_statement: invalid statement name\n");
@@ -564,27 +598,27 @@ ECPGexecute(struct statement * stmt)
564598

565599
/* Now the request is built. */
566600

567-
if (actual_connection->committed&& !no_auto_trans)
601+
if (stmt->connection->committed&& !no_auto_trans)
568602
{
569-
if ((results=PQexec(actual_connection->connection,"begin transaction"))==NULL)
603+
if ((results=PQexec(stmt->connection->connection,"begin transaction"))==NULL)
570604
{
571605
register_error(ECPG_TRANS,"Error starting transaction line %d.",stmt->lineno);
572606
return false;
573607
}
574608
PQclear(results);
575-
actual_connection->committed= false;
609+
stmt->connection->committed= false;
576610
}
577611

578-
ECPGlog("ECPGexecute line %d: QUERY: %s\n",stmt->lineno,copiedquery);
579-
results=PQexec(actual_connection->connection,copiedquery);
612+
ECPGlog("ECPGexecute line %d: QUERY: %s on connection %s\n",stmt->lineno,copiedquery,stmt->connection->name);
613+
results=PQexec(stmt->connection->connection,copiedquery);
580614
free(copiedquery);
581615

582616
if (results==NULL)
583617
{
584618
ECPGlog("ECPGexecute line %d: error: %s",stmt->lineno,
585-
PQerrorMessage(actual_connection->connection));
619+
PQerrorMessage(stmt->connection->connection));
586620
register_error(ECPG_PGSQL,"Postgres error: %s line %d.",
587-
PQerrorMessage(actual_connection->connection),stmt->lineno);
621+
PQerrorMessage(stmt->connection->connection),stmt->lineno);
588622
}
589623
else
590624
{
@@ -642,6 +676,7 @@ ECPGexecute(struct statement * stmt)
642676
status= false;
643677
break;
644678
}
679+
645680
for (act_tuple=0;act_tuple<ntuples;act_tuple++)
646681
{
647682
pval=PQgetvalue(results,act_tuple,act_field);
@@ -909,18 +944,18 @@ ECPGexecute(struct statement * stmt)
909944
casePGRES_FATAL_ERROR:
910945
casePGRES_BAD_RESPONSE:
911946
ECPGlog("ECPGexecute line %d: Error: %s",
912-
stmt->lineno,PQerrorMessage(actual_connection->connection));
947+
stmt->lineno,PQerrorMessage(stmt->connection->connection));
913948
register_error(ECPG_PGSQL,"Error: %s line %d.",
914-
PQerrorMessage(actual_connection->connection),stmt->lineno);
949+
PQerrorMessage(stmt->connection->connection),stmt->lineno);
915950
status= false;
916951
break;
917952
casePGRES_COPY_OUT:
918953
ECPGlog("ECPGexecute line %d: Got PGRES_COPY_OUT ... tossing.\n",stmt->lineno);
919-
PQendcopy(actual_connection->connection);
954+
PQendcopy(stmt->connection->connection);
920955
break;
921956
casePGRES_COPY_IN:
922957
ECPGlog("ECPGexecute line %d: Got PGRES_COPY_IN ... tossing.\n",stmt->lineno);
923-
PQendcopy(actual_connection->connection);
958+
PQendcopy(stmt->connection->connection);
924959
break;
925960
default:
926961
ECPGlog("ECPGexecute line %d: Got something else, postgres error.\n",
@@ -932,7 +967,7 @@ ECPGexecute(struct statement * stmt)
932967
}
933968

934969
/* check for asynchronous returns */
935-
notify=PQnotifies(actual_connection->connection);
970+
notify=PQnotifies(stmt->connection->connection);
936971
if (notify)
937972
{
938973
ECPGlog("ECPGexecute line %d: ASYNC NOTIFY of '%s' from backend pid '%d' received\n",
@@ -944,20 +979,27 @@ ECPGexecute(struct statement * stmt)
944979
}
945980

946981
bool
947-
ECPGdo(intlineno,char*query,...)
982+
ECPGdo(intlineno,constchar*connection_name,char*query,...)
948983
{
949984
va_listargs;
950985
structstatement*stmt;
986+
structconnection*con=get_connection(connection_name);
951987

988+
if (con==NULL)
989+
{
990+
register_error(ECPG_NO_CONN,"No such connection %s in line %d",connection_name,lineno);
991+
return (false);
992+
}
993+
952994
va_start(args,query);
953-
if (create_statement(lineno,&stmt,query,args)== false)
995+
if (create_statement(lineno,con,&stmt,query,args)== false)
954996
return (false);
955997
va_end(args);
956998

957999
/* are we connected? */
958-
if (actual_connection==NULL||actual_connection->connection==NULL)
1000+
if (con==NULL||con->connection==NULL)
9591001
{
960-
ECPGlog("ECPGdo: not connected\n");
1002+
ECPGlog("ECPGdo: not connected to %s\n",con->name);
9611003
register_error(ECPG_NOT_CONN,"Not connected in line %d",lineno);
9621004
return false;
9631005
}
@@ -967,16 +1009,23 @@ ECPGdo(int lineno, char *query,...)
9671009

9681010

9691011
bool
970-
ECPGtrans(intlineno,constchar*transaction)
1012+
ECPGtrans(intlineno,constchar*connection_name,constchar*transaction)
9711013
{
9721014
PGresult*res;
1015+
structconnection*con=get_connection(connection_name);
1016+
1017+
if (con==NULL)
1018+
{
1019+
register_error(ECPG_NO_CONN,"No such connection %s in line %d",connection_name,lineno);
1020+
return (false);
1021+
}
9731022

974-
ECPGlog("ECPGtrans line %d action = %s\n",lineno,transaction);
1023+
ECPGlog("ECPGtrans line %d action = %s connection = %s\n",lineno,transaction,con->name);
9751024

9761025
/* if we have no connection we just simulate the command */
977-
if (actual_connection&&actual_connection->connection)
1026+
if (con&&con->connection)
9781027
{
979-
if ((res=PQexec(actual_connection->connection,transaction))==NULL)
1028+
if ((res=PQexec(con->connection,transaction))==NULL)
9801029
{
9811030
register_error(ECPG_TRANS,"Error in transaction processing line %d.",lineno);
9821031
return FALSE;
@@ -987,7 +1036,7 @@ ECPGtrans(int lineno, const char *transaction)
9871036
{
9881037
structprepared_statement*this;
9891038

990-
actual_connection->committed= true;
1039+
con->committed= true;
9911040

9921041
/* deallocate all prepared statements */
9931042
for (this=prep_stmts;this!=NULL;this=this->next)
@@ -1005,11 +1054,8 @@ ECPGtrans(int lineno, const char *transaction)
10051054
bool
10061055
ECPGsetconn(intlineno,constchar*connection_name)
10071056
{
1008-
structconnection*con=all_connections;
1009-
1010-
ECPGlog("ECPGsetconn: setting actual connection to %s\n",connection_name);
1057+
structconnection*con=get_connection(connection_name);
10111058

1012-
for (;con&&strcmp(connection_name,con->name)!=0;con=con->next);
10131059
if (con)
10141060
{
10151061
actual_connection=con;
@@ -1070,9 +1116,7 @@ ECPGdisconnect(int lineno, const char *connection_name)
10701116
{
10711117
structconnection*con;
10721118

1073-
if (strcmp(connection_name,"CURRENT")==0)
1074-
ECPGfinish(actual_connection);
1075-
elseif (strcmp(connection_name,"ALL")==0)
1119+
if (strcmp(connection_name,"ALL")==0)
10761120
{
10771121
for (con=all_connections;con;)
10781122
{
@@ -1084,7 +1128,8 @@ ECPGdisconnect(int lineno, const char *connection_name)
10841128
}
10851129
else
10861130
{
1087-
for (con=all_connections;con&&strcmp(con->name,connection_name)!=0;con=con->next);
1131+
con=get_connection(connection_name);
1132+
10881133
if (con==NULL)
10891134
{
10901135
ECPGlog("disconnect: not connected to connection %s\n",connection_name);
@@ -1136,6 +1181,21 @@ sqlprint(void)
11361181
printf("sql error %s\n",sqlca.sqlerrm.sqlerrmc);
11371182
}
11381183

1184+
staticbool
1185+
isvarchar(unsignedcharc)
1186+
{
1187+
if (isalnum(c))
1188+
return true;
1189+
1190+
if (c=='_'||c=='>'||c=='-'||c=='.')
1191+
return true;
1192+
1193+
if (c >=128)
1194+
return true;
1195+
1196+
return(false);
1197+
}
1198+
11391199
staticvoid
11401200
replace_variables(char*text)
11411201
{
@@ -1150,7 +1210,7 @@ replace_variables(char *text)
11501210
if (!string&&*ptr==':')
11511211
{
11521212
ptr[0]=ptr[1]=';';
1153-
for (ptr+=2;*ptr&&*ptr!=' ';ptr++)
1213+
for (ptr+=2;*ptr&&isvarchar(*ptr);ptr++)
11541214
*ptr=' ';
11551215
}
11561216
}
@@ -1162,7 +1222,7 @@ ECPGprepare(int lineno, char *name, char *variable)
11621222
{
11631223
structstatement*stmt;
11641224
structprepared_statement*this;
1165-
1225+
11661226
/* check if we already have prepared this statement */
11671227
for (this=prep_stmts;this!=NULL&&strcmp(this->name,name)!=0;this=this->next);
11681228
if (this)
@@ -1186,6 +1246,7 @@ ECPGprepare(int lineno, char *name, char *variable)
11861246

11871247
/* create statement */
11881248
stmt->lineno=lineno;
1249+
stmt->connection=NULL;
11891250
stmt->command=ecpg_strdup(variable,lineno);
11901251
stmt->inlist=stmt->outlist=NULL;
11911252

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp