feat: add server-version
This commit is contained in:
parent
15f83c7f10
commit
284211e443
|
@ -15,3 +15,9 @@ make
|
||||||
```
|
```
|
||||||
./main 'postgresql://begerad:secret@localhost:5432/vbn_data'
|
./main 'postgresql://begerad:secret@localhost:5432/vbn_data'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* or run
|
||||||
|
|
||||||
|
```
|
||||||
|
./main 'host=localhost port=5432 user=begerad password=<secret> dbname=vbn_data'
|
||||||
|
```
|
|
@ -1,9 +1,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <libpq-fe.h>
|
#include <libpq-fe.h>
|
||||||
int main() {
|
int main() {
|
||||||
|
/*return version of libpq*/
|
||||||
int lib_ver = PQlibVersion();
|
int lib_ver = PQlibVersion();
|
||||||
printf("Version of libpq: %d\n", lib_ver);
|
printf("Version of libpq: %d\n", lib_ver);
|
||||||
printf("Version of libpq: %d\n", lib_ver);
|
|
||||||
printf("Version of libpq: %d\n", lib_ver);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,11 @@ EXE = main
|
||||||
# Compiler, Linker Defines
|
# Compiler, Linker Defines
|
||||||
CC = /usr/bin/gcc
|
CC = /usr/bin/gcc
|
||||||
#
|
#
|
||||||
all:
|
all: main.o
|
||||||
$(CC) main.c -I/usr/include/postgresql -L/usr/lib/x86_64-linux-gnu -lpq -std=c99 -Wall -o $(EXE)
|
$(CC) main.c -I/usr/include/postgresql -L/usr/lib/x86_64-linux-gnu -lpq -std=c99 -Wall -o $(EXE)
|
||||||
|
#
|
||||||
|
main.o:
|
||||||
|
$(CC) -c main.c -I/usr/include/postgresql
|
||||||
# Clean Up Objects, Exectuables, Dumps out of source directory
|
# Clean Up Objects, Exectuables, Dumps out of source directory
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o $(EXE) *~
|
$(RM) *.o $(EXE) *~
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
# Docu
|
||||||
|
#
|
||||||
|
#$@ is the name of the file to be made
|
||||||
|
#$? is the names of the changed dependents
|
||||||
|
#$< the name of the related file that caused the action
|
||||||
|
#$* the prefix shared by target and dependent files
|
||||||
|
#
|
||||||
|
# Others
|
||||||
|
RM = /bin/rm -f
|
||||||
|
#
|
||||||
|
# Source, Executable, Includes, Library Defines
|
||||||
|
EXE = main
|
||||||
|
#
|
||||||
|
# Compiler, Linker Defines
|
||||||
|
CC = /usr/bin/gcc
|
||||||
|
#
|
||||||
|
all: main.o
|
||||||
|
$(CC) main.c -I/usr/include/postgresql -L/usr/lib/x86_64-linux-gnu -lpq -std=c99 -Wall -o $(EXE)
|
||||||
|
#
|
||||||
|
main.o:
|
||||||
|
$(CC) -c main.c -I/usr/include/postgresql
|
||||||
|
# Clean Up Objects, Exectuables, Dumps out of source directory
|
||||||
|
clean:
|
||||||
|
$(RM) *.o $(EXE) *~
|
|
@ -0,0 +1,50 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <libpq-fe.h>
|
||||||
|
|
||||||
|
void do_exit(PGconn *conn) {
|
||||||
|
/*close connection and free memory*/
|
||||||
|
PQfinish(conn);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
/*declaration*/
|
||||||
|
const char *conninfo;
|
||||||
|
|
||||||
|
printf("main() Started...\n");
|
||||||
|
|
||||||
|
/*read command line*/
|
||||||
|
if (argc > 1){
|
||||||
|
printf("main() argv[1]: %s\n", argv[1]);
|
||||||
|
conninfo = argv[1];
|
||||||
|
}else{
|
||||||
|
conninfo = "dbname=postgres";
|
||||||
|
}
|
||||||
|
|
||||||
|
/*connect to database*/
|
||||||
|
PGconn *conn = PQconnectdb(conninfo);
|
||||||
|
|
||||||
|
if (PQstatus(conn) == CONNECTION_BAD) {
|
||||||
|
fprintf(stderr, "Connection to database failed: %s\n",
|
||||||
|
PQerrorMessage(conn));
|
||||||
|
do_exit(conn);
|
||||||
|
}else if(PQstatus(conn)==CONNECTION_OK){
|
||||||
|
printf("main() connected to database\n");
|
||||||
|
}else{
|
||||||
|
printf("main() connection status NOT known\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
char *user = PQuser(conn);
|
||||||
|
char *db_name = PQdb(conn);
|
||||||
|
char *pswd = PQpass(conn);
|
||||||
|
printf("User: %s\n", user);
|
||||||
|
printf("Database name: %s\n", db_name);
|
||||||
|
printf("Password: %s\n", pswd);
|
||||||
|
|
||||||
|
/*return integer representing database version*/
|
||||||
|
int ver = PQserverVersion(conn);
|
||||||
|
printf("Server version: %d\n", ver);
|
||||||
|
|
||||||
|
do_exit(conn);
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
# Docu
|
||||||
|
#
|
||||||
|
#$@ is the name of the file to be made
|
||||||
|
#$? is the names of the changed dependents
|
||||||
|
#$< the name of the related file that caused the action
|
||||||
|
#$* the prefix shared by target and dependent files
|
||||||
|
#
|
||||||
|
# Others
|
||||||
|
RM = /bin/rm -f
|
||||||
|
#
|
||||||
|
# Source, Executable, Includes, Library Defines
|
||||||
|
EXE = main
|
||||||
|
#
|
||||||
|
# Compiler, Linker Defines
|
||||||
|
CC = /usr/bin/gcc
|
||||||
|
#
|
||||||
|
all: main.o
|
||||||
|
$(CC) main.c -I/usr/include/postgresql -L/usr/lib/x86_64-linux-gnu -lpq -std=c99 -Wall -o $(EXE)
|
||||||
|
#
|
||||||
|
main.o:
|
||||||
|
$(CC) -c main.c -I/usr/include/postgresql
|
||||||
|
# Clean Up Objects, Exectuables, Dumps out of source directory
|
||||||
|
clean:
|
||||||
|
$(RM) *.o $(EXE) *~
|
|
@ -0,0 +1,21 @@
|
||||||
|
# Docu
|
||||||
|
#
|
||||||
|
#$@ is the name of the file to be made
|
||||||
|
#$? is the names of the changed dependents
|
||||||
|
#$< the name of the related file that caused the action
|
||||||
|
#$* the prefix shared by target and dependent files
|
||||||
|
#
|
||||||
|
# Others
|
||||||
|
RM = /bin/rm -f
|
||||||
|
#
|
||||||
|
# Source, Executable, Includes, Library Defines
|
||||||
|
EXE = main
|
||||||
|
#
|
||||||
|
# Compiler, Linker Defines
|
||||||
|
CC = /usr/bin/gcc
|
||||||
|
#
|
||||||
|
all:
|
||||||
|
$(CC) main.c -I/usr/include/postgresql -L/usr/lib/x86_64-linux-gnu -lpq -std=c99 -Wall -o $(EXE)
|
||||||
|
# Clean Up Objects, Exectuables, Dumps out of source directory
|
||||||
|
clean:
|
||||||
|
$(RM) *.o $(EXE) *~
|
|
@ -0,0 +1,24 @@
|
||||||
|
# Docu
|
||||||
|
#
|
||||||
|
#$@ is the name of the file to be made
|
||||||
|
#$? is the names of the changed dependents
|
||||||
|
#$< the name of the related file that caused the action
|
||||||
|
#$* the prefix shared by target and dependent files
|
||||||
|
#
|
||||||
|
# Others
|
||||||
|
RM = /bin/rm -f
|
||||||
|
#
|
||||||
|
# Source, Executable, Includes, Library Defines
|
||||||
|
EXE = main
|
||||||
|
#
|
||||||
|
# Compiler, Linker Defines
|
||||||
|
CC = /usr/bin/gcc
|
||||||
|
#
|
||||||
|
all: main.o
|
||||||
|
$(CC) main.c -I/usr/include/postgresql -L/usr/lib/x86_64-linux-gnu -lpq -std=c99 -Wall -o $(EXE)
|
||||||
|
#
|
||||||
|
main.o:
|
||||||
|
$(CC) -c main.c -I/usr/include/postgresql
|
||||||
|
# Clean Up Objects, Exectuables, Dumps out of source directory
|
||||||
|
clean:
|
||||||
|
$(RM) *.o $(EXE) *~
|
|
@ -0,0 +1,23 @@
|
||||||
|
* build
|
||||||
|
|
||||||
|
```
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
* run
|
||||||
|
|
||||||
|
```
|
||||||
|
./main 'postgresql://begerad:secret@localhost:5432/sib00_vbn_gtfs'
|
||||||
|
```
|
||||||
|
|
||||||
|
* or run
|
||||||
|
|
||||||
|
```
|
||||||
|
./main 'postgresql://begerad:secret@localhost:5432/vbn_data'
|
||||||
|
```
|
||||||
|
|
||||||
|
* or run
|
||||||
|
|
||||||
|
```
|
||||||
|
./main "host=localhost port=5432 user=begerad password=<secret> dbname=vbn_data"
|
||||||
|
```
|
Loading…
Reference in New Issue