1EXEC SQL INCLUDE ../regression; 2EXEC SQL WHENEVER SQLERROR SQLPRINT; 3 4int 5main(void) 6{ 7 EXEC SQL BEGIN DECLARE SECTION; 8 char *stmt1 = "INSERT INTO test1 VALUES ($1, $2)"; 9 char *stmt2 = "SELECT * from test1 where a = $1 and b = $2"; 10 char *stmt3 = "SELECT * from test1 where :var = a"; 11 12 int val1 = 1; 13 char val2[4] = "one", val2output[] = "AAA"; 14 int val1output = 2, val2i = 0; 15 int val2null = -1; 16 int ind1, ind2; 17 char desc1[8] = "outdesc"; 18 EXEC SQL END DECLARE SECTION; 19 20 ECPGdebug(1, stderr); 21 22 EXEC SQL ALLOCATE DESCRIPTOR indesc; 23 EXEC SQL ALLOCATE DESCRIPTOR :desc1; 24 25 EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = :val1; 26 EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2i, DATA = :val2; 27 28 EXEC SQL CONNECT TO REGRESSDB1; 29 30 EXEC SQL CREATE TABLE test1 (a int, b text); 31 EXEC SQL PREPARE foo1 FROM :stmt1; 32 EXEC SQL PREPARE "Foo-1" FROM :stmt1; 33 EXEC SQL PREPARE foo2 FROM :stmt2; 34 EXEC SQL PREPARE foo3 FROM :stmt3; 35 36 EXEC SQL EXECUTE foo1 USING SQL DESCRIPTOR indesc; 37 38 EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 2; 39 EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2null, DATA = :val2; 40 41 EXEC SQL EXECUTE foo1 USING SQL DESCRIPTOR indesc; 42 43 EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 3; 44 EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val1, DATA = 'this is a long test'; 45 46 EXEC SQL EXECUTE "Foo-1" USING SQL DESCRIPTOR indesc; 47 48 EXEC SQL DEALLOCATE "Foo-1"; 49 50 EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = :val1; 51 EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2i, DATA = :val2; 52 53 EXEC SQL EXECUTE foo2 USING SQL DESCRIPTOR indesc INTO SQL DESCRIPTOR :desc1; 54 55 EXEC SQL GET DESCRIPTOR :desc1 VALUE 1 :val2output = DATA; 56 printf("output = %s\n", val2output); 57 58 EXEC SQL DECLARE c1 CURSOR FOR foo2; 59 EXEC SQL OPEN c1 USING SQL DESCRIPTOR indesc; 60 61 EXEC SQL FETCH next FROM c1 INTO :val1output:ind1, :val2output:ind2; 62 printf("val1=%d (ind1: %d) val2=%s (ind2: %d)\n", 63 val1output, ind1, val2output, ind2); 64 65 EXEC SQL CLOSE c1; 66 67 EXEC SQL SET DESCRIPTOR indesc COUNT = 1; 68 EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 2; 69 70 EXEC SQL DECLARE c2 CURSOR FOR foo3; 71 EXEC SQL OPEN c2 USING SQL DESCRIPTOR indesc; 72 73 EXEC SQL FETCH next FROM c2 INTO :val1output, :val2output :val2i; 74 printf("val1=%d val2=%s\n", val1output, val2i ? "null" : val2output); 75 76 EXEC SQL CLOSE c2; 77 78 EXEC SQL SELECT * INTO :val1output, :val2output:val2i FROM test1 where a = 3; 79 printf("val1=%d val2=%c%c%c%c warn=%c truncate=%d\n", val1output, val2output[0], val2output[1], val2output[2], val2output[3], sqlca.sqlwarn[0], val2i); 80 81 EXEC SQL DROP TABLE test1; 82 EXEC SQL DEALLOCATE ALL; 83 EXEC SQL DISCONNECT; 84 85 EXEC SQL DEALLOCATE DESCRIPTOR indesc; 86 EXEC SQL DEALLOCATE DESCRIPTOR :desc1; 87 88 return 0; 89} 90