Header And Logo

PostgreSQL
| The world's most advanced open source database.

connect-test1.c

Go to the documentation of this file.
00001 /* Processed by ecpg (regression mode) */
00002 /* These include files are added by the preprocessor */
00003 #include <ecpglib.h>
00004 #include <ecpgerrno.h>
00005 #include <sqlca.h>
00006 /* End of automatic include section */
00007 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00008 
00009 #line 1 "test1.pgc"
00010 /*
00011  * this file tests all sorts of connecting to one single database.
00012  */
00013 
00014 #include <stdlib.h>
00015 #include <string.h>
00016 #include <stdlib.h>
00017 #include <stdio.h>
00018 
00019 /* do not include regression.h */
00020 
00021 int
00022 main(void)
00023 {
00024 /* exec sql begin declare section */
00025      
00026      
00027 
00028 #line 16 "test1.pgc"
00029  char db [ 200 ] ;
00030  
00031 #line 17 "test1.pgc"
00032  char pw [ 200 ] ;
00033 /* exec sql end declare section */
00034 #line 18 "test1.pgc"
00035 
00036 
00037     ECPGdebug(1, stderr);
00038 
00039     { ECPGconnect(__LINE__, 0, "connectdb" , NULL, NULL , "main", 0); }
00040 #line 22 "test1.pgc"
00041 
00042     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "alter user connectuser encrypted password 'connectpw'", ECPGt_EOIT, ECPGt_EORT);}
00043 #line 23 "test1.pgc"
00044 
00045     { ECPGdisconnect(__LINE__, "CURRENT");}
00046 #line 24 "test1.pgc"
00047   /* <-- "main" not specified */
00048 
00049     { ECPGconnect(__LINE__, 0, "connectdb@localhost" , NULL, NULL , "main", 0); }
00050 #line 26 "test1.pgc"
00051 
00052     { ECPGdisconnect(__LINE__, "main");}
00053 #line 27 "test1.pgc"
00054 
00055 
00056     { ECPGconnect(__LINE__, 0, "@localhost" , "connectdb" , NULL , "main", 0); }
00057 #line 29 "test1.pgc"
00058 
00059     { ECPGdisconnect(__LINE__, "main");}
00060 #line 30 "test1.pgc"
00061 
00062 
00063     /* exec sql connect to :@TEMP_PORT@ as main user connectdb;
00064     exec sql disconnect main; */
00065 
00066     { ECPGconnect(__LINE__, 0, "tcp:postgresql://localhost/connectdb" , "connectuser" , "connectpw" , NULL, 0); }
00067 #line 35 "test1.pgc"
00068 
00069     { ECPGdisconnect(__LINE__, "CURRENT");}
00070 #line 36 "test1.pgc"
00071 
00072 
00073     { ECPGconnect(__LINE__, 0, "tcp:postgresql://localhost/" , "connectdb" , NULL , NULL, 0); }
00074 #line 38 "test1.pgc"
00075 
00076     { ECPGdisconnect(__LINE__, "CURRENT");}
00077 #line 39 "test1.pgc"
00078 
00079 
00080     strcpy(pw, "connectpw");
00081     strcpy(db, "tcp:postgresql://localhost/connectdb");
00082     { ECPGconnect(__LINE__, 0, db , "connectuser" , pw , NULL, 0); }
00083 #line 43 "test1.pgc"
00084 
00085     { ECPGdisconnect(__LINE__, "CURRENT");}
00086 #line 44 "test1.pgc"
00087 
00088 
00089     { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/connectdb" , "connectuser" , "connectpw" , NULL, 0); }
00090 #line 46 "test1.pgc"
00091 
00092     { ECPGdisconnect(__LINE__, "CURRENT");}
00093 #line 47 "test1.pgc"
00094 
00095 
00096     { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/connectdb?connect_timeout=14" , "connectuser" , NULL , NULL, 0); }
00097 #line 49 "test1.pgc"
00098 
00099     { ECPGdisconnect(__LINE__, "CURRENT");}
00100 #line 50 "test1.pgc"
00101 
00102 
00103     /* wrong db */
00104     { ECPGconnect(__LINE__, 0, "tcp:postgresql://localhost/nonexistant" , "connectuser" , "connectpw" , NULL, 0); }
00105 #line 53 "test1.pgc"
00106 
00107     { ECPGdisconnect(__LINE__, "CURRENT");}
00108 #line 54 "test1.pgc"
00109 
00110 
00111     /* wrong port */
00112     { ECPGconnect(__LINE__, 0, "tcp:postgresql://localhost:20/connectdb" , "connectuser" , "connectpw" , NULL, 0); }
00113 #line 57 "test1.pgc"
00114 
00115     /* no disconnect necessary */
00116 
00117     /* wrong password */
00118     { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/connectdb" , "connectuser" , "wrongpw" , NULL, 0); }
00119 #line 61 "test1.pgc"
00120 
00121     /* no disconnect necessary */
00122 
00123     return (0);
00124 }