~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to src/interfaces/ecpg/test/preproc/type.pgc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
 
 
4
EXEC SQL include ../regression;
 
5
 
 
6
EXEC SQL typedef long mmInteger;
 
7
EXEC SQL typedef char mmChar;
 
8
EXEC SQL typedef short mmSmallInt;
 
9
 
 
10
exec sql type string is char[11];
 
11
typedef char string[11];
 
12
 
 
13
exec sql type c is char reference;
 
14
typedef char* c;
 
15
 
 
16
EXEC SQL BEGIN DECLARE SECTION;
 
17
struct TBempl
 
18
{
 
19
  mmInteger idnum;
 
20
  mmChar name[21];
 
21
  mmSmallInt accs;
 
22
};
 
23
EXEC SQL END DECLARE SECTION;
 
24
 
 
25
int
 
26
main (void)
 
27
{
 
28
  EXEC SQL BEGIN DECLARE SECTION;
 
29
  struct TBempl empl;
 
30
  string str;
 
31
  c ptr = NULL;
 
32
  struct varchar_vc
 
33
  {
 
34
        int len;
 
35
        char text[10];
 
36
  } vc;
 
37
  EXEC SQL END DECLARE SECTION;
 
38
 
 
39
  EXEC SQL var vc is varchar[10];
 
40
  ECPGdebug (1, stderr);
 
41
 
 
42
  empl.idnum = 1;
 
43
  EXEC SQL connect to REGRESSDB1;
 
44
  if (sqlca.sqlcode)
 
45
    {
 
46
      printf ("connect error = %ld\n", sqlca.sqlcode);
 
47
      exit (sqlca.sqlcode);
 
48
    }
 
49
 
 
50
  EXEC SQL create table empl
 
51
    (idnum integer, name char(20), accs smallint, string1 char(10), string2 char(10), string3 char(10));
 
52
  if (sqlca.sqlcode)
 
53
    {
 
54
      printf ("create error = %ld\n", sqlca.sqlcode);
 
55
      exit (sqlca.sqlcode);
 
56
    }
 
57
 
 
58
  EXEC SQL insert into empl values (1, 'user name', 320, 'first str', 'second str', 'third str');
 
59
  if (sqlca.sqlcode)
 
60
    {
 
61
      printf ("insert error = %ld\n", sqlca.sqlcode);
 
62
      exit (sqlca.sqlcode);
 
63
    }
 
64
 
 
65
  EXEC SQL select idnum, name, accs, string1, string2, string3
 
66
        into :empl, :str, :ptr, :vc
 
67
        from empl
 
68
        where idnum =:empl.idnum;
 
69
  if (sqlca.sqlcode)
 
70
    {
 
71
      printf ("select error = %ld\n", sqlca.sqlcode);
 
72
      exit (sqlca.sqlcode);
 
73
    }
 
74
  printf ("id=%ld name='%s' accs=%d str='%s' ptr='%s' vc='%10.10s'\n", empl.idnum, empl.name, empl.accs, str, ptr, vc.text);
 
75
 
 
76
  EXEC SQL disconnect;
 
77
 
 
78
  free(ptr);
 
79
  exit (0);
 
80
}