Line data Source code
1 : /* 2 : * this file tests multiple connections to databases and switches 3 : * between them. 4 : */ 5 : 6 : #include <stdlib.h> 7 : #include <string.h> 8 : #include <stdlib.h> 9 : #include <stdio.h> 10 : 11 : exec sql include ../regression; 12 : 13 : int 14 4 : main(void) 15 : { 16 : exec sql begin declare section; 17 : char id[200]; 18 : char res[200]; 19 : exec sql end declare section; 20 : 21 4 : ECPGdebug(1, stderr); 22 : 23 4 : strcpy(id, "first"); 24 4 : exec sql connect to ecpg2_regression as :id; 25 4 : exec sql connect to REGRESSDB1 as second; 26 : 27 : /* this selects from "second" which was opened last */ 28 4 : exec sql select current_database() into :res; 29 4 : exec sql at first select current_database() into :res; 30 4 : exec sql at second select current_database() into :res; 31 : 32 4 : exec sql set connection first; 33 4 : exec sql select current_database() into :res; 34 : 35 : /* this will disconnect from "first" */ 36 4 : exec sql disconnect; 37 4 : exec sql select current_database() into :res; 38 : 39 : /* error here since "first" is already disconnected */ 40 4 : exec sql disconnect :id; 41 : 42 : /* disconnect from "second" */ 43 4 : exec sql disconnect; 44 : 45 4 : return 0; 46 : }