Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8736413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:17:53+00:00 2026-06-13T10:17:53+00:00

I am using libpq-fe to connect to the sql server as explained here .

  • 0

I am using libpq-fe to connect to the sql server as explained here.
I made a small file to check login using this api.

Here is the file psql.cpp:

#include <iostream>
#include <libpq-fe.h>
#include <string>
using namespace std;

void CloseConn(PGconn *conn)
{
  PQfinish(conn);
  getchar();
}

PGconn *ConnectDB(string user="postgres",string password="123321",string dbname="bridge",string hostaddr="127.0.0.1",string port="5432")
{
  PGconn *conn = NULL;
  string s = "user=" + user + " password=" + password + " dbname=" +dbname + " hostaddr=" + hostaddr + " port=" + port;

  // Make a connection to the database
  conn = PQconnectdb(s.c_str());

  // Check to see that the backend connection was successfully made
  if (PQstatus(conn) != CONNECTION_OK)
  {
    cout << "Connection to database failed.\n";
    CloseConn(conn);
  }

  cout << "Connection to database - OK\n";

  return conn;
}


void login_check(PGconn *conn, string username, string password)
{
  string query = "SELECT * FROM login where plid='" + username + "'";

  PGresult *res = PQexec(conn,query.c_str());

  if(PQresultStatus(res) == PGRES_TUPLES_OK)//successful completion of a command returning data
  {
    cout << "query executed successfully\n";
    int row = PQntuples(res); // number of rows in the output of the query
    cout<<row<<endl;
    if (row != 1)
    {
      //wrong username
    }
    else
    {      
      cout<<PQgetvalue(res,0,1)<<endl;
      if( !(string(PQgetvalue(res,0,1)).compare(password)) )//return 0 on equality
      {
        cout<<"valid user";
      }
    }
  }

  // Clear result
  PQclear(res);
}

I put hits main function in this file and everything works fine:

int main()
{
  PGconn *conn = NULL;
  //conn = ConnectDB("postgres","123321","bridge","127.0.0.1","5432");
  conn = ConnectDB("postgres","123321","bridge","127.0.0.1","5432");

  if (conn != NULL) {
    login(conn, "11111000", "abcd");
    CloseConn(conn);
  }

  return 0;

}

Now I want to include this file in another .cpp file so I made a psql.h file:

#include <libpq-fe.h>
#include <string>
using namespace std;

PGconn *ConnectDB(string ,string, string, string, string);
void login_check(PGconn, string, string);
void CloseConn(PGconn);

For using the psql.h file the changes I have done in psql.cpp header are:

#include "psql.h"
#include <iostream>

void CloseConn(PGconn *conn)
{
...
...

and I removed the main function from this.

Now in my new file – dispatcher.cpp I want to include this file, So change in its header:

#include "psql.h"

And I put the contents of the main function that I have mentioned above in the main function of this file. When I compile this file I got the error:

dispatcher.cpp: In function ‘void login(int)’:
dispatcher.cpp:154:45: error: parameter 1 of ‘void login_check(PGconn, std::string, std::string)’ has incomplete type ‘PGconn {aka pg_conn}’
dispatcher.cpp:155:23: error: parameter 1 of ‘void CloseConn(PGconn)’ has incomplete type ‘PGconn {aka pg_conn}’

My makefile:

dispatcher:dispatcher.o access.o psql.o
    g++ dispatcher.o access.o psql.o -pthread -I /usr/include/postgresql -lpq -o ./bin/dispatcher

dispatcher.o:dispatcher.cpp
    g++ -I /usr/include/postgresql -lpq -c dispatcher.cpp

access.o:access.cpp access.h
    g++ -c access.cpp

psql.o:psql.cpp psql.h
    g++ -c psql.cpp -I /usr/include/postgresql -lpq

You can ignore access.o it only contain accessories. I know I am c programming using c++. Why I am getting this error. Is it anything specific to CPP. The login() is a simple function that I am calling from the dispatcher's main and its defination is same as of the main I have mentioned above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:17:55+00:00Added an answer on June 13, 2026 at 10:17 am
    void login_check(PGconn, string, string);
    void CloseConn(PGconn);
    

    This doesn’t match your functions. Use:

    void login_check(PGconn*, string, string);
    void CloseConn(PGconn*);
    

    You can have pointers to incomplete types, but not incomplete types, in function arguments. The compiler needs to know the size of the objects to set up the call/stack properly. It can’t do that with incomplete types, but it can with pointers to such.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL Server 2008 R2 we are looking for a way to select the
Using Microsoft SQL Server 2005, is there any way to see when a table
I'm trying to install postgresql on my server using chef-solo. I've had this working
Using SQL Server 2005 Leave Table ID StartDate EndDate 001 02/03/2010 02/03/2010 002 02/03/2010
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using CI for the first time and i'm smashing my head with this seemingly
Using ASIHTTPRequest, I downloaded a zip file containing a folder with several audio files.
I've created a Objective-C class to interface with PostgreSQL using libpq. It mostly works
Using Java,I have to fetch multiple sets of values from an XML file to
First time posting here, will try to be succinct. This is a classic 'can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.