Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
d49b20fb
Commit
d49b20fb
authored
Sep 26, 2007
by
Michael Meskes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Applied patch by ITAGAKI Takahiro <itagaki.takahiro@oss.ntt.co.jp> to get prepare thread-safe.
parent
689df1bc
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
512 additions
and
120 deletions
+512
-120
src/interfaces/ecpg/ChangeLog
src/interfaces/ecpg/ChangeLog
+5
-0
src/interfaces/ecpg/ecpglib/connect.c
src/interfaces/ecpg/ecpglib/connect.c
+2
-1
src/interfaces/ecpg/ecpglib/execute.c
src/interfaces/ecpg/ecpglib/execute.c
+2
-2
src/interfaces/ecpg/ecpglib/extern.h
src/interfaces/ecpg/ecpglib/extern.h
+3
-2
src/interfaces/ecpg/ecpglib/prepare.c
src/interfaces/ecpg/ecpglib/prepare.c
+109
-85
src/interfaces/ecpg/include/ecpglib.h
src/interfaces/ecpg/include/ecpglib.h
+4
-4
src/interfaces/ecpg/preproc/output.c
src/interfaces/ecpg/preproc/output.c
+4
-3
src/interfaces/ecpg/preproc/preproc.y
src/interfaces/ecpg/preproc/preproc.y
+17
-12
src/interfaces/ecpg/test/ecpg_schedule
src/interfaces/ecpg/test/ecpg_schedule
+1
-0
src/interfaces/ecpg/test/ecpg_schedule_tcp
src/interfaces/ecpg/test/ecpg_schedule_tcp
+1
-0
src/interfaces/ecpg/test/expected/sql-desc.c
src/interfaces/ecpg/test/expected/sql-desc.c
+4
-4
src/interfaces/ecpg/test/expected/sql-dyntest.c
src/interfaces/ecpg/test/expected/sql-dyntest.c
+1
-1
src/interfaces/ecpg/test/expected/sql-execute.c
src/interfaces/ecpg/test/expected/sql-execute.c
+3
-3
src/interfaces/ecpg/test/expected/sql-oldexec.c
src/interfaces/ecpg/test/expected/sql-oldexec.c
+2
-2
src/interfaces/ecpg/test/expected/thread-prep.c
src/interfaces/ecpg/test/expected/thread-prep.c
+256
-0
src/interfaces/ecpg/test/expected/thread-prep.stderr
src/interfaces/ecpg/test/expected/thread-prep.stderr
+0
-0
src/interfaces/ecpg/test/expected/thread-prep.stdout
src/interfaces/ecpg/test/expected/thread-prep.stdout
+1
-0
src/interfaces/ecpg/test/expected/thread-prep_2.stdout
src/interfaces/ecpg/test/expected/thread-prep_2.stdout
+0
-0
src/interfaces/ecpg/test/thread/Makefile
src/interfaces/ecpg/test/thread/Makefile
+2
-1
src/interfaces/ecpg/test/thread/prep.pgc
src/interfaces/ecpg/test/thread/prep.pgc
+95
-0
No files found.
src/interfaces/ecpg/ChangeLog
View file @
d49b20fb
...
@@ -2237,5 +2237,10 @@ Wed, 29 Aug 2007 15:41:58 +0200
...
@@ -2237,5 +2237,10 @@ Wed, 29 Aug 2007 15:41:58 +0200
Tue, 04 Sep 2007 11:13:55 +0200
Tue, 04 Sep 2007 11:13:55 +0200
- Synced parser and keyword list.
- Synced parser and keyword list.
Mi 26. Sep 12:45:51 CEST 2007
- Applied patch by ITAGAKI Takahiro <itagaki.takahiro@oss.ntt.co.jp>
to get prepare thread-safe.
- Set ecpg library version to 6.0.
- Set ecpg library version to 6.0.
- Set ecpg version to 4.4.
- Set ecpg version to 4.4.
src/interfaces/ecpg/ecpglib/connect.c
View file @
d49b20fb
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.4
2 2007/08/14 10:01:52
meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.4
3 2007/09/26 10:57:00
meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
#include "postgres_fe.h"
...
@@ -460,6 +460,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
...
@@ -460,6 +460,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
this
->
name
=
ECPGstrdup
(
realname
,
lineno
);
this
->
name
=
ECPGstrdup
(
realname
,
lineno
);
this
->
cache_head
=
NULL
;
this
->
cache_head
=
NULL
;
this
->
prep_stmts
=
NULL
;
if
(
all_connections
==
NULL
)
if
(
all_connections
==
NULL
)
this
->
next
=
NULL
;
this
->
next
=
NULL
;
...
...
src/interfaces/ecpg/ecpglib/execute.c
View file @
d49b20fb
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.
69 2007/09/21 10:59:27
meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.
70 2007/09/26 10:57:00
meskes Exp $ */
/*
/*
* The aim is to get a simpler inteface to the database routines.
* The aim is to get a simpler inteface to the database routines.
...
@@ -1515,7 +1515,7 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char
...
@@ -1515,7 +1515,7 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char
if
(
statement_type
==
ECPGst_execute
)
if
(
statement_type
==
ECPGst_execute
)
{
{
/* if we have an EXECUTE command, only the name is send */
/* if we have an EXECUTE command, only the name is send */
char
*
command
=
ECPGprepared
(
stmt
->
command
,
lineno
);
char
*
command
=
ECPGprepared
(
stmt
->
command
,
con
,
lineno
);
if
(
command
)
if
(
command
)
{
{
...
...
src/interfaces/ecpg/ecpglib/extern.h
View file @
d49b20fb
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.2
6 2007/08/14 10:54:57
meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.2
7 2007/09/26 10:57:00
meskes Exp $ */
#ifndef _ECPG_LIB_EXTERN_H
#ifndef _ECPG_LIB_EXTERN_H
#define _ECPG_LIB_EXTERN_H
#define _ECPG_LIB_EXTERN_H
...
@@ -91,6 +91,7 @@ struct connection
...
@@ -91,6 +91,7 @@ struct connection
bool
committed
;
bool
committed
;
int
autocommit
;
int
autocommit
;
struct
ECPGtype_information_cache
*
cache_head
;
struct
ECPGtype_information_cache
*
cache_head
;
struct
prepared_statement
*
prep_stmts
;
struct
connection
*
next
;
struct
connection
*
next
;
};
};
...
@@ -144,7 +145,7 @@ bool ECPGstore_input(const int, const bool, const struct variable *, const char
...
@@ -144,7 +145,7 @@ bool ECPGstore_input(const int, const bool, const struct variable *, const char
bool
ECPGcheck_PQresult
(
PGresult
*
,
int
,
PGconn
*
,
enum
COMPAT_MODE
);
bool
ECPGcheck_PQresult
(
PGresult
*
,
int
,
PGconn
*
,
enum
COMPAT_MODE
);
void
ECPGraise
(
int
line
,
int
code
,
const
char
*
sqlstate
,
const
char
*
str
);
void
ECPGraise
(
int
line
,
int
code
,
const
char
*
sqlstate
,
const
char
*
str
);
void
ECPGraise_backend
(
int
line
,
PGresult
*
result
,
PGconn
*
conn
,
int
compat
);
void
ECPGraise_backend
(
int
line
,
PGresult
*
result
,
PGconn
*
conn
,
int
compat
);
char
*
ECPGprepared
(
const
char
*
,
int
);
char
*
ECPGprepared
(
const
char
*
,
struct
connection
*
,
int
);
/* SQLSTATE values generated or processed by ecpglib (intentionally
/* SQLSTATE values generated or processed by ecpglib (intentionally
* not exported -- users should refer to the codes directly) */
* not exported -- users should refer to the codes directly) */
...
...
src/interfaces/ecpg/ecpglib/prepare.c
View file @
d49b20fb
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.
19 2007/08/14 10:01:52
meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.
20 2007/09/26 10:57:00
meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
#include "postgres_fe.h"
...
@@ -11,13 +11,13 @@
...
@@ -11,13 +11,13 @@
#include "extern.h"
#include "extern.h"
#include "sqlca.h"
#include "sqlca.h"
st
atic
st
ruct
prepared_statement
struct
prepared_statement
{
{
char
*
name
;
char
*
name
;
bool
prepared
;
bool
prepared
;
struct
statement
*
stmt
;
struct
statement
*
stmt
;
struct
prepared_statement
*
next
;
struct
prepared_statement
*
next
;
}
*
prep_stmts
=
NULL
;
};
#define STMTID_SIZE 32
#define STMTID_SIZE 32
...
@@ -35,6 +35,11 @@ static int stmtCacheNBuckets = 2039; /* # buckets - a pri
...
@@ -35,6 +35,11 @@ static int stmtCacheNBuckets = 2039; /* # buckets - a pri
static
int
stmtCacheEntPerBucket
=
8
;
/* # entries/bucket */
static
int
stmtCacheEntPerBucket
=
8
;
/* # entries/bucket */
static
stmtCacheEntry
stmtCacheEntries
[
16384
]
=
{{
0
,{
0
},
0
,
0
,
0
}};
static
stmtCacheEntry
stmtCacheEntries
[
16384
]
=
{{
0
,{
0
},
0
,
0
,
0
}};
static
struct
prepared_statement
*
find_prepared_statement
(
const
char
*
name
,
struct
connection
*
con
,
struct
prepared_statement
**
prev
);
static
bool
deallocate_one
(
int
lineno
,
enum
COMPAT_MODE
c
,
struct
connection
*
con
,
struct
prepared_statement
*
prev
,
struct
prepared_statement
*
this
);
static
bool
static
bool
isvarchar
(
unsigned
char
c
)
isvarchar
(
unsigned
char
c
)
{
{
...
@@ -105,23 +110,23 @@ replace_variables(char **text, int lineno, bool questionmarks)
...
@@ -105,23 +110,23 @@ replace_variables(char **text, int lineno, bool questionmarks)
bool
bool
ECPGprepare
(
int
lineno
,
const
char
*
connection_name
,
const
int
questionmarks
,
const
char
*
name
,
const
char
*
variable
)
ECPGprepare
(
int
lineno
,
const
char
*
connection_name
,
const
int
questionmarks
,
const
char
*
name
,
const
char
*
variable
)
{
{
struct
statement
*
stmt
;
struct
connection
*
con
;
struct
prepared_statement
*
this
;
struct
statement
*
stmt
;
struct
prepared_statement
*
this
,
*
prev
;
struct
sqlca_t
*
sqlca
=
ECPGget_sqlca
();
struct
sqlca_t
*
sqlca
=
ECPGget_sqlca
();
PGresult
*
query
;
PGresult
*
query
;
ECPGinit_sqlca
(
sqlca
);
ECPGinit_sqlca
(
sqlca
);
/* check if we already have prepared this statement */
con
=
ECPGget_connection
(
connection_name
);
for
(
this
=
prep_stmts
;
this
!=
NULL
&&
strcmp
(
this
->
name
,
name
)
!=
0
;
this
=
this
->
next
);
if
(
this
)
{
bool
b
=
ECPGdeallocate
(
lineno
,
ECPG_COMPAT_PGSQL
,
name
);
if
(
!
b
)
/* check if we already have prepared this statement */
return
false
;
this
=
find_prepared_statement
(
name
,
con
,
&
prev
);
}
if
(
this
&&
!
deallocate_one
(
lineno
,
ECPG_COMPAT_PGSQL
,
con
,
prev
,
this
))
return
false
;
/* allocate new statement */
this
=
(
struct
prepared_statement
*
)
ECPGalloc
(
sizeof
(
struct
prepared_statement
),
lineno
);
this
=
(
struct
prepared_statement
*
)
ECPGalloc
(
sizeof
(
struct
prepared_statement
),
lineno
);
if
(
!
this
)
if
(
!
this
)
return
false
;
return
false
;
...
@@ -135,7 +140,7 @@ ECPGprepare(int lineno, const char *connection_name, const int questionmarks, co
...
@@ -135,7 +140,7 @@ ECPGprepare(int lineno, const char *connection_name, const int questionmarks, co
/* create statement */
/* create statement */
stmt
->
lineno
=
lineno
;
stmt
->
lineno
=
lineno
;
stmt
->
connection
=
ECPGget_connection
(
connection_name
)
;
stmt
->
connection
=
con
;
stmt
->
command
=
ECPGstrdup
(
variable
,
lineno
);
stmt
->
command
=
ECPGstrdup
(
variable
,
lineno
);
stmt
->
inlist
=
stmt
->
outlist
=
NULL
;
stmt
->
inlist
=
stmt
->
outlist
=
NULL
;
...
@@ -160,90 +165,114 @@ ECPGprepare(int lineno, const char *connection_name, const int questionmarks, co
...
@@ -160,90 +165,114 @@ ECPGprepare(int lineno, const char *connection_name, const int questionmarks, co
PQclear
(
query
);
PQclear
(
query
);
this
->
prepared
=
true
;
this
->
prepared
=
true
;
if
(
prep_stmts
==
NULL
)
if
(
con
->
prep_stmts
==
NULL
)
this
->
next
=
NULL
;
this
->
next
=
NULL
;
else
else
this
->
next
=
prep_stmts
;
this
->
next
=
con
->
prep_stmts
;
prep_stmts
=
this
;
con
->
prep_stmts
=
this
;
return
true
;
return
true
;
}
}
static
struct
prepared_statement
*
find_prepared_statement
(
const
char
*
name
,
struct
connection
*
con
,
struct
prepared_statement
**
prev_
)
{
struct
prepared_statement
*
this
,
*
prev
;
for
(
this
=
con
->
prep_stmts
,
prev
=
NULL
;
this
!=
NULL
;
prev
=
this
,
this
=
this
->
next
)
{
if
(
strcmp
(
this
->
name
,
name
)
==
0
)
{
if
(
prev_
)
*
prev_
=
prev
;
return
this
;
}
}
return
NULL
;
}
static
bool
static
bool
deallocate_one
(
int
lineno
,
const
char
*
name
)
deallocate_one
(
int
lineno
,
enum
COMPAT_MODE
c
,
struct
connection
*
con
,
struct
prepared_statement
*
prev
,
struct
prepared_statement
*
this
)
{
{
struct
prepared_statement
*
this
,
bool
r
=
false
;
*
prev
;
/* check if we really have prepared this statement */
ECPGlog
(
"ECPGdeallocate line %d: NAME: %s
\n
"
,
lineno
,
this
->
name
);
for
(
this
=
prep_stmts
,
prev
=
NULL
;
this
!=
NULL
&&
strcmp
(
this
->
name
,
name
)
!=
0
;
prev
=
this
,
this
=
this
->
next
);
if
(
this
)
/* first deallocate the statement in the backend */
if
(
this
->
prepared
)
{
{
/* first deallocate the statement in the backend */
char
*
text
;
if
(
this
->
prepared
)
PGresult
*
query
;
text
=
(
char
*
)
ECPGalloc
(
strlen
(
"deallocate
\"\"
"
)
+
strlen
(
this
->
name
),
this
->
stmt
->
lineno
);
if
(
text
)
{
{
char
*
text
;
sprintf
(
text
,
"deallocate
\"
%s
\"
"
,
this
->
name
);
PGresult
*
query
;
query
=
PQexec
(
this
->
stmt
->
connection
->
connection
,
text
);
ECPGfree
(
text
);
if
(
!
(
text
=
(
char
*
)
ECPGalloc
(
strlen
(
"deallocate
\"\"
"
)
+
strlen
(
this
->
name
),
this
->
stmt
->
lineno
)))
if
(
ECPGcheck_PQresult
(
query
,
lineno
,
this
->
stmt
->
connection
->
connection
,
this
->
stmt
->
compat
))
return
false
;
else
{
{
sprintf
(
text
,
"deallocate
\"
%s
\"
"
,
this
->
name
);
query
=
PQexec
(
this
->
stmt
->
connection
->
connection
,
text
);
ECPGfree
(
text
);
if
(
!
ECPGcheck_PQresult
(
query
,
lineno
,
this
->
stmt
->
connection
->
connection
,
this
->
stmt
->
compat
))
return
false
;
PQclear
(
query
);
PQclear
(
query
);
r
=
true
;
}
}
}
}
}
/* okay, free all the resources */
ECPGfree
(
this
->
stmt
->
command
);
ECPGfree
(
this
->
stmt
);
if
(
prev
!=
NULL
)
prev
->
next
=
this
->
next
;
else
prep_stmts
=
this
->
next
;
ECPGfree
(
this
);
/*
return
true
;
* Just ignore all errors since we do not know the list of cursors we
* are allowed to free. We have to trust the software.
*/
if
(
!
r
&&
!
INFORMIX_MODE
(
c
))
{
ECPGraise
(
lineno
,
ECPG_INVALID_STMT
,
ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
,
this
->
name
);
return
false
;
}
}
return
false
;
/* okay, free all the resources */
ECPGfree
(
this
->
stmt
->
command
);
ECPGfree
(
this
->
stmt
);
if
(
prev
!=
NULL
)
prev
->
next
=
this
->
next
;
else
con
->
prep_stmts
=
this
->
next
;
ECPGfree
(
this
);
return
true
;
}
}
/* handle the EXEC SQL DEALLOCATE PREPARE statement */
/* handle the EXEC SQL DEALLOCATE PREPARE statement */
bool
bool
ECPGdeallocate
(
int
lineno
,
int
c
,
const
char
*
name
)
ECPGdeallocate
(
int
lineno
,
int
c
,
const
char
*
connection_name
,
const
char
*
name
)
{
{
bool
ret
=
deallocate_one
(
lineno
,
name
);
struct
connection
*
con
;
enum
COMPAT_MODE
compat
=
c
;
struct
prepared_statement
*
this
,
*
prev
;
ECPGlog
(
"ECPGdeallocate line %d: NAME: %s
\n
"
,
lineno
,
name
);
con
=
ECPGget_connection
(
connection_name
);
if
(
INFORMIX_MODE
(
compat
))
{
/*
* Just ignore all errors since we do not know the list of cursors we
* are allowed to free. We have to trust the software.
*/
return
true
;
}
if
(
!
ret
)
this
=
find_prepared_statement
(
name
,
con
,
&
prev
);
ECPGraise
(
lineno
,
ECPG_INVALID_STMT
,
ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
,
name
);
if
(
this
)
return
deallocate_one
(
lineno
,
c
,
con
,
prev
,
this
);
return
ret
;
/* prepared statement is not found */
if
(
INFORMIX_MODE
(
c
))
return
true
;
ECPGraise
(
lineno
,
ECPG_INVALID_STMT
,
ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
,
name
);
return
false
;
}
}
bool
bool
ECPGdeallocate_all
(
int
lineno
,
int
compat
)
ECPGdeallocate_all
(
int
lineno
,
int
compat
,
const
char
*
connection_name
)
{
{
struct
connection
*
con
;
con
=
ECPGget_connection
(
connection_name
);
/* deallocate all prepared statements */
/* deallocate all prepared statements */
while
(
prep_stmts
!=
NULL
)
while
(
con
->
prep_stmts
)
{
{
bool
b
=
ECPGdeallocate
(
lineno
,
compat
,
prep_stmts
->
name
);
if
(
!
deallocate_one
(
lineno
,
compat
,
con
,
NULL
,
con
->
prep_stmts
))
if
(
!
b
)
return
false
;
return
false
;
}
}
...
@@ -251,22 +280,18 @@ ECPGdeallocate_all(int lineno, int compat)
...
@@ -251,22 +280,18 @@ ECPGdeallocate_all(int lineno, int compat)
}
}
char
*
char
*
ECPGprepared
(
const
char
*
name
,
int
lineno
)
ECPGprepared
(
const
char
*
name
,
struct
connection
*
con
,
int
lineno
)
{
{
struct
prepared_statement
*
this
;
struct
prepared_statement
*
this
;
this
=
find_prepared_statement
(
name
,
con
,
NULL
);
for
(
this
=
prep_stmts
;
this
!=
NULL
&&
((
strcmp
(
this
->
name
,
name
)
!=
0
)
||
this
->
prepared
==
false
);
this
=
this
->
next
);
return
this
?
this
->
stmt
->
command
:
NULL
;
return
(
this
)
?
this
->
stmt
->
command
:
NULL
;
}
}
/* return the prepared statement */
/* return the prepared statement */
char
*
char
*
ECPGprepared_statement
(
const
char
*
name
,
int
lineno
)
ECPGprepared_statement
(
const
char
*
connection_name
,
const
char
*
name
,
int
lineno
)
{
{
struct
prepared_statement
*
this
;
return
ECPGprepared
(
name
,
ECPGget_connection
(
connection_name
),
lineno
);
for
(
this
=
prep_stmts
;
this
!=
NULL
&&
strcmp
(
this
->
name
,
name
)
!=
0
;
this
=
this
->
next
);
return
(
this
)
?
this
->
stmt
->
command
:
NULL
;
}
}
/*
/*
...
@@ -426,14 +451,14 @@ ECPGauto_prepare(int lineno, const char *connection_name, const int questionmark
...
@@ -426,14 +451,14 @@ ECPGauto_prepare(int lineno, const char *connection_name, const int questionmark
entNo
=
SearchStmtCache
(
query
);
entNo
=
SearchStmtCache
(
query
);
/* if not found - add the statement to the cache */
/* if not found - add the statement to the cache */
if
(
entNo
)
if
(
entNo
)
{
{
ECPGlog
(
"ECPGauto_prepare line %d: stmt found in cache, entry %d
\n
"
,
lineno
,
entNo
);
ECPGlog
(
"ECPGauto_prepare line %d: stmt found in cache, entry %d
\n
"
,
lineno
,
entNo
);
*
name
=
ECPGstrdup
(
stmtCacheEntries
[
entNo
].
stmtID
,
lineno
);
*
name
=
ECPGstrdup
(
stmtCacheEntries
[
entNo
].
stmtID
,
lineno
);
}
}
else
else
{
{
ECPGlog
(
"ECPGauto_prepare line %d: stmt not in cache; inserting
\n
"
,
lineno
);
ECPGlog
(
"ECPGauto_prepare line %d: stmt not in cache; inserting
\n
"
,
lineno
);
/* generate a statement ID */
/* generate a statement ID */
*
name
=
(
char
*
)
ECPGalloc
(
STMTID_SIZE
,
lineno
);
*
name
=
(
char
*
)
ECPGalloc
(
STMTID_SIZE
,
lineno
);
...
@@ -450,4 +475,3 @@ ECPGauto_prepare(int lineno, const char *connection_name, const int questionmark
...
@@ -450,4 +475,3 @@ ECPGauto_prepare(int lineno, const char *connection_name, const int questionmark
return
(
true
);
return
(
true
);
}
}
src/interfaces/ecpg/include/ecpglib.h
View file @
d49b20fb
/*
/*
* this is a small part of c.h since we don't want to leak all postgres
* this is a small part of c.h since we don't want to leak all postgres
* definitions into ecpg programs
* definitions into ecpg programs
* $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpglib.h,v 1.7
1 2007/08/14 10:01:52
meskes Exp $
* $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpglib.h,v 1.7
2 2007/09/26 10:57:00
meskes Exp $
*/
*/
#ifndef _ECPGLIB_H
#ifndef _ECPGLIB_H
...
@@ -49,9 +49,9 @@ bool ECPGtrans(int, const char *, const char *);
...
@@ -49,9 +49,9 @@ bool ECPGtrans(int, const char *, const char *);
bool
ECPGdisconnect
(
int
,
const
char
*
);
bool
ECPGdisconnect
(
int
,
const
char
*
);
bool
ECPGprepare
(
int
,
const
char
*
,
const
int
,
const
char
*
,
const
char
*
);
bool
ECPGprepare
(
int
,
const
char
*
,
const
int
,
const
char
*
,
const
char
*
);
bool
ECPGauto_prepare
(
int
,
const
char
*
,
const
int
,
char
**
,
const
char
*
);
bool
ECPGauto_prepare
(
int
,
const
char
*
,
const
int
,
char
**
,
const
char
*
);
bool
ECPGdeallocate
(
int
,
int
,
const
char
*
);
bool
ECPGdeallocate
(
int
,
int
,
const
char
*
connection_name
,
const
char
*
name
);
bool
ECPGdeallocate_all
(
int
,
int
);
bool
ECPGdeallocate_all
(
int
,
int
,
const
char
*
connection_name
);
char
*
ECPGprepared_statement
(
const
char
*
,
int
);
char
*
ECPGprepared_statement
(
const
char
*
connection_name
,
const
char
*
name
,
int
);
void
ECPGlog
(
const
char
*
format
,...);
void
ECPGlog
(
const
char
*
format
,...);
char
*
ECPGerrmsg
(
void
);
char
*
ECPGerrmsg
(
void
);
...
...
src/interfaces/ecpg/preproc/output.c
View file @
d49b20fb
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/output.c,v 1.2
1 2007/08/14 10:32:47
meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/output.c,v 1.2
2 2007/09/26 10:57:00
meskes Exp $ */
#include "postgres_fe.h"
#include "postgres_fe.h"
...
@@ -153,14 +153,15 @@ output_prepare_statement(char *name, char *stmt)
...
@@ -153,14 +153,15 @@ output_prepare_statement(char *name, char *stmt)
void
void
output_deallocate_prepare_statement
(
char
*
name
)
output_deallocate_prepare_statement
(
char
*
name
)
{
{
const
char
*
con
=
connection
?
connection
:
"NULL"
;
if
(
strcmp
(
name
,
"all"
))
if
(
strcmp
(
name
,
"all"
))
{
{
fprintf
(
yyout
,
"{ ECPGdeallocate(__LINE__, %d,
"
,
compat
);
fprintf
(
yyout
,
"{ ECPGdeallocate(__LINE__, %d,
%s, "
,
compat
,
con
);
output_escaped_str
(
name
,
true
);
output_escaped_str
(
name
,
true
);
fputs
(
");"
,
yyout
);
fputs
(
");"
,
yyout
);
}
}
else
else
fprintf
(
yyout
,
"{ ECPGdeallocate_all(__LINE__, %d
);"
,
compat
);
fprintf
(
yyout
,
"{ ECPGdeallocate_all(__LINE__, %d
, %s);"
,
compat
,
con
);
whenever_action
(
2
);
whenever_action
(
2
);
free
(
name
);
free
(
name
);
...
...
src/interfaces/ecpg/preproc/preproc.y
View file @
d49b20fb
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.35
1 2007/09/04 10:02:29
meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.35
2 2007/09/26 10:57:00
meskes Exp $ */
/* Copyright comment */
/* Copyright comment */
%{
%{
...
@@ -906,10 +906,11 @@ stmt: AlterDatabaseStmt { output_statement($1, 0, ECPGst_normal); }
...
@@ -906,10 +906,11 @@ stmt: AlterDatabaseStmt { output_statement($1, 0, ECPGst_normal); }
| ECPGExecuteImmediateStmt { output_statement($1, 0, ECPGst_exec_immediate); }
| ECPGExecuteImmediateStmt { output_statement($1, 0, ECPGst_exec_immediate); }
| ECPGFree
| ECPGFree
{
{
const char *con = connection ? connection : "NULL";
if (strcmp($1, "all"))
if (strcmp($1, "all"))
fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d,
\"%s\");", compat
, $1);
fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d,
%s, \"%s\");", compat, con
, $1);
else
else
fprintf(yyout, "{ ECPGdeallocate_all(__LINE__, %d
);", compat
);
fprintf(yyout, "{ ECPGdeallocate_all(__LINE__, %d
, %s);", compat, con
);
whenever_action(2);
whenever_action(2);
free($1);
free($1);
...
@@ -3349,7 +3350,7 @@ prep_type_clause: '(' type_list ')' { $$ = cat_str(3, make_str("("), $2, make_st
...
@@ -3349,7 +3350,7 @@ prep_type_clause: '(' type_list ')' { $$ = cat_str(3, make_str("("), $2, make_st
ExecuteStmt: EXECUTE prepared_name execute_param_clause execute_rest /* execute_rest is an ecpg addon */
ExecuteStmt: EXECUTE prepared_name execute_param_clause execute_rest /* execute_rest is an ecpg addon */
{
{
/* $$ = cat_str(3, make_str("ECPGprepared_statement("),
$2, make_str(",
__LINE__)"));*/
/* $$ = cat_str(3, make_str("ECPGprepared_statement("),
connection, $2, make_str("
__LINE__)"));*/
$$ = $2;
$$ = $2;
}
}
| CREATE OptTemp TABLE create_as_target AS
| CREATE OptTemp TABLE create_as_target AS
...
@@ -5185,6 +5186,7 @@ ECPGCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR prepared_name
...
@@ -5185,6 +5186,7 @@ ECPGCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR prepared_name
{
{
struct cursor *ptr, *this;
struct cursor *ptr, *this;
struct variable *thisquery = (struct variable *)mm_alloc(sizeof(struct variable));
struct variable *thisquery = (struct variable *)mm_alloc(sizeof(struct variable));
const char *con = connection ? connection : "NULL";
for (ptr = cur; ptr != NULL; ptr = ptr->next)
for (ptr = cur; ptr != NULL; ptr = ptr->next)
{
{
...
@@ -5205,8 +5207,8 @@ ECPGCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR prepared_name
...
@@ -5205,8 +5207,8 @@ ECPGCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR prepared_name
thisquery->type = &ecpg_query;
thisquery->type = &ecpg_query;
thisquery->brace_level = 0;
thisquery->brace_level = 0;
thisquery->next = NULL;
thisquery->next = NULL;
thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement(,
__LINE__)"
) + strlen($7));
thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement(,
, __LINE__)") + strlen(con
) + strlen($7));
sprintf(thisquery->name, "ECPGprepared_statement(%s,
__LINE__)"
, $7);
sprintf(thisquery->name, "ECPGprepared_statement(%s,
%s, __LINE__)", con
, $7);
this->argsinsert = NULL;
this->argsinsert = NULL;
add_variable_to_head(&(this->argsinsert), thisquery, &no_indicator);
add_variable_to_head(&(this->argsinsert), thisquery, &no_indicator);
...
@@ -5914,21 +5916,24 @@ UsingConst: AllConst
...
@@ -5914,21 +5916,24 @@ UsingConst: AllConst
*/
*/
ECPGDescribe: SQL_DESCRIBE INPUT_P name using_descriptor
ECPGDescribe: SQL_DESCRIBE INPUT_P name using_descriptor
{
{
const char *con = connection ? connection : "NULL";
mmerror(PARSE_ERROR, ET_WARNING, "using unsupported describe statement.\n");
mmerror(PARSE_ERROR, ET_WARNING, "using unsupported describe statement.\n");
$$ = (char *) mm_alloc(sizeof("1, ECPGprepared_statement(
\"\", __LINE__)"
) + strlen($3));
$$ = (char *) mm_alloc(sizeof("1, ECPGprepared_statement(
, \"\", __LINE__)") + strlen(con
) + strlen($3));
sprintf($$, "1, ECPGprepared_statement(
\"%s\", __LINE__)"
, $3);
sprintf($$, "1, ECPGprepared_statement(
%s, \"%s\", __LINE__)", con
, $3);
}
}
| SQL_DESCRIBE opt_output name using_descriptor
| SQL_DESCRIBE opt_output name using_descriptor
{
{
const char *con = connection ? connection : "NULL";
mmerror(PARSE_ERROR, ET_WARNING, "using unsupported describe statement.\n");
mmerror(PARSE_ERROR, ET_WARNING, "using unsupported describe statement.\n");
$$ = (char *) mm_alloc(sizeof("0, ECPGprepared_statement(
\"\", __LINE__)"
) + strlen($3));
$$ = (char *) mm_alloc(sizeof("0, ECPGprepared_statement(
, \"\", __LINE__)") + strlen(con
) + strlen($3));
sprintf($$, "0, ECPGprepared_statement(
\"%s\", __LINE__)"
, $3);
sprintf($$, "0, ECPGprepared_statement(
%s, \"%s\", __LINE__)", con
, $3);
}
}
| SQL_DESCRIBE opt_output name into_descriptor
| SQL_DESCRIBE opt_output name into_descriptor
{
{
const char *con = connection ? connection : "NULL";
mmerror(PARSE_ERROR, ET_WARNING, "using unsupported describe statement.\n");
mmerror(PARSE_ERROR, ET_WARNING, "using unsupported describe statement.\n");
$$ = (char *) mm_alloc(sizeof("0, ECPGprepared_statement(
\"\", __LINE__)"
) + strlen($3));
$$ = (char *) mm_alloc(sizeof("0, ECPGprepared_statement(
, \"\", __LINE__)") + strlen(con
) + strlen($3));
sprintf($$, "0, ECPGprepared_statement(
\"%s\", __LINE__)"
, $3);
sprintf($$, "0, ECPGprepared_statement(
%s, \"%s\", __LINE__)", con
, $3);
}
}
;
;
...
...
src/interfaces/ecpg/test/ecpg_schedule
View file @
d49b20fb
...
@@ -41,3 +41,4 @@ test: sql/insupd
...
@@ -41,3 +41,4 @@ test: sql/insupd
test: sql/parser
test: sql/parser
test: thread/thread
test: thread/thread
test: thread/thread_implicit
test: thread/thread_implicit
test: thread/prep
src/interfaces/ecpg/test/ecpg_schedule_tcp
View file @
d49b20fb
...
@@ -41,5 +41,6 @@ test: sql/insupd
...
@@ -41,5 +41,6 @@ test: sql/insupd
test: sql/parser
test: sql/parser
test: thread/thread
test: thread/thread
test: thread/thread_implicit
test: thread/thread_implicit
test: thread/prep
test: connect/test1
test: connect/test1
src/interfaces/ecpg/test/expected/sql-desc.c
View file @
d49b20fb
...
@@ -197,7 +197,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
...
@@ -197,7 +197,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
#line 45 "desc.pgc"
#line 45 "desc.pgc"
{
ECPGdeallocate
(
__LINE__
,
0
,
"Foo-1"
);
{
ECPGdeallocate
(
__LINE__
,
0
,
NULL
,
"Foo-1"
);
#line 47 "desc.pgc"
#line 47 "desc.pgc"
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
...
@@ -247,7 +247,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
...
@@ -247,7 +247,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
#line 57 "desc.pgc"
#line 57 "desc.pgc"
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
0
,
ECPGst_normal
,
"declare c1 cursor for $1"
,
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
0
,
ECPGst_normal
,
"declare c1 cursor for $1"
,
ECPGt_char_variable
,(
ECPGprepared_statement
(
"foo2"
,
__LINE__
)),(
long
)
1
,(
long
)
1
,(
1
)
*
sizeof
(
char
),
ECPGt_char_variable
,(
ECPGprepared_statement
(
NULL
,
"foo2"
,
__LINE__
)),(
long
)
1
,(
long
)
1
,(
1
)
*
sizeof
(
char
),
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_descriptor
,
"indesc"
,
0L
,
0L
,
0L
,
ECPGt_descriptor
,
"indesc"
,
0L
,
0L
,
0L
,
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
...
@@ -297,7 +297,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
...
@@ -297,7 +297,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
#line 69 "desc.pgc"
#line 69 "desc.pgc"
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
0
,
ECPGst_normal
,
"declare c2 cursor for $1"
,
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
0
,
ECPGst_normal
,
"declare c2 cursor for $1"
,
ECPGt_char_variable
,(
ECPGprepared_statement
(
"foo3"
,
__LINE__
)),(
long
)
1
,(
long
)
1
,(
1
)
*
sizeof
(
char
),
ECPGt_char_variable
,(
ECPGprepared_statement
(
NULL
,
"foo3"
,
__LINE__
)),(
long
)
1
,(
long
)
1
,(
1
)
*
sizeof
(
char
),
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_descriptor
,
"indesc"
,
0L
,
0L
,
0L
,
ECPGt_descriptor
,
"indesc"
,
0L
,
0L
,
0L
,
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
...
@@ -344,7 +344,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
...
@@ -344,7 +344,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
#line 80 "desc.pgc"
#line 80 "desc.pgc"
{
ECPGdeallocate_all
(
__LINE__
,
0
);
{
ECPGdeallocate_all
(
__LINE__
,
0
,
NULL
);
#line 81 "desc.pgc"
#line 81 "desc.pgc"
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
...
...
src/interfaces/ecpg/test/expected/sql-dyntest.c
View file @
d49b20fb
...
@@ -263,7 +263,7 @@ if (sqlca.sqlcode < 0) error ( );}
...
@@ -263,7 +263,7 @@ if (sqlca.sqlcode < 0) error ( );}
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
0
,
ECPGst_normal
,
"declare MYCURS cursor for $1"
,
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
0
,
ECPGst_normal
,
"declare MYCURS cursor for $1"
,
ECPGt_char_variable
,(
ECPGprepared_statement
(
"myquery"
,
__LINE__
)),(
long
)
1
,(
long
)
1
,(
1
)
*
sizeof
(
char
),
ECPGt_char_variable
,(
ECPGprepared_statement
(
NULL
,
"myquery"
,
__LINE__
)),(
long
)
1
,(
long
)
1
,(
1
)
*
sizeof
(
char
),
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
#line 60 "dyntest.pgc"
#line 60 "dyntest.pgc"
...
...
src/interfaces/ecpg/test/expected/sql-execute.c
View file @
d49b20fb
...
@@ -142,7 +142,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
...
@@ -142,7 +142,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
0
,
ECPGst_normal
,
"declare CUR cursor for $1"
,
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
0
,
ECPGst_normal
,
"declare CUR cursor for $1"
,
ECPGt_char_variable
,(
ECPGprepared_statement
(
"f"
,
__LINE__
)),(
long
)
1
,(
long
)
1
,(
1
)
*
sizeof
(
char
),
ECPGt_char_variable
,(
ECPGprepared_statement
(
NULL
,
"f"
,
__LINE__
)),(
long
)
1
,(
long
)
1
,(
1
)
*
sizeof
(
char
),
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
#line 52 "execute.pgc"
#line 52 "execute.pgc"
...
@@ -187,7 +187,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
...
@@ -187,7 +187,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
#line 66 "execute.pgc"
#line 66 "execute.pgc"
{
ECPGdeallocate
(
__LINE__
,
0
,
"f"
);
{
ECPGdeallocate
(
__LINE__
,
0
,
NULL
,
"f"
);
#line 67 "execute.pgc"
#line 67 "execute.pgc"
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
...
@@ -207,7 +207,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
...
@@ -207,7 +207,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
0
,
ECPGst_normal
,
"declare CUR2 cursor for $1"
,
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
0
,
ECPGst_normal
,
"declare CUR2 cursor for $1"
,
ECPGt_char_variable
,(
ECPGprepared_statement
(
"f"
,
__LINE__
)),(
long
)
1
,(
long
)
1
,(
1
)
*
sizeof
(
char
),
ECPGt_char_variable
,(
ECPGprepared_statement
(
NULL
,
"f"
,
__LINE__
)),(
long
)
1
,(
long
)
1
,(
1
)
*
sizeof
(
char
),
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_const
,
"1"
,(
long
)
1
,(
long
)
1
,
strlen
(
"1"
),
ECPGt_const
,
"1"
,(
long
)
1
,(
long
)
1
,
strlen
(
"1"
),
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
...
...
src/interfaces/ecpg/test/expected/sql-oldexec.c
View file @
d49b20fb
...
@@ -142,7 +142,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
...
@@ -142,7 +142,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
1
,
ECPGst_normal
,
"declare CUR cursor for $1"
,
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
1
,
ECPGst_normal
,
"declare CUR cursor for $1"
,
ECPGt_char_variable
,(
ECPGprepared_statement
(
"f"
,
__LINE__
)),(
long
)
1
,(
long
)
1
,(
1
)
*
sizeof
(
char
),
ECPGt_char_variable
,(
ECPGprepared_statement
(
NULL
,
"f"
,
__LINE__
)),(
long
)
1
,(
long
)
1
,(
1
)
*
sizeof
(
char
),
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
#line 52 "oldexec.pgc"
#line 52 "oldexec.pgc"
...
@@ -201,7 +201,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
...
@@ -201,7 +201,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
1
,
ECPGst_normal
,
"declare CUR3 cursor for $1"
,
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
1
,
ECPGst_normal
,
"declare CUR3 cursor for $1"
,
ECPGt_char_variable
,(
ECPGprepared_statement
(
"f"
,
__LINE__
)),(
long
)
1
,(
long
)
1
,(
1
)
*
sizeof
(
char
),
ECPGt_char_variable
,(
ECPGprepared_statement
(
NULL
,
"f"
,
__LINE__
)),(
long
)
1
,(
long
)
1
,(
1
)
*
sizeof
(
char
),
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_const
,
"1"
,(
long
)
1
,(
long
)
1
,
strlen
(
"1"
),
ECPGt_const
,
"1"
,(
long
)
1
,(
long
)
1
,
strlen
(
"1"
),
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
...
...
src/interfaces/ecpg/test/expected/thread-prep.c
0 → 100644
View file @
d49b20fb
/* Processed by ecpg (regression mode) */
/* These include files are added by the preprocessor */
#include <ecpgtype.h>
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
/* End of automatic include section */
#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
#line 1 "prep.pgc"
#include <stdlib.h>
#include "ecpg_config.h"
#ifndef ENABLE_THREAD_SAFETY
int
main
(
void
)
{
printf
(
"No threading enabled.
\n
"
);
return
0
;
}
#else
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <process.h>
#else
#include <pthread.h>
#endif
#include <stdio.h>
#define THREADS 16
#define REPEATS 50
#line 1 "sqlca.h"
#ifndef POSTGRES_SQLCA_H
#define POSTGRES_SQLCA_H
#ifndef PGDLLIMPORT
#if defined(WIN32) || defined(__CYGWIN__)
#define PGDLLIMPORT __declspec (dllimport)
#else
#define PGDLLIMPORT
#endif
/* __CYGWIN__ */
#endif
/* PGDLLIMPORT */
#define SQLERRMC_LEN 150
#ifdef __cplusplus
extern
"C"
{
#endif
struct
sqlca_t
{
char
sqlcaid
[
8
];
long
sqlabc
;
long
sqlcode
;
struct
{
int
sqlerrml
;
char
sqlerrmc
[
SQLERRMC_LEN
];
}
sqlerrm
;
char
sqlerrp
[
8
];
long
sqlerrd
[
6
];
/* Element 0: empty */
/* 1: OID of processed tuple if applicable */
/* 2: number of rows processed */
/* after an INSERT, UPDATE or */
/* DELETE statement */
/* 3: empty */
/* 4: empty */
/* 5: empty */
char
sqlwarn
[
8
];
/* Element 0: set to 'W' if at least one other is 'W' */
/* 1: if 'W' at least one character string */
/* value was truncated when it was */
/* stored into a host variable. */
/*
* 2: if 'W' a (hopefully) non-fatal notice occurred
*/
/* 3: empty */
/* 4: empty */
/* 5: empty */
/* 6: empty */
/* 7: empty */
char
sqlstate
[
5
];
};
struct
sqlca_t
*
ECPGget_sqlca
(
void
);
#ifndef POSTGRES_ECPG_INTERNAL
#define sqlca (*ECPGget_sqlca())
#endif
#ifdef __cplusplus
}
#endif
#endif
#line 24 "prep.pgc"
#line 1 "regression.h"
#line 25 "prep.pgc"
/* exec sql whenever sqlerror sqlprint ; */
#line 27 "prep.pgc"
/* exec sql whenever not found sqlprint ; */
#line 28 "prep.pgc"
#ifdef WIN32
static
unsigned
STDCALL
fn
(
void
*
arg
)
#else
void
*
fn
(
void
*
arg
)
#endif
{
int
i
;
/* exec sql begin declare section */
#line 39 "prep.pgc"
int
value
;
#line 40 "prep.pgc"
char
name
[
100
]
;
#line 41 "prep.pgc"
char
query
[
256
]
=
"INSERT INTO T VALUES ( ? )"
;
/* exec sql end declare section */
#line 42 "prep.pgc"
value
=
(
int
)
arg
;
sprintf
(
name
,
"Connection: %d"
,
value
);
{
ECPGconnect
(
__LINE__
,
0
,
"regress1"
,
NULL
,
NULL
,
name
,
0
);
#line 47 "prep.pgc"
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
#line 47 "prep.pgc"
{
ECPGsetcommit
(
__LINE__
,
"on"
,
NULL
);
#line 48 "prep.pgc"
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
#line 48 "prep.pgc"
for
(
i
=
1
;
i
<=
REPEATS
;
++
i
)
{
{
ECPGprepare
(
__LINE__
,
NULL
,
0
,
"i"
,
query
);
#line 51 "prep.pgc"
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
#line 51 "prep.pgc"
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
0
,
1
,
"i"
,
ECPGt_int
,
&
(
value
),(
long
)
1
,(
long
)
1
,
sizeof
(
int
),
ECPGt_NO_INDICATOR
,
NULL
,
0L
,
0L
,
0L
,
ECPGt_EOIT
,
ECPGt_EORT
);
#line 52 "prep.pgc"
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
#line 52 "prep.pgc"
}
{
ECPGdeallocate
(
__LINE__
,
0
,
NULL
,
"i"
);
#line 54 "prep.pgc"
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
#line 54 "prep.pgc"
{
ECPGdisconnect
(
__LINE__
,
name
);
#line 55 "prep.pgc"
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
#line 55 "prep.pgc"
return
0
;
}
int
main
(
int
argc
,
char
**
argv
)
{
int
i
;
#ifdef WIN32
HANDLE
threads
[
THREADS
];
#else
pthread_t
threads
[
THREADS
];
#endif
{
ECPGconnect
(
__LINE__
,
0
,
"regress1"
,
NULL
,
NULL
,
NULL
,
0
);
#line 69 "prep.pgc"
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
#line 69 "prep.pgc"
{
ECPGsetcommit
(
__LINE__
,
"on"
,
NULL
);
#line 70 "prep.pgc"
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
#line 70 "prep.pgc"
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
0
,
ECPGst_normal
,
"drop table if exists T "
,
ECPGt_EOIT
,
ECPGt_EORT
);
#line 71 "prep.pgc"
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
#line 71 "prep.pgc"
{
ECPGdo
(
__LINE__
,
0
,
1
,
NULL
,
0
,
ECPGst_normal
,
"create table T ( i int ) "
,
ECPGt_EOIT
,
ECPGt_EORT
);
#line 72 "prep.pgc"
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
#line 72 "prep.pgc"
{
ECPGdisconnect
(
__LINE__
,
"CURRENT"
);
#line 73 "prep.pgc"
if
(
sqlca
.
sqlcode
<
0
)
sqlprint
();}
#line 73 "prep.pgc"
#ifdef WIN32
for
(
i
=
0
;
i
<
THREADS
;
++
i
)
{
unsigned
id
;
threads
[
i
]
=
(
HANDLE
)
_beginthreadex
(
NULL
,
0
,
fn
,
(
void
*
)
i
,
0
,
&
id
);
}
WaitForMultipleObjects
(
THREADS
,
threads
,
TRUE
,
INFINITE
);
for
(
i
=
0
;
i
<
THREADS
;
++
i
)
CloseHandle
(
threads
[
i
]);
#else
for
(
i
=
0
;
i
<
THREADS
;
++
i
)
pthread_create
(
&
threads
[
i
],
NULL
,
fn
,
(
void
*
)
i
);
for
(
i
=
0
;
i
<
THREADS
;
++
i
)
pthread_join
(
threads
[
i
],
NULL
);
#endif
return
0
;
}
#endif
src/interfaces/ecpg/test/expected/thread-prep.stderr
0 → 100644
View file @
d49b20fb
src/interfaces/ecpg/test/expected/thread-prep.stdout
0 → 100644
View file @
d49b20fb
No threading enabled.
src/interfaces/ecpg/test/expected/thread-prep_2.stdout
0 → 100644
View file @
d49b20fb
src/interfaces/ecpg/test/thread/Makefile
View file @
d49b20fb
...
@@ -5,7 +5,8 @@ include $(top_srcdir)/$(subdir)/../Makefile.regress
...
@@ -5,7 +5,8 @@ include $(top_srcdir)/$(subdir)/../Makefile.regress
TESTS
=
thread_implicit thread_implicit.c
\
TESTS
=
thread_implicit thread_implicit.c
\
thread thread.c
thread thread.c
\
prep prep.c
all
:
$(TESTS)
all
:
$(TESTS)
src/interfaces/ecpg/test/thread/prep.pgc
0 → 100644
View file @
d49b20fb
#include <stdlib.h>
#include "ecpg_config.h"
#ifndef ENABLE_THREAD_SAFETY
int
main(void)
{
printf("No threading enabled.\n");
return 0;
}
#else
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <process.h>
#else
#include <pthread.h>
#endif
#include <stdio.h>
#define THREADS 16
#define REPEATS 50
exec sql include sqlca;
exec sql include ../regression;
exec sql whenever sqlerror sqlprint;
exec sql whenever not found sqlprint;
#ifdef WIN32
static unsigned STDCALL fn(void* arg)
#else
void* fn(void* arg)
#endif
{
int i;
EXEC SQL BEGIN DECLARE SECTION;
int value;
char name[100];
char query[256] = "INSERT INTO T VALUES ( ? )";
EXEC SQL END DECLARE SECTION;
value = (int)arg;
sprintf(name, "Connection: %d", value);
EXEC SQL CONNECT TO REGRESSDB1 AS :name;
EXEC SQL SET AUTOCOMMIT TO ON;
for (i = 1; i <= REPEATS; ++i)
{
EXEC SQL PREPARE I FROM :query;
EXEC SQL EXECUTE I USING :value;
}
EXEC SQL DEALLOCATE I;
EXEC SQL DISCONNECT :name;
return 0;
}
int main (int argc, char** argv)
{
int i;
#ifdef WIN32
HANDLE threads[THREADS];
#else
pthread_t threads[THREADS];
#endif
EXEC SQL CONNECT TO REGRESSDB1;
EXEC SQL SET AUTOCOMMIT TO ON;
EXEC SQL DROP TABLE IF EXISTS T;
EXEC SQL CREATE TABLE T ( i int );
EXEC SQL DISCONNECT;
#ifdef WIN32
for (i = 0; i < THREADS; ++i)
{
unsigned id;
threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id);
}
WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
for (i = 0; i < THREADS; ++i)
CloseHandle(threads[i]);
#else
for (i = 0; i < THREADS; ++i)
pthread_create(&threads[i], NULL, fn, (void*)i);
for (i = 0; i < THREADS; ++i)
pthread_join(threads[i], NULL);
#endif
return 0;
}
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment