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

Commit1f0a6cd

Browse files
author
Michael Meskes
committed
Hopefully that's it. The remaining files for ecpg regression tests.
1 parent6392518 commit1f0a6cd

File tree

126 files changed

+30557
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+30557
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
subdir = src/interfaces/ecpg/test/compat_informix
2+
top_builddir = ../../../../..
3+
include$(top_builddir)/src/Makefile.global
4+
include ../Makefile.regress
5+
6+
# special informix compatiblity switches
7+
ECPG += -C INFORMIX
8+
ECPG_NOIND =$(ECPG) -r no_indicator
9+
overrideLDFLAGS += -L../../compatlib
10+
overrideLIBS +=$(LIBS) -lecpg_compat
11+
12+
TESTS = test_informix test_informix.c\
13+
test_informix2 test_informix2.c
14+
15+
all:$(TESTS)
16+
17+
test_informix.c: test_informix.pgc ../regression.h
18+
$(ECPG) -o$@ -I$(srcdir)$<
19+
20+
test_informix2.c: test_informix2.pgc ../regression.h
21+
$(ECPG_NOIND) -o$@ -I$(srcdir)$<
22+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#include "sqltypes.h"
2+
3+
$include ../regression;
4+
$define NUMBER 12;
5+
6+
static void openit(void);
7+
static void dosqlprint(void) {
8+
printf("doSQLprint: Error: %s\n", sqlca.sqlerrm.sqlerrmc);
9+
}
10+
11+
int main(void)
12+
{
13+
$int i = 14;
14+
$decimal j, m, n;
15+
16+
ECPGdebug(1, stderr);
17+
$whenever sqlerror do dosqlprint();
18+
19+
$connect to REGRESSDB1;
20+
if (sqlca.sqlcode != 0) exit(1);
21+
22+
$create table test(i int primary key, j int);
23+
24+
/* this INSERT works */
25+
rsetnull(CDECIMALTYPE, (char *)&j);
26+
$insert into test (i, j) values (7, :j);
27+
$commit;
28+
29+
/* this INSERT should fail because i is a unique column */
30+
$insert into test (i, j) values (7, NUMBER);
31+
printf("INSERT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
32+
if (sqlca.sqlcode != 0) $rollback;
33+
34+
$insert into test (i, j) values (:i, 1);
35+
$commit;
36+
37+
/* this will fail (more than one row in subquery) */
38+
$select i from test where j=(select j from test);
39+
40+
/* this however should be ok */
41+
$select i from test where j=(select j from test limit 1);
42+
printf("SELECT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
43+
if (sqlca.sqlcode != 0) $rollback;
44+
45+
$declare c cursor for select * from test where i <= :i;
46+
openit();
47+
48+
deccvint(0, &j);
49+
50+
while (1)
51+
{
52+
$fetch forward c into :i, :j;
53+
if (sqlca.sqlcode == 100) break;
54+
else if (sqlca.sqlcode != 0) printf ("Error: %ld\n", sqlca.sqlcode);
55+
56+
if (risnull(CDECIMALTYPE, (char *)&j))
57+
printf("%d NULL\n", i);
58+
else
59+
{
60+
int a;
61+
62+
dectoint(&j, &a);
63+
printf("%d %d\n", i, a);
64+
}
65+
}
66+
67+
deccvint(7, &j);
68+
deccvint(14, &m);
69+
decadd(&j, &m, &n);
70+
$delete from test where i=:n;
71+
printf("DELETE: %ld\n", sqlca.sqlcode);
72+
73+
$select 1 from test where i=14;
74+
printf("Exists: %ld\n", sqlca.sqlcode);
75+
76+
$select 1 from test where i=147;
77+
printf("Does not exist: %ld\n", sqlca.sqlcode);
78+
79+
$commit;
80+
$drop table test;
81+
$commit;
82+
83+
$close database;
84+
85+
return 0;
86+
}
87+
88+
static void openit(void)
89+
{
90+
$open c;
91+
}
92+
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "sqltypes.h"
4+
5+
EXEC SQL include sqlca.h;
6+
EXEC SQL include ../regression;
7+
EXEC SQL DEFINE MAXDBLEN 30;
8+
9+
/* Check SQLCODE, and produce a "standard error" if it's wrong! */
10+
static void sql_check(char *fn, char *caller, int ignore)
11+
{
12+
char errorstring[255];
13+
14+
if (SQLCODE == ignore)
15+
return;
16+
else
17+
{
18+
if (SQLCODE != 0)
19+
{
20+
21+
sprintf(errorstring, "**SQL error %ld doing '%s' in function '%s'. [%s]",
22+
SQLCODE, caller, fn, sqlca.sqlerrm.sqlerrmc);
23+
fprintf(stderr, "%s", errorstring);
24+
printf("%s\n", errorstring);
25+
26+
/* attempt a ROLLBACK */
27+
EXEC SQL rollback;
28+
29+
if (SQLCODE == 0)
30+
{
31+
sprintf(errorstring, "Rollback successful.\n");
32+
} else {
33+
sprintf(errorstring, "Rollback failed with code %ld.\n", SQLCODE);
34+
}
35+
36+
fprintf(stderr, "%s", errorstring);
37+
printf("%s\n", errorstring);
38+
39+
exit(1);
40+
}
41+
}
42+
}
43+
44+
45+
46+
int main(void)
47+
{
48+
EXEC SQL BEGIN DECLARE SECTION;
49+
int c;
50+
timestamp d;
51+
timestamp maxd;
52+
char dbname[30];
53+
EXEC SQL END DECLARE SECTION;
54+
55+
EXEC SQL whenever sqlerror sqlprint;
56+
57+
ECPGdebug(1, stderr);
58+
59+
/*if (strlen(REGRESSDB1) > MAXDBLEN) {
60+
exit(1);
61+
}
62+
*/
63+
strcpy(dbname, "regress1");
64+
EXEC SQL connect to :dbname;
65+
sql_check("main", "connect", 0);
66+
67+
EXEC SQL create table history (customerid integer, timestamp timestamp without time zone, action_taken char(5), narrative varchar(100));
68+
sql_check("main", "create", 0);
69+
70+
EXEC SQL insert into history
71+
(customerid, timestamp, action_taken, narrative)
72+
values(1, '2003-05-07 13:28:34 CEST', 'test', 'test');
73+
sql_check("main", "insert", 0);
74+
75+
EXEC SQL select max(timestamp)
76+
into :maxd
77+
from history;
78+
sql_check("main", "select max", 100);
79+
80+
if (risnull(CDTIMETYPE, (char *) &maxd))
81+
{
82+
printf("Nothing on the history table\n\n");
83+
exit(0);
84+
}
85+
86+
EXEC SQL select customerid, timestamp
87+
into :c, :d
88+
from history
89+
where timestamp = :maxd
90+
limit 1;
91+
sql_check("main", "select", 0);
92+
93+
printf("Read in customer %d\n", c);
94+
95+
/* Adding 1 to d adds 1 second. So:
96+
60 1 minute
97+
3600 1 hour
98+
86400 1 day */
99+
d=d+86400;
100+
c++;
101+
102+
EXEC SQL insert into history
103+
(customerid, timestamp, action_taken, narrative)
104+
values(:c, :d, 'test', 'test');
105+
sql_check("main", "update", 0);
106+
107+
EXEC SQL commit;
108+
109+
EXEC SQL drop table history;
110+
sql_check("main", "drop", 0);
111+
112+
EXEC SQL commit;
113+
114+
EXEC SQL disconnect;
115+
sql_check("main", "disconnect", 0);
116+
117+
printf("All OK!\n");
118+
119+
exit(0);
120+
121+
/*
122+
Table "public.history"
123+
Column | Type | Modifiers
124+
--------------+-----------------------------+-----------
125+
customerid | integer | not null
126+
timestamp | timestamp without time zone | not null
127+
action_taken | character(5) | not null
128+
narrative | character varying(100) |
129+
*/
130+
131+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
subdir = src/interfaces/ecpg/test/complex
2+
top_builddir = ../../../../..
3+
include$(top_builddir)/src/Makefile.global
4+
include ../Makefile.regress
5+
6+
7+
TESTS = test1 test1.c\
8+
test2 test2.c\
9+
test3 test3.c\
10+
test4 test4.c\
11+
test5 test5.c
12+
13+
all:$(TESTS)
14+
15+
# test4 needs the -c option for the "EXEC SQL TYPE" construct
16+
test4.c: test4.pgc ../regression.h
17+
$(ECPG) -c -o$@ -I$(srcdir)$<
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/test/complex/header_test.h,v 1.1 2006/08/02 14:14:02 meskes Exp $ */
2+
3+
#include"stdlib.h"
4+
5+
staticvoid
6+
Finish(char*msg)
7+
{
8+
fprintf(stderr,"Error in statement '%s':\n",msg);
9+
sqlprint();
10+
11+
/* finish transaction */
12+
execsqlrollback;
13+
14+
/* and remove test table */
15+
execsqldroptablemeskes;
16+
execsqlcommit;
17+
18+
execsqldisconnect;
19+
20+
exit(-1);
21+
}
22+
23+
staticvoid
24+
warn(void)
25+
{
26+
fprintf(stderr,"Warning: At least one column was truncated\n");
27+
}
28+
29+
execsqlwheneversqlerror
30+
do
31+
Finish(msg);
32+
execsqlwheneversqlwarning
33+
do
34+
warn();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp