I am using SQLAPI++ to insert values into my SQL DataBase, I am trying to extract actions from chess games and insert it as string in actions table in the database just like this (action_id=1, action_name=e4). here is my code:
int main()
{
SAConnection con;
SACommand cmd;
try
{
con.Connect("test","tester","tester", SA_SQLServer_Client);
cmd.setConnection(&con);
std::ifstream pgnfile("sample.pgn");
pgn::GameCollection games;
pgnfile >> games;
for(pgn::GameCollection::iterator itr=games.begin();itr!=games.end();itr++)
{
pgn::Game game = *itr;
pgn::MoveList move_list=game.moves();
for(pgn::MoveList::iterator itr2=move_list.begin();itr2!=move_list.end();itr2++)
{
pgn::Move move=*itr2;
cmd.setCommandText("insert into actions (action_id,action_name) values (:1,:2)");
cmd.Param(1).setAsLong() = 1;
cmd.Param(2).setAsString() = move.black().str(); // the line that cause the error
}
}
}
}
the problem is in that line:
cmd.Param(2).setAsString() = move.black().str();
it can not convert from std::string to SAString! so can you tell me how to make this conversion from std::string to SAString?
I don't know your particular SAString
class, but I believe it should be possible to construct such a string object from a C-style const char*
string (like e.g. SAString("Connie")
).
Given a std::string
you can call its c_str
method to get such a C-style string, which can probably be used to construct your SAString
.
So, in your method call sequence:
... = move.black().str();
Assuming str
returns a std::string
, I'd add a call to c_str
:
... = move.black().str().c_str();