Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <libpq-fe.h>
- void doSQL(PGconn *conn, char *command)
- {
- PGresult *result;
- printf("%s\n", command);
- result = PQexec(conn, command);
- printf("status is : %s\n", PQresStatus(PQresultStatus(result)));
- printf("#rows affected: %s\n", PQcmdTuples(result));
- printf("result message: %s\n", PQresultErrorMessage(result));
- switch(PQresultStatus(result)) {
- case PGRES_TUPLES_OK:
- {
- int n = 0, m = 0;
- int nrows = PQntuples(result);
- int nfields = PQnfields(result);
- printf("number of rows returned = %d\n", nrows);
- printf("number of fields returned = %d\n", nfields);
- for(m = 0; m < nrows; m++) {
- for(n = 0; n < nfields; n++)
- printf(" %s = %s", PQfname(result, n),PQgetvalue(result,m,n));
- printf("\n");
- }
- }
- }
- PQclear(result);
- }
- int main()
- {
- PGresult *result;
- PGconn *conn;
- conn = PQconnectdb("host=localhost port=5432 dbname=pkulas user=pkulas password=");
- if(PQstatus(conn) == CONNECTION_OK) {
- printf("connection made\n");
- doSQL(conn, "CREATE TABLE nazwa (lp integer,imie varchar(40),nazwisko varchar(40),ulica varchar(40),numer integer,kod varchar(6),miejscowosc varchar(40),telefon varchar(20),email varchar(40),data_ur date)");
- }
- else
- printf("connection failed: %s\n", PQerrorMessage(conn));
- PQfinish(conn);
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment