2017-08-13 4 views
0

私は正しくsociを使用してmysqlに接続し、sqlを実行できます。しかし、postgresqlと同じ方法ではうまくいきません。これは私のメイクファイルとmain.cppにある:なぜ私は社会を使用してpostgresqlに接続するのに十分な特権がデータベースにないのですか?

all: main.cpp 
    g++ -Wall -g -o main main.cpp -lpq -lsoci_core -lsoci_postgresql -ldl 
clean: 

そして、これはmain.cppにある:私は、端末内のSQL "select count(*) from student"を実行することができ

Error:Cannot execute query. Fatal error. 错误: 对关系 student 权限不够 
while executing "select count(*) from student". 

#include <soci/soci.h> 
#include <soci/postgresql/soci-postgresql.h> 
#include<iostream> 
#include<istream> 
#include<ostream> 
#include<string> 
#include<exception> 

using namespace std; 
using namespace soci; 

int main() { 
    try { 
     session sql("postgresql://dbname=mydb_0"); 
     int count ; 
     sql<< "select count(*) from student", into(count); 
     cout<<"count="<<count<<endl; 
    } catch (exception const &e) { 
     cerr<<"Error:" <<e.what()<<endl; 
    } 
} 

これは、エラーが出力されますしかし、C++のコードはうまくいかない、なぜ?

答えて

0

私はこの問題を自分で解決しました。他の例とは異なり、 "host = 127.0.0.1"と "port = 5432"をinit文に追加します。これは次のようなものです:session sql(postgresql, "host=127.0.0.1 dbname=exampledb user=postgres password=123 port=5432");。私はこの解決策が他人を助けることを望む。

関連する問題