473,471 Members | 4,650 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Unable to run testlibpq.c program

Hello All,
Im novice to Postgres ,Im trying to program in 'libpq the C
application programmer's interface to PostgreSQL'
I was trying to execute sample 'testlibpq.c'.

I did the following......

#su postgres(enter)

(bash#)createdb sampledb
(bash#)psql sampledb

(sampledb#)create table sirisha (name varchar(20),city varchar(20));
(sampledb#)insert into sirisha(name,city) values('Vikram','Toronto');
(sampledb#)\q

(bash#)gcc -I/usr/include/pgsql sirisha_retrieve.c -o output2 -lpq
(enter)

/usr/bin/ld: cannot open output file output2: Permission denied
collect2: ld returned 1 exit status

What does the above message signify? I tried to run the program as
root still the same prob ?
What is the problem?
Thanks in advance ......

Vikram.
*********Source Code is as follows.*********************
*
* testlibpq.c
*
* Test the C version of libpq, the PostgreSQL frontend
* library.
*/
#include <stdio.h>
#include <libpq-fe.h>

void
exit_nicely(PGconn *conn)
{
PQfinish(conn);
exit(1);
}

main()
{
char *pghost,
*pgport,
*pgoptions,
*pgtty;
char *dbName;
int nFields;
int i,
j;

/* FILE *debug; */

PGconn *conn;
PGresult *res;

/*
* begin, by setting the parameters for a backend connection if
the
* parameters are null, then the system will try to use
reasonable
* defaults by looking up environment variables or, failing that,
* using hardwired constants
*/
pghost = NULL; /* host name of the backend server */
pgport = NULL; /* port of the backend server */
pgoptions = NULL; /* special options to start up the
backend
* server */
pgtty = NULL; /* debugging tty for the backend
server */
dbName = "template1";

/* make a connection to the database */
conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName);

/*
* check to see that the backend connection was successfully made
*/
if (PQstatus(conn) == CONNECTION_BAD)
{
fprintf(stderr, "Connection to database '%s' failed.\n",
dbName);
fprintf(stderr, "%s", PQerrorMessage(conn));
exit_nicely(conn);
}

/* debug = fopen("/tmp/trace.out","w"); */
/* PQtrace(conn, debug); */

/* start a transaction block */
res = PQexec(conn, "BEGIN");
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "BEGIN command failed\n");
PQclear(res);
exit_nicely(conn);
}

/*
* should PQclear PGresult whenever it is no longer needed to
avoid
* memory leaks
*/
PQclear(res);

/*
* fetch rows from the pg_database, the system catalog of
* databases
*/
res = PQexec(conn, "DECLARE mycursor CURSOR FOR SELECT * FROM
pg_database");
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "DECLARE CURSOR command failed\n");
PQclear(res);
exit_nicely(conn);
}
PQclear(res);
res = PQexec(conn, "FETCH ALL in mycursor");
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "FETCH ALL command didn't return tuples
properly\n");
PQclear(res);
exit_nicely(conn);
}

/* first, print out the attribute names */
nFields = PQnfields(res);
for (i = 0; i < nFields; i++)
printf("%-15s", PQfname(res, i));
printf("\n\n");

/* next, print out the rows */
for (i = 0; i < PQntuples(res); i++)
{
for (j = 0; j < nFields; j++)
printf("%-15s", PQgetvalue(res, i, j));
printf("\n");
}
PQclear(res);

/* close the cursor */
res = PQexec(conn, "CLOSE mycursor");
PQclear(res);

/* commit the transaction */
res = PQexec(conn, "COMMIT");
PQclear(res);

/* close the connection to the database and cleanup */
PQfinish(conn);

/* fclose(debug); */
return 0;

}
Nov 23 '05 #1
1 1810
vi********@yahoo.com (Vikram) writes:
(bash#)gcc -I/usr/include/pgsql sirisha_retrieve.c -o output2 -lpq
/usr/bin/ld: cannot open output file output2: Permission denied
collect2: ld returned 1 exit status What does the above message signify?


It sure looks like you're doing this in a directory that you don't have
write permission for.

A less-probable alternative is that output2 already exists in your
current directory and you don't have write permission to overwrite it.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jonathan Polley | last post by:
I have one account on a WindowsXP machine that refuses to run IDLE (or any other python script that uses Tk). Other people can login to that PC and IDLE runs just fine, so it is not an...
2
by: Jim Chapman | last post by:
This is driving me nuts. I've been using VB.NET for about a year on this machine and decided to try C#. This is what I get when I try to debug (F11): Window title = Microsoft Development...
22
by: Kristof Thys | last post by:
Hello, I'm developing a C# - windows forms application. To get some information for my application, I'm connecting to an URL, wich gives me XML generated using php. With 90% of the users, this...
0
by: Michael R. Pierotti | last post by:
Has anyone seen this error before when trying to make the install on a program. ------ Starting pre-build validation for project 'HafaSMPPInstall' ------ WARNING: Unable to find dependency...
1
by: geetu | last post by:
hi to all.. pls help me its urgent.. i m unable to understand the exact answer .. tell me step to be carried to set libraries or directory path so that i can execute a simple program everytime i...
6
by: Bob Rock | last post by:
Hello, I'm using an executable (for which I do not have the source code nor the pdb file) as the startup application to load a DLL I'm writing and need to debug. If I try to debug the DLL I...
1
markmcgookin
by: markmcgookin | last post by:
Hi Folks, this is a problem I had a few days ago, and I was able to solve it, but I thought I'd post the solution I found here incase anyone has a similar problem! I found this stuff on an MSNDN...
1
by: Benedict Verheyen | last post by:
Hi, i get an "Unable to relay for" when trying to send an email from within my network to an email address not on my domain. I don't understand why it says "relaying" as i'm sending from an...
5
by: kailashchandra | last post by:
I am trying to upload a file in php,but it gives me error msg please Help me? My Code is like below:- i have one php file named upload.php and i have another html file named upload.html and...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.