Norhan Foda Norhan Foda - 3 months ago 46
SQL Question

converting from std::string to SAString

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;
con.Connect("test","tester","tester", SA_SQLServer_Client);
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() =; // the line that cause the error


the problem is in that line:

cmd.Param(2).setAsString() =;

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:

 ... =;

Assuming str returns a std::string, I'd add a call to c_str:

... =;