Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
00c11039
Commit
00c11039
authored
22 years ago
by
Bruce Momjian
Browse files
Options
Downloads
Patches
Plain Diff
Update ecpg thread testing program to be more automated.
parent
9c6d5495
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/interfaces/ecpg/test/test_thread.pgc
+79
-53
79 additions, 53 deletions
src/interfaces/ecpg/test/test_thread.pgc
with
79 additions
and
53 deletions
src/interfaces/ecpg/test/test_thread.pgc
+
79
−
53
View file @
00c11039
/*
---
/*
* Thread test program
* by Philip Yarra
*
* To run, create this table in the 'test' database:
*
* CREATE TABLE foo (
* message character(40)
* );
* ---
*/
#include <pthread.h>
int main(void);
void ins1(void);
void ins2(void);
int main(void)
EXEC SQL BEGIN DECLARE SECTION;
char *dbname;
EXEC SQL END DECLARE SECTION;
int
main(int argc, char **argv)
{
pthread_t thread1, thread2;
pthread_t thread1,
thread2;
EXEC SQL BEGIN DECLARE SECTION;
int rows;
EXEC SQL END DECLARE SECTION;
if (argc != 2)
{
fprintf(stderr, "Usage: %s dbname\n", argv[0]);
return 1;
}
dbname = argv[1];
EXEC SQL CONNECT TO:dbname AS test0;
/* DROP might fail */
EXEC SQL AT test0 DROP TABLE test_thread;
EXEC SQL AT test0 COMMIT WORK;
EXEC SQL AT test0 CREATE TABLE test_thread(message character(40));
EXEC SQL AT test0 COMMIT WORK;
EXEC SQL DISCONNECT test0;
pthread_create(&thread1, NULL, (void *) ins1, NULL);
pthread_create(&thread2, NULL, (void *) ins2, NULL);
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
printf("Program done!\n");
EXEC SQL CONNECT TO:dbname AS test3;
EXEC SQL AT test3 SELECT COUNT(*) INTO :rows FROM test_thread;
EXEC SQL AT test3 COMMIT WORK;
EXEC SQL DISCONNECT test3;
if (rows == 10)
printf("Success.\n");
else
printf("Failure.\n");
return 0;
}
void ins1(void)
void
ins1(void)
{
int i;
EXEC SQL BEGIN DECLARE SECTION;
char* cs = "test";
char* bar = "one!";
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER sqlerror sqlprint;
EXEC SQL CONNECT TO :cs AS test1;
EXEC SQL CONNECT TO:dbname AS test1;
for (i = 0; i < 5; i++)
{
printf("thread 1 : inserting\n");
EXEC SQL AT test1 INSERT INTO foo VALUES(:bar);
EXEC SQL AT test1 INSERT INTO test_thread VALUES('thread1');
printf("thread 1 : insert done\n");
}
EXEC SQL AT test1 COMMIT WORK;
EXEC SQL DISCONNECT test1;
printf("thread 1 : done!\n");
}
void ins2(void)
void
ins2(void)
{
int i;
EXEC SQL BEGIN DECLARE SECTION;
char* cs = "test";
char* bar = "two!";
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER sqlerror sqlprint;
EXEC SQL CONNECT TO :cs AS test2;
EXEC SQL CONNECT TO:dbname AS test2;
for (i = 0; i < 5; i++)
{
printf("thread 2: inserting\n");
EXEC SQL AT test2 INSERT INTO foo VALUES(:bar);
EXEC SQL AT test2 INSERT INTO test_thread VALUES('thread2');
printf("thread 2: insert done\n");
}
EXEC SQL AT test2 COMMIT WORK;
EXEC SQL DISCONNECT test2;
printf("thread 2: done!\n");
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment