설명서를 읽었으며 예제를 살펴 봤지만 C++의 전역 변수에 테이블을 할당하는 방법을 여전히 이해할 수 없습니다. 나는 조금 부끄러 웠을지도 모른다. 파이썬에서 왔고 전역 변수에 테이블을 할당하는 것은 mysqldb를 사용하는 단순한 문제입니다.mysql ++ 전역 테이블 변수
테이블을 mysqlpp 클래스 외부에서 액세스 할 수있는 전역 변수에 할당 할 수 있습니까? 내가 대신 다시 클래스로 for 루프를 이동하면 'sched_recs'가이 범위
#include <mysql++.h>
#include <string>
#include <time.h>
using namespace std;
using namespace mysqlpp;
int SSE (const char* timeStr)
{
time_t sse;
struct tm tm;
strptime(timeStr, "%Y-%m-%d %H:%M:%S", &tm);
sse = mktime(&tm);
return (sse);
}
int main()
{
string table = "sched_recs";
time_t now, tt;
now = time(NULL);
try
{
// Connect to the sample database.
mysqlpp::Connection conn(false);
// databasename, host, username, password
if (conn.connect("dbname", "dbhost", "dbusername", "dbpasswd")) {
// Retrieve a subset of the sample stock table set up by resetdb
// and display it.
//stmt = "select datetime from %s", table
mysqlpp::Query query = conn.query("select * from sched_recs");
mysqlpp::StoreQueryResult sched_recs = query.store();
//if (mysqlpp::StoreQueryResult tableData = query.store()) {
////cout << "We have:" << endl;
//}
}
}
catch (Exception& e)
{
cerr << "Exception: " << e.what() << endl;
}
for (size_t i = 0; i < sched_recs.num_rows(); ++i) {
if (SSE(sched_recs[i][1]) - 60 * 3 < now && SSE(sched_recs[i][2]) > now)
{
cout << '\t' << sched_recs[i][1] << endl;
//system("at -f test.py '18:30' today");
}
}
}
에 선언되지 않은 : 오류 : 다음 코드를 컴파일 할 때 예를 들어
는, 나는 오류 모든 것이 잘 작동하지만 이것은 제한적입니다. 이것을 할 수있는 유일한 방법입니까? 모든 예가 그렇게 보일 것 같습니다.
어떤 문서 (좋은 링크가 좋을까요). –
SSQLS를 통해 이루어졌지만 [documentation] (http://www.tangentsoft.net/mysql++/doc/html/userman/ssqls.html)의 5 장을 보면 알 수 있습니다. 테이블의 각 SQL 열에 대해 데이터 멤버를 정의해야합니까? 아니면 요청하고 싶은 SQL 멤버 만 정의해야합니까? 문서는 테이블의 각 열에 대해 하나씩 정의해야하는 것처럼 들립니다. "각 SQL 열에 대해 동일한 이름을 사용하는 데이터 멤버가 있습니다." – nomadicME
'try {}'블록 안에'mysqlpp :: StoreQueryResult sched_recs'를 선언 했으므로 블록이 끝나면 변수는 범위를 벗어나 try 블록 외부에서 사용할 수 없습니다. 'try {}'블록 안에'for' 루프를 옮기거나'try {}'블록 앞에 변수 선언을 옮깁니다. – Yaniro