0
我可以正確使用soci連接到mysql並執行sql。但postgresql的相同方式不起作用。這是我的makefile和main.cpp中:當我使用soci連接到postgresql時,爲什麼我沒有足夠的數據庫特權?
all: main.cpp
g++ -Wall -g -o main main.cpp -lpq -lsoci_core -lsoci_postgresql -ldl
clean:
這是main.cpp中:
#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;
}
}
這是錯誤輸出:
Error:Cannot execute query. Fatal error. 錯誤: 對關係 student 權限不夠
while executing "select count(*) from student".
我可以在終端執行sql "select count(*) from student"
但C++代碼不起作用,爲什麼?