Exemple #1
0
void generateHTML(){
  PGresult* result = getSqlResult("SELECT * FROM ksiazka");

	PGresult* result2 = getSqlResult("SELECT * FROM autor");		


		if(PQresultStatus(result)==PGRES_TUPLES_OK) 
    		{ 

		      FILE * fpx;

		      fpx = fopen ("index.html", "w+");	

		      PQprintOpt pqp;
		      pqp.header = 1;
		      pqp.align = 0;
		      pqp.html3 = 1;
		      pqp.expanded = 0;
		      pqp.pager = 0;
		      pqp.fieldSep = "";
		      pqp.tableOpt = "";
		      pqp.caption = "Ksiazki";
		      pqp.fieldName = NULL;

		      PQprintOpt pqp2;
		      pqp2.header = 1;
		      pqp2.align = 0;
		      pqp2.html3 = 1;
		      pqp2.expanded = 0;
		      pqp2.pager = 0;
		      pqp2.fieldSep = "";
		      pqp2.tableOpt = "";
		      pqp2.caption = "Autor";
		      pqp2.fieldName = NULL;

		      fprintf(fpx,"<!DOCTYPE HTML>\n");
		      fprintf(fpx,"<HTML><HEAD><link rel=\"stylesheet\" href=\"style.css\">\n<meta name=\"Author\" content=\"Szymon Sedek\" /><title>Dane o ksiazkach</title><meta content=\"text/html;charset=utf-8\" http-equiv=\"Content-Type\"></HEAD>\n<BODY>\n");
			  PQprint(fpx, result, &pqp);
			  PQprint(fpx, result2, &pqp2);
		      fprintf(fpx,"</BODY></HTML>\n");
		      fclose(fpx);
			  system("sed -i -e 's/align=\"right\"//g' index.html");			
			  system("sed -i -e 's/align=\"top\"//g' index.html");	
			
	
				fpx = fopen ("style.css", "w+");
				fprintf(fpx,"BODY{font-family: sans-serif; font-size: 15px; background: #666699; }\n");
				fprintf(fpx,"caption{font-size: 25px; font-style: italic; color: #0000FF;}\n");
				fprintf(fpx,"caption:before{content: \"Tabela: \";}\n");
				fprintf(fpx,"table, th, td {text-align: center; border-style: solid; border-color: black; margin-left: 550px; margin-top: 120px;}\n");
				fclose(fpx);
	printf("\n\tPlik html o nazwie index.html wygenerowano pomyslnie !\n\n");
		      
		}
	}
Exemple #2
0
int main()
{
  PGresult *result;
  PGconn *conn;

  conn = PQconnectdb("");

  if(PQstatus(conn) == CONNECTION_OK) {

    result = PQexec(conn, "SELECT * FROM customer 
                           WHERE town = 'Bingham'");
    { 
      PQprintOpt pqp;
      pqp.header = 1;
      pqp.align = 1;
      pqp.html3 = 1;
      pqp.expanded = 0;
      pqp.pager = 0;
      pqp.fieldSep = "";
      pqp.tableOpt = "align=center";
      pqp.caption = "Bingham Customer List";
      pqp.fieldName = NULL;
      printf("<HTML><HEAD></HEAD><BODY>\n");
      PQprint(stdout, result, &pqp);
      printf("</BODY></HTML>\n");
    }
Exemple #3
0
/*
 * Actually execute the query in *query.
 *
 * Returns 0 if the query finished successfully, 1 otherwise.
 */
static int
handle_execution(char *query) 
{
    PGresult *result;
    int retval = 0;
    PQprintOpt opt;
    
    result = PQexec(conn, query);

    if (result == NULL) {
      fprintf(stderr,"%s", PQerrorMessage(conn));
      return 1;
    }

    switch (PQresultStatus(result)) {
    case PGRES_EMPTY_QUERY:
	break;
    case PGRES_COMMAND_OK:
	break;
    case PGRES_TUPLES_OK:
/*	PQprintTuples(result,stdout,PrintAttNames,TerseOutput,COLWIDTH); */
/* 	if (TerseOutput)
 	    PQdisplayTuples(result,stdout,1,"",PrintAttNames,TerseOutput);
 	else
 	    PQdisplayTuples(result,stdout,1,"|",PrintAttNames,TerseOutput); */
        memset(&opt, 0, sizeof opt);
        opt.header = opt.align = opt.standard = 1;
	if (TerseOutput)
	    opt.fieldSep = "";
	else
	    opt.fieldSep = "|";
        PQprint(stdout, result, &opt);
        break;
    case PGRES_COPY_OUT:
	handle_copy_out(result);
	break;
    case PGRES_COPY_IN:
	handle_copy_in(result);
	break;
    case PGRES_BAD_RESPONSE:
	retval = 1;
	break;
    case PGRES_NONFATAL_ERROR:
	retval = 1;
	break;
    case PGRES_FATAL_ERROR:
	retval = 1;
	break;
    }

    if (SingleStepMode) {
	fflush(stdin);
	printf("\npress return to continue ...\n");
	getc(stdin);	/* assume stdin is not a file! */
    }
    return(retval);
}
Exemple #4
0
//wypisanie calej bazy
void print(PGconn *conn){
	PGresult *result;
	result = PQexec(conn, "SELECT * FROM cars");

	if(PQresultStatus(result) == PGRES_TUPLES_OK){
		PQprintOpt pqp;
		pqp.header = 1;
		pqp.align = 1;
		pqp.html3 = 1;
		pqp.expanded = 0;
		pqp.pager = 0;
		pqp.fieldSep = "";
		pqp.tableOpt = "align=center";
		pqp.caption = "Cars list";
		pqp.fieldName = NULL;
		printf("<HTML><HEAD></HEAD><BODY>\n");
		PQprint(stdout, result, &pqp);
		printf("</BODY></HTML>\n");
	}
}