summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/sql/quote.pgc
blob: 9b62b7da90d995f0c9bc35b5048f897dc44c2cd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

EXEC SQL INCLUDE ../regression;

int main() {
  EXEC SQL BEGIN DECLARE SECTION;
    char var[25];
    int i, loopcount;
  EXEC SQL END DECLARE SECTION;

  ECPGdebug(1, stderr);
  EXEC SQL CONNECT TO REGRESSDB1;

  EXEC SQL SET AUTOCOMMIT TO ON;
  EXEC SQL WHENEVER SQLWARNING SQLPRINT;
  EXEC SQL WHENEVER SQLERROR STOP;

  EXEC SQL CREATE TABLE "My_Table" ( Item1 int, Item2 text );

  EXEC SQL SET standard_conforming_strings TO off;

  EXEC SQL SHOW standard_conforming_strings INTO :var;
  printf("Standard conforming strings: %s\n", var);

  /* this is a\\b actually */
  EXEC SQL INSERT INTO "My_Table" VALUES ( 1, 'a\\\\b' );
  /* this is a\\b */
  EXEC SQL INSERT INTO "My_Table" VALUES ( 1, E'a\\\\b' );

  EXEC SQL SET standard_conforming_strings TO on;

  EXEC SQL SHOW standard_conforming_strings INTO :var;
  printf("Standard conforming strings: %s\n", var);

  /* this is a\\\\b actually */
  EXEC SQL INSERT INTO "My_Table" VALUES ( 2, 'a\\\\b' );
  /* this is a\\b */
  EXEC SQL INSERT INTO "My_Table" VALUES ( 2, E'a\\\\b' );

  EXEC SQL BEGIN;
  EXEC SQL DECLARE C CURSOR FOR SELECT * FROM "My_Table";

  EXEC SQL OPEN C;

  EXEC SQL WHENEVER NOT FOUND DO BREAK;

  for (loopcount = 0; loopcount < 100; loopcount++)
  {
	EXEC SQL FETCH C INTO :i, :var;
	printf("value: %d %s\n", i, var);
  }

  EXEC SQL ROLLBACK;
  EXEC SQL DROP TABLE "My_Table";

  EXEC SQL DISCONNECT ALL;

  return 0;
}