~ubuntu-branches/debian/sid/postgresql-9.3/sid

« back to all changes in this revision

Viewing changes to src/interfaces/ecpg/test/compat_informix/test_informix.pgc

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-05-08 05:39:52 UTC
  • Revision ID: package-import@ubuntu.com-20130508053952-1j7uilp7mjtrvq8q
Tags: upstream-9.3~beta1
ImportĀ upstreamĀ versionĀ 9.3~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "sqltypes.h"
 
2
#include <stdlib.h>
 
3
 
 
4
$include ../regression;
 
5
$define NUMBER 12;
 
6
 
 
7
static void openit(void);
 
8
static void dosqlprint(void) {
 
9
        printf("doSQLprint: Error: %s\n", sqlca.sqlerrm.sqlerrmc);
 
10
}
 
11
 
 
12
int main(void)
 
13
{
 
14
        $int i = 14;
 
15
        $decimal j, m, n;
 
16
        $string c[10];
 
17
 
 
18
        ECPGdebug(1, stderr);
 
19
        $whenever sqlerror do dosqlprint();
 
20
 
 
21
        $connect to REGRESSDB1;
 
22
        if (sqlca.sqlcode != 0) exit(1);
 
23
 
 
24
        $create table test(i int primary key, j int, c text);
 
25
 
 
26
        /* this INSERT works */
 
27
        rsetnull(CDECIMALTYPE, (char *)&j);
 
28
        $insert into test (i, j, c) values (7, :j, 'test   ');
 
29
        $commit;
 
30
 
 
31
        /* this INSERT should fail because i is a unique column */
 
32
        $insert into test (i, j, c) values (7, NUMBER, 'a');
 
33
        printf("INSERT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
 
34
        if (sqlca.sqlcode != 0) $rollback;
 
35
 
 
36
        $insert into test (i, j, c) values (:i, 1, 'a      ');
 
37
        $commit;
 
38
 
 
39
        /* this will fail (more than one row in subquery) */
 
40
        $select i from test where j=(select j from test);
 
41
        $rollback;
 
42
 
 
43
        /* this however should be ok */
 
44
        $select i from test where j=(select j from test order by i limit 1);
 
45
        printf("SELECT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
 
46
        if (sqlca.sqlcode != 0) $rollback;
 
47
 
 
48
        sqlca.sqlcode = 100;
 
49
        $declare c cursor for select * from test where i <= :i;
 
50
        printf ("%ld\n", sqlca.sqlcode);
 
51
        openit();
 
52
 
 
53
        deccvint(0, &j);
 
54
 
 
55
        while (1)
 
56
        {
 
57
                $fetch forward c into :i, :j, :c;
 
58
                if (sqlca.sqlcode == 100) break;
 
59
                else if (sqlca.sqlcode != 0) printf ("Error: %ld\n", sqlca.sqlcode);
 
60
 
 
61
                if (risnull(CDECIMALTYPE, (char *)&j))
 
62
                        printf("%d NULL\n", i);
 
63
                else
 
64
                {
 
65
                        int a;
 
66
 
 
67
                        dectoint(&j, &a);
 
68
                        printf("%d %d \"%s\"\n", i, a, c);
 
69
                }
 
70
        }
 
71
 
 
72
        deccvint(7, &j);
 
73
        deccvint(14, &m);
 
74
        decadd(&j, &m, &n);
 
75
        $delete from test where i= :n::decimal;
 
76
        printf("DELETE: %ld\n", sqlca.sqlcode);
 
77
 
 
78
        $select 1 from test where i=14;
 
79
        printf("Exists: %ld\n", sqlca.sqlcode);
 
80
 
 
81
        $select 1 from test where i=147;
 
82
        printf("Does not exist: %ld\n", sqlca.sqlcode);
 
83
 
 
84
        $commit;
 
85
        $drop table test;
 
86
        $commit;
 
87
 
 
88
        $close database;
 
89
 
 
90
        return 0;
 
91
}
 
92
 
 
93
static void openit(void)
 
94
{
 
95
        $open c;
 
96
}