Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <postgresql/libpq-fe.h>
- #include <string.h>
- #include <stdio.h>
- struct Insumo{
- char *nombre;
- };
- struct Insumo insumos[50];
- int main(){
- PGconn *conn;
- PGresult *res;
- int rec_count;
- int row;
- conn = PQconnectdb("dbname=SistemaProduccion host=localhost user=postgres password=andyjosue");
- if (PQstatus(conn) == CONNECTION_BAD) {
- printf("We were unable to connect to the database");
- }
- res = PQexec(conn,
- "select * from Insumos");
- if (PQresultStatus(res) != PGRES_TUPLES_OK) {
- printf("We did not get any data!");
- }
- rec_count = PQntuples(res);
- printf("We received %d records.\n", rec_count);
- printf("==========================\n");
- for (row=0; row<rec_count; row++) {
- // printf("%s\t", PQgetvalue(res, row, 1));
- insumos[row].nombre = PQgetvalue(res, row, 1);
- //insumos[row]->nombre = PQgetvalue(res, row, 1);
- printf("\n");
- }
- for(int k=0;k<rec_count;k++){
- printf("%s \n",insumos[0].nombre);
- }
- PQclear(res);
- PQfinish(conn);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement