가변 개수의 열로 테이블을 만들려고합니다. YH (i, Y1, Y2 .... Yd)오류 : 'const char *'및 'const char [7]'- 2 진 'operator +'에 대한 잘못된 피연산자
그래서 쿼리 내에서 for 루프를 만들었습니다.
error: invalid operands of types ‘const char*’ and ‘const char [7]’ to binary ‘operator+’ for(int l=1;l<=d;l++) {commandline+=", Y"+ l +" real ";}
주요 코드는 아래와 같습니다 - - 그러나 다음과 같은 오류를 보여주는 그들의
for(int l=1;l<=d;l++) {commandline+=", Y" l " real ";}
for(int l=1;l<=d;l++) {commandline+=", Y"+std::string(l)+" real ";}
없음 작동하는 것 같다 -
string commandline;
commandline = "DROP TABLE YH";
if(SQL_SUCCESS != SQLExecDirect(hdlStmt, (SQLCHAR*)(commandline.c_str()), SQL_NTS))
{
cout<<"The drop YH table is unsuccessful."<<endl;
}
commandline = "CREATE TABLE YH"
"(i int primary key ";
for(int l=1;l<=d;l++) {
commandline+=", Y"+l+" real ";
}
commandline+=") ";
if(SQL_SUCCESS != SQLExecDirect(hdlStmt, (SQLCHAR*)(commandline.c_str()), SQL_NTS))
{
cout<<"The create table sql command hasn't been executed successfully."<<endl;
}
나는은 다음 시도했다.
SQL 문에서 큰 따옴표를 사용하려면 \를 사용하여 올바르게 이스케이프 처리하십시오. 또한 SQL 주입 공격에 대해 SQL 문을 검사해야합니다. – Jodocus
@Jodocus 그는 SQL 문에서 큰 따옴표를 어디에서 사용하려고합니까? – Barmar
죄송합니다. 나는 그것을 놓쳤습니다! 'commandline + = std :: string (", Y") + std :: to_string (l) + "real"; 또는 @ user4581301에서 말하는대로'std :: istringstream'을 사용하십시오. –