soci를 올바르게 사용하여 mysql에 연결하고 sql을 실행할 수 있습니다. 그러나 postgresql에 대한 동일한 방법은 작동하지 않습니다. 이것은 내 makefile과 main.cpp입니다.
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".
"select count(*) from student"
터미널에서 SQL 을 실행할 수 있지만 C ++ 코드가 작동하지 않는 이유는 무엇입니까?
좋아,이 문제를 혼자 해결했습니다. 다른 예제와 달리 init 문에 "host = 127.0.0.1"및 "port = 5432"를 추가합니다 session sql(postgresql, "host=127.0.0.1 dbname=exampledb user=postgres password=123 port=5432");
. 다음과 같습니다 .. 이 솔루션이 다른 사람들에게 도움이되기를 바랍니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다