Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Postgres/src/interfaces/ecpg/test/preproc/   (Postgres Database Version 18.4©)  Datei vom 11.4.2026 mit Größe 1 kB image not shown  

Quelle  autoprep.pgc   Sprache: unbekannt

 
Spracherkennung für: .pgc vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* test automatic prepare for all statements */
EXEC SQL INCLUDE ../regression;

static void test(void) {
  EXEC SQL BEGIN DECLARE SECTION;
 int item[4], ind[4], i = 1;
 int item1, ind1;
 char sqlstr[64] = "SELECT item2 FROM T ORDER BY item2 NULLS LAST";
  EXEC SQL END DECLARE SECTION;

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

  EXEC SQL WHENEVER SQLWARNING SQLPRINT;
  EXEC SQL WHENEVER SQLERROR SQLPRINT;

  EXEC SQL CREATE TABLE T ( Item1 int, Item2 int );

  EXEC SQL INSERT INTO T VALUES ( 1, null );
  EXEC SQL INSERT INTO T VALUES ( 1, :i );
  i++;
  EXEC SQL INSERT INTO T VALUES ( 1, :i );
  EXEC SQL PREPARE I AS INSERT INTO T VALUES ( 12 );
  EXEC SQL EXECUTE I;

  EXEC SQL SELECT Item2 INTO :item:ind FROM T ORDER BY Item2 NULLS LAST;

  for (i=0; i<4; i++)
 printf("item[%d] = %d\n", i, ind[i] ? -1 : item[i]);

  EXEC SQL DECLARE C CURSOR FOR SELECT Item1 FROM T;

  EXEC SQL OPEN C;

  EXEC SQL FETCH 1 IN C INTO :i;
  printf("i = %d\n", i);

  EXEC SQL CLOSE C;

  EXEC SQL PREPARE stmt1 FROM :sqlstr;

  EXEC SQL DECLARE cur1 CURSOR FOR stmt1;

  EXEC SQL OPEN cur1;

  EXEC SQL WHENEVER NOT FOUND DO BREAK;

  i = 0;
  while (i < 100)
  {
 EXEC SQL FETCH cur1 INTO :item1:ind1;
 printf("item[%d] = %d\n", i, ind1 ? -1 : item1);
 i++;
  }

  EXEC SQL CLOSE cur1;

  EXEC SQL DROP TABLE T;

  EXEC SQL DISCONNECT ALL;
}

int main() {
  test();
  test();     /* retry */

  return 0;
}

[Dauer der Verarbeitung: 0.16 Sekunden, vorverarbeitet 2026-08-08]