Alright now.. Rewrote the first chunk of code to my liking.
mysqlpp::Query qry_help_cmd = mysql_conn.query("SELECT *
FROM `command` WHERE `name` = ");
qry_help_cmd << quote << command_tokens[1];
mysqlpp::StoreQueryResult res_help_cmd =
qry_help_cmd.store();
if(res_help_cmd){
slog.clog("Name: " + res_help_cmd[0]["name"]);
slog.clog("Syntax: " + res_help_cmd[0]["syntax"]);
slog.clog("Description: " +
res_help_cmd[0]["help"]);
}else{
slog.clog("No help available for " +
command_tokens[1] + ".");
};
Although, it seems either a) I did something wrong or b) mysql++ is acting
weird. Because, it somehow manages to make the query into this:
terminate called after throwing an instance of 'mysqlpp::BadQuery'
what(): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
''info' * from `command` where `name` =' at line 1
That's.. Not what it's supposed to do, is it?
Note: command_tokens is the tokens of the entered text ("help info" becomes
command_tokens[0] and command_tokens[1]).
And yes, I do have the actual data in the DB:
mysql> select * from awi.command where name = "info";
+------+------------------------------+--------+
| name | help | syntax |
+------+------------------------------+--------+
| info | Shows information about AWI. | info |
+------+------------------------------+--------+
I might've missed some little detail here, though. Scanned it over
thoroughly and couldn't find any errors in my version.
Thanks.
2008/8/21 Alex <xtzgzorex@stripped>
> Haha, no, not homework. Just a project I'm working on. :)
>
> Thanks for that extensive piece of code. I'll try to give it a shot
> tomorrow.. Right now, I'm going to go to sleep.
>
> Thanks again. :)
>
> 2008/8/21 Warren Young <mysqlpp@stripped>
>
>> Alex wrote:
>>
>>
>>> So you can understand that I wouldn't be able to directly refer to the
>>> specific command the user wants help for as the vector is split up in
>>> numbers.
>>>
>>
>> I understand no such thing. The answer is simple either way:
>>
>> Query q = conn.query("SELECT * FROM command WHERE NAME =");
>> q << quote << myCommandName;
>> StoreQueryResult res = q.store();
>> if (res) {
>> // have help for this command
>> }
>> else {
>> // don't have help for this command
>> }
>>
>> Or:
>>
>> class command {
>> public:
>> command(const char* name, const char* help = 0,
>> const char* syntax = 0) :
>> name_(name),
>> help_(help ? help : ""),
>> syntax_(syntax ? syntax : "")
>> {
>> }
>> ....
>> bool operator==(const command& rhs)
>> {
>> return name_ == rhs.name_;
>> }
>> private:
>> string name_, help_, syntax_;
>> };
>>
>> vector<commands> vc;
>>
>> // populate vector of command objects somehow
>>
>> vector<commands>::iterator it = find(vc.begin(), vc.end(),
>> command(myCommandName));
>> if (it != vc.end()) {
>> // have help for this command
>> }
>> else {
>> // don't have help for this command
>> }
>>
>> So, is this a homework problem, or what?
>>
>>
>> --
>> MySQL++ Mailing List
>> For list archives: http://lists.mysql.com/plusplus
>> To unsubscribe:
>> http://lists.mysql.com/plusplus?unsub=1
>>
>>
>
>
> --
> GamerzWoW - http://www.gamerzwow.net
>
--
GamerzWoW - http://www.gamerzwow.net