#include #include #include "func.h" #include "www.h" #include "wwwedit.h" #include "/usr/include/pgsql/libpq-fe.h" void wwwedit_showlist() { char *stala="select name from html;", *pghost, *pgport, *pguser, *pgpw, *pgoptions, *pgtty; char *dbName; int nFields; int i,j; PGconn *conn; PGresult *res; pghost = "direct"; pgport = "5432"; pgoptions = NULL; pguser="cez"; pgpw ="ala"; pgtty = NULL; dbName ="cez"; conn = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName,pguser,pgpw); if (PQstatus(conn) == CONNECTION_BAD) { printf("Polaczenie z baza '%s' nieudane.\n", dbName); printf("%s", PQerrorMessage(conn)); PQfinish(conn); exit(1); } res = PQexec(conn, stala ); if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) { printf("Blad wywolania %s bo
%s",stala,PQerrorMessage(conn)); PQclear(res); PQfinish(conn); exit(1); } nFields = PQnfields(res); html_naglowek("Lista Stron"); printf(""); for (i=0 ; i< PQntuples(res) ; i++) { for (j =0; j < nFields; j++) { printf("\n"); printf("\t", PQgetvalue(res, i, j),PQgetvalue(res,i, j)); printf("\n"); } } printf("
%s
"); PQfinish(conn); html_koniec(); } void wwwedit_edit(const char *strona) { char *query; char *stala="select body from html where name='", *stala1="';", *pghost, *pgport, *pguser, *pgpw, *pgoptions, *pgtty; char *dbName; int nFields; int i,j; PGconn *conn; PGresult *res; query=(char *)malloc(sizeof(char)*(licz_znak(strona)+140)); strcpy(query,stala); if (strona!=NULL) { strcat(query,strona); } strcat(query,stala1); pghost = "direct"; pgport = "5432"; pgoptions = NULL; pguser="cez"; pgpw ="ala"; pgtty = NULL; dbName ="cez"; conn = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName,pguser,pgpw); if (PQstatus(conn) == CONNECTION_BAD) { printf("Polaczenie z baza '%s' nieudane.\n", dbName); printf("%s", PQerrorMessage(conn)); PQfinish(conn); exit(1); } res = PQexec(conn, query ); if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) { printf("Blad wywolania %s bo
%s",query,PQerrorMessage(conn)); PQclear(res); PQfinish(conn); exit(1); } nFields = PQnfields(res); html_naglowek("Edycja Strony"); printf("
"); printf("", PQgetvalue(res, 0, 0)); printf(" ",strona); printf(",%s",strona); html_koniec(); PQfinish(conn); free(query); }