Commit a968b381 by trkall

andmebaasid

parent d42588b2
#include <stdio.h>
#include <pgsql/libpq-fe.h>
void yl1(PGconn*);
int main(void)
{
PGconn *conn;
conn = PQconnectdb("dbname=ablib host=ewis.pld.ttu.ee user=student password=iag0582");
if (PQstatus(conn) == CONNECTION_BAD) {
printf("We were unable to connect to the database\n");
return 0;
}
yl1(conn);
return 0;
}
void yl1(PGconn *conn)
{
PGresult *res;
int rec_count;
int row;
int col;
res = PQexec(conn, "SELECT name, length_km FROM river LIMIT 5;");
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
printf("We did not get any data!\n");
PQfinish(conn);
} else {
rec_count = PQntuples(res);
printf("We received %d records.\n", rec_count);
printf("==========================\n");
for (row=0; row<rec_count; row++) {
for (col=0; col<2; col++) {
printf("%-10s\t", PQgetvalue(res, row, col));
}
printf("\n");
}
printf("==========================\n");
}
}
#include <stdio.h>
#include <pgsql/libpq-fe.h>
void yl1(PGconn*);
void yl2(PGconn*);
void yl3(PGconn*);
int main(void)
{
PGconn *conn;
conn = PQconnectdb("dbname=ablid host=ewis.pld.ttu.ee user=student password=iag0582");
if (PQstatus(conn) == CONNECTION_BAD) {
printf("We were unable to connect to the database\n");
return 0;
}
//yl1(conn); tehtud!
//yl2(conn); tehtud!
yl3(conn);
return 0;
}
void yl1(PGconn *conn)
{
PGresult *res;
int rec_count;
int row;
int col;
res = PQexec(conn, "SELECT joenimi, pikkus_km FROM joe_andmed ORDER BY pikkus_km DESC LIMIT 5;");
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
printf("We did not get any data!\n");
PQfinish(conn);
} else {
rec_count = PQntuples(res);
printf("We received %d records.\n", rec_count);
printf("==========================\n");
for (row=0; row<rec_count; row++) {
for (col=0; col<2; col++) {
printf("%-10s\t", PQgetvalue(res, row, col));
}
printf("\n");
}
printf("==========================\n");
}
}
//Pärida jõed, mis on peajõed ja pikemad kui 70km.Peajõe kindlaks tegemiseks saab kasutada id_peajogi välja.
void yl2(PGconn *conn)
{
PGresult *res;
int rec_count;
int row;
int col;
res = PQexec(conn, "SELECT joenimi, pikkus_km FROM joe_andmed WHERE pikkus_km > 70 AND id_peajogi = id_jogi ORDER BY pikkus_km DESC;");
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
printf("We did not get any data!\n");
PQfinish(conn);
} else {
rec_count = PQntuples(res);
printf("We received %d records.\n", rec_count);
printf("==========================\n");
for (row=0; row<rec_count; row++) {
for (col=0; col<2; col++) {
printf("%-10s\t", PQgetvalue(res, row, col));
}
printf("\n");
}
printf("==========================\n");
}
}
//Leida eelmises punktis leitud jõgedel asetsevad seirejaamad.
void yl3(PGconn *conn)
{
PGresult *res;
PGresult *res1;
PGresult *res2;
int rec_count;
int row;
int col;
//res = PQexec(conn, "SELECT joenimi, id_jogi FROM joe_andmed WHERE pikkus_km > 70 AND id_peajogi = id_jogi INNER JOIN seire_jaamad ON ;");
res = PQexec(conn, "SELECT joenimi, id_jogi FROM joe_andmed INNER JOIN seire_jaamad ON
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
printf("We did not get any data!\n");
PQfinish(conn);
} else {
rec_count = PQntuples(res);
printf("We received %d records.\n", rec_count);
printf("==========================\n");
for (row=0; row<rec_count; row++) {
for (col=0; col<2; col++) {
printf("%-10s\t", PQgetvalue(res, row, col));
}
printf("\n");
}
printf("==========================\n");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment